render($this->action->id); } public function actionList() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { // 取出所有分销员 $data = Yii::$app->request->get(); $valid = Yii::$app->services->validate->validate($data, [ [['page', 'limit', 'sharer_type', 'shop_id', 'level', 'status'], 'integer'], // 需要取本地的数据 [['member', 'invite_start_date', 'invite_end_date', 'bind_start_date', 'bind_end_date'], 'string'] ]); if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); try { $sharer_list = (new SharerService())->page($this->mall_id, $data); // 获取所有店铺键值对 $ret['list'] = $sharer_list; $ret['shop'] = (new ShopService())->ShopArr($this->mall_id); $ret['levels'] = WechatVideoShopLevel::getLevelByColumn($this->mall_id); $ret['is_async'] = WechatVideoShopLevel::getLevelByColumn($this->mall_id); return $this->success('获取成功', $ret); } catch (\Exception $e) { return $this->error($e->getMessage()); } } } return $this->render($this->action->id); } /** * 绑定 * @return mixed|null */ public function actionBind() { // 取出所有分销员 $data = Yii::$app->request->post(); try { $ret = (new SharerService())->bind($this->mall_id, $data); return is_string($ret) ? $this->error($ret) : $this->success('绑定成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 解绑 * @return mixed|null */ public function actionUnbind() { // 取出所有分销员 $data = Yii::$app->request->post(); try { $ret = (new SharerService())->unbind($this->mall_id, $data); return is_string($ret) ? $this->error($ret) : $this->success('解绑成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function actionManual() { return $this->render('manual'); } /** * @return mixed|null */ public function actionAsync() { try { (new SharerService())->async(); return $this->success("同步进行中..."); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * @return mixed|null {*} * @msg: 获取会员列表 */ public function actionGetUsers() { if (!\Yii::$app->request->isGet) { return $this->error('请求方式错误'); } $user_id = \Yii::$app->request->get('user_id'); $keyword = \Yii::$app->request->get('keyword'); $page = \Yii::$app->request->get('page', 1); $limit = \Yii::$app->request->get('limit', $this->pageSize); $store_user_ids = WechatVideoShopSharer::find()->select('user_id') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])->asArray()->column(); $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]; $wheres[] = ['not in', 'id', $store_user_ids]; if (!empty($user_id)) { $wheres[] = ['id' => $user_id]; } if (!empty($keyword)) { $wheres[] = ['or', ['like', 'nickname', $keyword], ['like', 'mobile', $keyword]]; } $params = [ 'select' => 'id,nickname,avatar_url,mobile,level,parent_id', 'where' => $wheres, 'order' => 'created_at desc', 'page' => $page, 'limit' => $limit, ]; $user_list = User::listPage($params); if (empty($user_list['list'])) { if (false === $user_list['list']) { return $this->error(User::getStaticError()); } } else { $levels = UserLevel::find() ->select('id,level,name') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->indexBy('level') ->all(); $parent_ids = array_column($user_list['list'], 'parent_id'); $parent_users = User::find() ->select('id,nickname,avatar_url,mobile,level,parent_id') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $parent_ids]) ->asArray() ->indexBy('id') ->all(); foreach ($user_list['list'] as &$user) { if (empty($user['avatar_url'])) { $user['avatar_url'] = \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png'; } $level = $levels[$user['level']] ?? []; $parent_user = $parent_users[$user['parent_id']] ?? []; $user['level_name'] = $level['name'] ?? ''; $user['parent_nickname'] = $parent_user['nickname'] ?? ''; } } return $this->success('success', $user_list); } /** * 客户列表 * @return mixed|null */ public function actionCustomer() { $data = Yii::$app->request->get(); $valid = Yii::$app->services->validate->validate($data, [ [['page', 'limit', 'user_id', 'parent_id'], 'integer'], // 需要取本地的数据 [['keyword', 'start_date', 'end_date'], 'string'] ]); if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $ret = (new SharerService())->customerList($this->mall_id, $data); return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret); } }