| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- namespace addons\WechatVideoShop\backend\controllers;
- use addons\WechatVideoShop\common\models\WechatVideoShopLevel;
- use addons\WechatVideoShop\common\models\WechatVideoShopSharer;
- use addons\WechatVideoShop\common\service\SharerService;
- use addons\WechatVideoShop\common\service\ShopService;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use common\models\user\UserLevel;
- use Yii;
- class SharerController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 售后列表
- * @return string
- */
- public function actionIndex()
- {
- return $this->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);
- }
- }
|