request->isAjax) { if (Yii::$app->request->isGet) { $params = Yii::$app->request->get(); $time = time(); $list = $where = []; $where[] = ['=', 'mall_id', $this->mall_id]; if (isset($params['p_id']) && $params['p_id'] !== '') { $where[] = ['=', 'user_parent_id', $params['p_id']]; } if (isset($params['id']) && $params['id'] !== '') { $where[] = ['=', 'user_id', $params['id']]; } if (isset($params['mobile']) && $params['mobile'] !== '') { $userId = User::find() ->where([ 'mobile' => $params['mobile'], 'mall_id' => $this->mall_id ]) ->select('id') ->scalar(); if (empty($userId)) { $this->success('获取成功', ['list' => $list, 'now_time' => $time]); } $where[] = ['=', 'user_id', $userId]; } if (isset($params['p_mobile']) && $params['p_mobile'] !== '') { $userId = User::find() ->where([ 'mobile' => $params['p_mobile'], 'mall_id' => $this->mall_id ]) ->select('id') ->scalar(); if (empty($userId)) { $this->success('获取成功', ['list' => $list, 'now_time' => $time]); } $where[] = ['=', 'user_parent_id', $userId]; } if (isset($params['rebate_title']) && $params['rebate_title'] !== '') { $rebateId = Rebate::find() ->where([ 'title' => $params['rebate_title'], 'mall_id' => $this->mall_id ]) ->select('id') ->column(); if (empty($rebateId)) { $this->success('获取成功', ['list' => $list, 'now_time' => $time]); } $where[] = ['in', 'rebate_id', $rebateId]; } if (isset($params['order_no']) && $params['order_no'] !== '') { $rebateBuyId = RebateBuy::find() ->where([ 'order_no' => $params['order_no'], 'mall_id' => $this->mall_id ]) ->select('id') ->scalar(); if (empty($rebateBuyId)) { $this->success('获取成功', ['list' => $list, 'now_time' => $time]); } $where[] = ['=', 'rebate_buy_id', $rebateBuyId]; } $order = 'id desc'; $select = 'id, user_id, user_parent_id, mall_id, rebate_id, rebate_buy_id, created_at'; $with = [ 'user' => function ($query) { $query->select('id, nickname, avatar_url, mobile'); }, 'parentUser' => function ($query) { $query->select('id, nickname, avatar_url, mobile'); }, 'rebate' => function ($query) { $query->select('id, title'); }, 'rebateBuy' => function ($query) { $query->select('id, order_no'); } ]; $params = compact('where', 'order', 'select', 'with'); $list = RebateVirtualOrderLog::listPage($params, false, true); $this->success('获取成功', ['list' => $list, 'now_time' => $time]); } } else { return $this->render($this->action->id); } } /** * 创建虚拟订单 * * @return mixed|string|null */ public function actionAdd() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isPost) { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['user_id', 'rebate_id'], 'required'], [['user_id', 'rebate_id'], 'integer'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); if (!RewardLogic::createVirtualOrder($this->mall_id, $params['user_id'], $params['rebate_id'])) { return $this->error(RewardLogic::getStaticError()); } return $this->success("保存成功"); } } return $this->render($this->action->id); } }