request->isAjax) { if (Yii::$app->request->isGet) { $get = Yii::$app->request->get(); $where = $list = []; $where[] = ['=', 'status', StatusEnum::ENABLED]; $where[] = ['=', 'mall_id', $this->mall_id]; if (!empty($get['order_no'])) { $where[] = ['order_no'=>$get['order_no']]; } if (!empty($get['user_id'])) { $where[] = ['user_id'=>$get['user_id']]; } if (!empty($get['date'])) { $where[]=['between', 'created_at', strtotime($get[0]), strtotime($get[1])]; } if (!empty($get['change_type'])) { if($get['change_type']=='add') { $where[] = ['>','amount',0]; } else{ $where[] = ['<','amount',0]; } } if (isset($get['keyword']) && !empty($get['keyword'])) { $user_list = User::lists([ 'where' => [ ['mall_id' => $this->mall_id], ['or', ['like', 'nickname', $get['keyword']], ['=', 'mobile', $get['keyword']]] ], 'select' => 'id' ]); $where[] = ['user_id' => array_column($user_list, 'id') ?? []]; } $with = [ 'user' => function ($query) { return $query->select('id, nickname, avatar_url, mobile'); } ]; $order = 'created_at desc'; $params = array('where' => $where, 'order' => $order, 'limit' => $get['limit'] ?? 15,'with'=>$with); $list = HappinessWeightPoolOrderLog::listPage($params, false, true); if ($list === false) return $this->error(HappinessWeightPoolOrderLog::getStaticError()); foreach ($list['list'] as &$val) { $date_limit = explode('-', $val['date_limit']); $val['date_limit'] = date('Y-m-d', strtotime($date_limit[0])) . '至' . date('Y-m-d', strtotime($date_limit[1])); } unset($val); $total_amount=HappinessWeightPoolOrderLog::find()->where(['mall_id' => $this->mall_id,'status'=>1])->sum('amount');//实际已结算的订单分红总额 $total_settle_amount=HappinessWeightPoolOrderLog::find()->where(['mall_id' => $this->mall_id,'settlement_status' => 1,'status'=>1])->sum('amount');//实际已结算的订单分红总额 $total_send_amount=HappinessWeightPoolLog::find()->where(['mall_id' => $this->mall_id,'status'=>1])->sum('amount');//实际用户获得的分红 $now_amount=HappinessWeightPoolOrderLog::find()->where(['mall_id' => $this->mall_id, 'settlement_status' => 0,'status'=>1])->sum('amount');//当前未结算的分红,就是分红池的额度 $list['orderStatistics'] = [ 'total_amount' =>$total_amount??0, 'total_settle_amount' => $total_settle_amount??0, 'total_send_amount' => $total_send_amount??0, 'now_amount' => $now_amount??0 ]; return $this->success('获取成功', $list); } } return $this->render($this->action->id); } public function actionRecharge() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isPost) { $params = Yii::$app->request->post(); $rules = [ [['price'], 'required'], [['price'], 'number'], [['remark'], 'string'], ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); try { $params['remark'] = !empty($params['remark']) ? trim($params['remark']) : '管理员调整,' . ($params['price'] > 0 ? '增加' : '减少') . strval(abs($params['price'])); $before_amount = HappinessWeightPoolOrderLog::find()->where(['mall_id' => $this->mall_id, 'settlement_status' => 0])->sum('amount')??0; if(($before_amount+$params['price'])<0) { throw new Exception('奖励池金额不足'.abs($params['price'])); } if (HappinessWeightPoolOrderLog::addData([ 'mall_id' => $this->mall_id, 'date' => date('YmdHis'), 'amount' => $params['price'], 'user_id'=>0, 'price'=>0, 'pay_price'=>0, 'order_id' => 0, 'order_no' => '', 'before_amount' => $before_amount, 'after_amount' => bcadd($before_amount, $params['price'], 2), 'desc'=>$params['remark'] ]) === false) { throw new \Exception(HappinessWeightPoolOrderLog::getStaticError()); } return $this->success('调整成功'); } catch (Exception $e) { return $this->error($e->getMessage()); } } return $this->error('非法的请求'); } } /** * 首页 结算周期 * * @return string */ public function actionList() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { $get = Yii::$app->request->get(); $where = $list = []; $where[] = ['=', 'status', StatusEnum::ENABLED]; $where[] = ['=', 'mall_id', $this->mall_id]; if (isset($get['start_at']) && !empty($get['start_at'])) { $where[] = ['>=', 'created_at', strtotime($get['start_at'])]; } if (isset($get['end_at']) && !empty($get['end_at'])) { $where[] = ['<=', 'created_at', strtotime($get['end_at'])]; } $order = 'created_at desc'; $params = array('where' => $where, 'order' => $order, 'limit' => $get['limit'] ?? 15); $list = HappinessWeightPoolJob::listPage($params, false, true); if ($list === false) return $this->error(HappinessWeightPoolJob::getStaticError()); foreach ($list['list'] as &$val) { $date_limit = explode('-', $val['date_limit']); $val['date_limit'] = date('Y-m-d', strtotime($date_limit[0])) . '至' . date('Y-m-d', strtotime($date_limit[1])); } unset($val); return $this->success('获取成功', compact('list')); } } return $this->render($this->action->id); } /** * 结算明细 */ public function actionDetail() { if (Yii::$app->request->isAjax) { $get = Yii::$app->request->get(); $where = $list = []; $where[] = ['=', 'status', StatusEnum::ENABLED]; $where[] = ['=', 'mall_id', $this->mall_id]; $where[] = ['=', 'job_id', $get['job_id']]; if (isset($get['user_id']) && !empty($get['user_id'])) { $where[] = ['user_id' => $get['user_id']]; } $user_where= []; if(isset($get['level'])&& !empty($get['level'])) { $user_where[]= ['level' => $get['level']]; } if (isset($get['keyword']) && !empty($get['keyword'])) { $user_where[]=[ 'or', ['like', 'nickname', $get['keyword']], ['like', 'mobile', $get['keyword']]]; } if (!empty($user_where)) { $user_where=array_merge(['mall_id' => $this->mall_id],$user_where); $user_list = User::lists([ 'where' => $user_where, 'select' => 'id' ]); $where[] = ['user_id' => array_column($user_list, 'id') ?? []]; } $with = [ 'user' => function ($query) { return $query->select('id, nickname, avatar_url, mobile'); } ]; $order = 'created_at desc'; $params = array('where' => $where, 'order' => $order, 'with' => $with, 'limit' => $get['limit'] ?? 15); $list = HappinessWeightPoolLog::listPage($params, false, true); $levels =UserLevel::getListIndexByLevelColumn($this->mall_id); if ($list === false) return $this->error(HappinessWeightPoolLog::getStaticError()); return $this->success('获取成功', compact('list','levels')); } return $this->render($this->action->id); } //手动执行 public function actionDoRun() { try { $logic = new PoolLogLogic(); $res = $logic->executeNoAuto($this->mall_id); if($res == true) { return $this->success('已经执行'); } } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function actionOrderList() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { $get = Yii::$app->request->get(); $where = $list = []; $where[] = ['=', 'status', StatusEnum::ENABLED]; $where[] = ['=', 'mall_id', $this->mall_id]; if (!empty($get['order_no'])) { $where[] = ['order_no'=>$get['order_no']]; } if (!empty($get['user_id'])) { $where[] = ['user_id'=>$get['user_id']]; } if (!empty($get['date'])) { $where[]=['between', 'created_at', strtotime($get[0]), strtotime($get[1])]; } if (isset($get['keyword']) && !empty($get['keyword'])) { $user_list = User::lists([ 'where' => [ ['mall_id' => $this->mall_id], ['or', ['like', 'nickname', $get['keyword']], ['like', 'mobile', $get['keyword']]], ], 'select' => 'id' ]); $where[] = ['user_id' => array_column($user_list, 'id') ?? []]; } $with = [ 'user' => function ($query) { return $query->select('id, nickname, avatar_url, mobile'); } ]; $order = 'created_at desc'; $params = array('where' => $where, 'order' => $order, 'limit' => $get['limit'] ?? 15,'with'=>$with); $list = HappinessWeightPoolOrderLog::listPage($params, false, true); if ($list === false) return $this->error(HappinessWeightPoolOrderLog::getStaticError()); foreach ($list['list'] as &$val) { $date_limit = explode('-', $val['date_limit']); $val['date_limit'] = date('Y-m-d', strtotime($date_limit[0])) . '至' . date('Y-m-d', strtotime($date_limit[1])); } return $this->success('获取成功', $list); } } return $this->render($this->action->id); } }