| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- <?php
- namespace addons\DoubleCopy\backend\controllers;
- use addons\DoubleCopy\common\enums\DoubleCopyEnum;
- use addons\DoubleCopy\common\logic\ChangePosLogic;
- use addons\DoubleCopy\common\models\DoubleCopyChangePos;
- use addons\DoubleCopy\common\models\DoubleCopyChangeTopid;
- use addons\DoubleCopy\common\models\DoubleCopyHelp;
- use addons\DoubleCopy\common\models\DoubleCopyLevel;
- use addons\DoubleCopy\common\models\DoubleCopyUser;
- use common\enums\RabbitMqEnum;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\DoubleCopy\backend\controllers
- */
- class DefaultController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isGet) {
- $get = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($get,[
- [['user_id','level','mobile'], 'integer'],
- [['user_id','mobile','start_at','end_at'], 'safe'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 获取等级
- $level_arr = DoubleCopyLevel::getLevelMap($this->mall_id, 2);
- // 升级类型
- $upgrade_type = DoubleCopyEnum::getUpgradeStatusMap();
- $capital_map = DoubleCopyEnum::getCapitalMap($this->mall_id);
- $where = $list = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- !empty($get['user_id']) && $where[] = ['=', 'user_id', $get['user_id']];
- !empty($get['level']) && $where[] = ['=', 'level', $get['level']];
- if (!empty($get['start_at']) && !empty($get['end_at'])) {
- $where[] = ['between', 'created_at', strtotime($get['start_at']), strtotime($get['end_at'])];
- }
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $where[] = ['is_virtual' => 0];
- // 根据搜索手机号查询用户id
- if (!empty($get['mobile'])) {
- $user_id = User::find()->select("id")->where(['mall_id' => $this->mall_id,'mobile' => $get['mobile']])->asArray()->column();
- if (empty($user_id)) $this->success('获取成功', compact('list','level_arr', 'upgrade_type','capital_map'));
- $where[] = ['in', 'user_id', $user_id];
- }
- $with = ['user','puser','topuser','market'];
- $order = 'created_at desc';
- $params = array('where' => $where, 'order'=>$order, 'with' => $with, 'limit' => $get['limit']);
- //基础设置:当前奖励类型
- $config = Yii::$app->services->setting->addons->get($this->mall_id, DoubleCopyEnum::ADDONS_NAME, 'basic');
- $reward_currency = $config['reward_currency'] ?? 'commission';
- $list = DoubleCopyUser::listPage($params, false, true);
- $pid_ids_arr = array_column($list['list'], 'user_id');
- $virtual_user_num_list = DoubleCopyUser::lists(['where' => [['mall_id' => $this->mall_id], ['pid' => $pid_ids_arr], ['status' => StatusEnum::ENABLED], ['is_virtual' => 1]], 'group' => 'pid', 'select' => 'count(*) as virtual_num, pid', 'index' => 'pid']);
- foreach ($list['list'] as &$item) {
- $item['reward_currency'] = $reward_currency == 'score' ? '积分' : '佣金';
- if($reward_currency == 'score'){
- $item['commission'] = $item['score'];
- $item['frozen_fund'] = $item['frozen_fund_score'];
- }
- if (isset($virtual_user_num_list[$item['user_id']])) {
- $item['has_virtual'] = 1;
- $item['virtual_user_num'] = intval($virtual_user_num_list[$item['user_id']]['virtual_num']);
- }else{
- $item['has_virtual'] = 0;
- $item['virtual_user_num'] = 0;
- }
- }
- $this->success('获取成功', compact('list','level_arr', 'upgrade_type','capital_map'));
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- /**
- * 处理
- * @Author: lun
- * @DateTime: 2022/5/14 0014 16:47
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionHandle()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isGet) {
- $params = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['id'], 'required'],
- [['id','status','is_height_commission'], 'integer'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- if (!isset($params['status'])) unset($params['status']);
- if (!isset($params['is_height_commission'])) unset($params['is_height_commission']);
- $params['mall_id'] = $this->mall_id;
- $res = DoubleCopyUser::setData($params);
- if (!$res) return $this->error('修改失败:msg=' . DoubleCopyLevel::getStaticError());
- return $this->success('修改成功');
- }
- }
- }
- /**
- * 助力用户列表
- * @Author: lun
- * @DateTime: 2022/5/14 0014 16:39
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionHelpList()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isGet) {
- $get = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($get,[
- [['user_id'], 'required'],
- [['user_id','limit'], 'integer'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = [];
- $where[] = ['=', 'pid', $get['user_id']];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $with = ['user'];
- $order = 'pos asc,created_at asc';
- $select = "user_id,pos,created_at,is_virtual";
- $params = array('where' => $where, 'select' => $select, 'order' => $order, 'with' => $with, 'limit' => $get['limit']);
- $list = DoubleCopyUser::listPage($params);
- $this->success('获取成功', $list);
- }
- }
- }
- /**
- * 换位处理
- * @Author: lun
- * @DateTime: 2023/6/3 0003 11:50
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionChange()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isPost) {
- $list = Yii::$app->request->post();
- if (empty($list)) return $this->error('请提交更改内容');
- if (DoubleCopyChangePos::check($this->mall_id) == false) return $this->error('您有尚未完成的助力换位任务,请等此任务完成再提交');
- unset($list['_csrf']);
- $change_arr = [];
- // 获取需要换位的用户
- foreach ($list as $item) {
- if ($item['pos'] != $item['now_pos']) {
- $change_arr[] = [
- 'user_id' => $item['user_id'],
- 'old_pos' => $item['pos'],
- 'now_pos' => $item['now_pos'],
- ];
- }
- }
- if (empty($change_arr)) return $this->error('暂无可交换位置的用户');
- $return_id = DoubleCopyChangePos::setData($this->mall_id, $change_arr);
- if ($return_id == false) return $this->error('提交失败:' . DoubleCopyChangePos::getStaticError());
- Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, ['id' => $return_id], ChangePosLogic::class, 'handle');
- // ChangePosLogic::handle(['id' => $return_id]);
- return $this->success('换位申请提交成功,请耐性等候!');
- }
- }
- }
- /**
- * 获取换位信息
- * @Author: lun
- * @DateTime: 2023/6/3 0003 15:18
- * @Copyright: copyright (c) 2021 广东七件事集团
- */
- public function actionChangeLogs()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isGet) {
- $where = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $order = 'id desc,created_at desc';
- $params = array('where' => $where, 'order' => $order);
- $list = DoubleCopyChangePos::listPage($params);
- if (!empty($list['list'])) {
- foreach ($list['list'] as &$item) {
- $users = json_decode($item['content'], true);
- $content = [];
- foreach ($users as $info) {
- // 获取用户信息
- $user = User::find()->select('id,mobile,nickname,avatar_url')->where(['id' => $info['user_id']])->asArray()->one();
- $content[] = [
- 'user_id' => $info['user_id'],
- 'nickname' => $user['nickname'],
- 'avatar_url' => $user['avatar_url'],
- 'mobile' => $user['mobile'],
- 'old_pos' => $info['old_pos'],
- 'now_pos' => $info['now_pos'],
- ];
- }
- $item['content_arr'] = $content;
- }
- }
- $this->success('获取成功', $list);
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- /**
- * 查看换位后团队变动记录
- * @Author: lun
- * @DateTime: 2023/6/3 0003 16:25
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionChangeTeamLogs()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isGet) {
- $get = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($get,[
- [['change_id'], 'required'],
- [['change_id'], 'integer'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = [];
- $where[] = ['=', 'change_pos_id', $get['change_id']];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $with = ['user', 'oldTop', 'nowTop'];
- $order = 'id desc,created_at desc';
- $params = array('where' => $where, 'order' => $order, 'with' => $with, 'limit' => 5);
- $list = DoubleCopyChangeTopid::listPage($params);
- $this->success('获取成功', $list);
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- /**
- * 处理
- * @Author: lun
- * @DateTime: 2022/5/14 0014 16:47
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionCommission()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isPost) {
- $params = Yii::$app->request->post();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['id','height_commission'], 'required'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- $res = DoubleCopyUser::setData($params);
- if (!$res) return $this->error('设置失败:msg=' . DoubleCopyLevel::getStaticError());
- return $this->success('设置成功');
- }
- }
- }
- public function actionSearchUser()
- {
- if (\Yii::$app->request->isAjax) {
- $keyword = \Yii::$app->request->get('keyword', '');
- $params = ['keyword' => $keyword, 'mall_id' => $this->mall_id];
- $query = User::find()->alias('u')
- ->where(['u.status' => StatusEnum::ENABLED, 'u.mall_id' => $params['mall_id']])
- ->andWhere(['u.is_inviter' => 1]);
- if (isset($params['keyword']) && !empty($params['keyword'])) {
- $query->andWhere(['or', ['like', 'nickname', $params['keyword']], ['like', 'mobile', $params['keyword']], ['like', 'id', $params['keyword']]]);
- }
- $list = $query->limit(20)->select('u.id,u.nickname,u.mobile,u.avatar_url')->asArray()->all();
- foreach ($list as &$item) {
- if (empty($item['nickname'])) {
- $item['nickname'] = $item['mobile'] . "(id:{$item['id']})";
- }
- }
- $list['list'] = $list;
- return $this->success('操作成功', $list);
- }
- return $this->error();
- }
- }
|