DefaultController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <?php
  2. namespace addons\DoubleCopy\backend\controllers;
  3. use addons\DoubleCopy\common\enums\DoubleCopyEnum;
  4. use addons\DoubleCopy\common\logic\ChangePosLogic;
  5. use addons\DoubleCopy\common\models\DoubleCopyChangePos;
  6. use addons\DoubleCopy\common\models\DoubleCopyChangeTopid;
  7. use addons\DoubleCopy\common\models\DoubleCopyHelp;
  8. use addons\DoubleCopy\common\models\DoubleCopyLevel;
  9. use addons\DoubleCopy\common\models\DoubleCopyUser;
  10. use common\enums\RabbitMqEnum;
  11. use common\enums\StatusEnum;
  12. use common\models\user\User;
  13. use Yii;
  14. /**
  15. * 默认控制器
  16. *
  17. * Class DefaultController
  18. * @package addons\DoubleCopy\backend\controllers
  19. */
  20. class DefaultController extends BaseController
  21. {
  22. public $enableCsrfValidation = false;
  23. /**
  24. * 首页
  25. *
  26. * @return string
  27. */
  28. /**
  29. * 首页
  30. *
  31. * @return string
  32. */
  33. public function actionIndex()
  34. {
  35. $retuest = Yii::$app->request;
  36. if ($retuest->isAjax) {
  37. if ($retuest->isGet) {
  38. $get = Yii::$app->request->get();
  39. // 检查提交的参数
  40. $res = Yii::$app->services->validate->validate($get,[
  41. [['user_id','level','mobile'], 'integer'],
  42. [['user_id','mobile','start_at','end_at'], 'safe'],
  43. ]);
  44. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  45. // 获取等级
  46. $level_arr = DoubleCopyLevel::getLevelMap($this->mall_id, 2);
  47. // 升级类型
  48. $upgrade_type = DoubleCopyEnum::getUpgradeStatusMap();
  49. $capital_map = DoubleCopyEnum::getCapitalMap($this->mall_id);
  50. $where = $list = [];
  51. $where[] = ['=', 'mall_id', $this->mall_id];
  52. !empty($get['user_id']) && $where[] = ['=', 'user_id', $get['user_id']];
  53. !empty($get['level']) && $where[] = ['=', 'level', $get['level']];
  54. if (!empty($get['start_at']) && !empty($get['end_at'])) {
  55. $where[] = ['between', 'created_at', strtotime($get['start_at']), strtotime($get['end_at'])];
  56. }
  57. $where[] = ['=', 'status', StatusEnum::ENABLED];
  58. $where[] = ['is_virtual' => 0];
  59. // 根据搜索手机号查询用户id
  60. if (!empty($get['mobile'])) {
  61. $user_id = User::find()->select("id")->where(['mall_id' => $this->mall_id,'mobile' => $get['mobile']])->asArray()->column();
  62. if (empty($user_id)) $this->success('获取成功', compact('list','level_arr', 'upgrade_type','capital_map'));
  63. $where[] = ['in', 'user_id', $user_id];
  64. }
  65. $with = ['user','puser','topuser','market'];
  66. $order = 'created_at desc';
  67. $params = array('where' => $where, 'order'=>$order, 'with' => $with, 'limit' => $get['limit']);
  68. //基础设置:当前奖励类型
  69. $config = Yii::$app->services->setting->addons->get($this->mall_id, DoubleCopyEnum::ADDONS_NAME, 'basic');
  70. $reward_currency = $config['reward_currency'] ?? 'commission';
  71. $list = DoubleCopyUser::listPage($params, false, true);
  72. $pid_ids_arr = array_column($list['list'], 'user_id');
  73. $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']);
  74. foreach ($list['list'] as &$item) {
  75. $item['reward_currency'] = $reward_currency == 'score' ? '积分' : '佣金';
  76. if($reward_currency == 'score'){
  77. $item['commission'] = $item['score'];
  78. $item['frozen_fund'] = $item['frozen_fund_score'];
  79. }
  80. if (isset($virtual_user_num_list[$item['user_id']])) {
  81. $item['has_virtual'] = 1;
  82. $item['virtual_user_num'] = intval($virtual_user_num_list[$item['user_id']]['virtual_num']);
  83. }else{
  84. $item['has_virtual'] = 0;
  85. $item['virtual_user_num'] = 0;
  86. }
  87. }
  88. $this->success('获取成功', compact('list','level_arr', 'upgrade_type','capital_map'));
  89. }
  90. } else {
  91. return $this->render($this->action->id);
  92. }
  93. }
  94. /**
  95. * 处理
  96. * @Author: lun
  97. * @DateTime: 2022/5/14 0014 16:47
  98. * @Copyright: copyright (c) 2021 广东七件事集团
  99. * @return mixed|void
  100. */
  101. public function actionHandle()
  102. {
  103. $request = Yii::$app->request;
  104. if ($request->isAjax) {
  105. if ($request->isGet) {
  106. $params = Yii::$app->request->get();
  107. // 检查提交的参数
  108. $res = Yii::$app->services->validate->validate($params,[
  109. [['id'], 'required'],
  110. [['id','status','is_height_commission'], 'integer'],
  111. ]);
  112. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  113. if (!isset($params['status'])) unset($params['status']);
  114. if (!isset($params['is_height_commission'])) unset($params['is_height_commission']);
  115. $params['mall_id'] = $this->mall_id;
  116. $res = DoubleCopyUser::setData($params);
  117. if (!$res) return $this->error('修改失败:msg=' . DoubleCopyLevel::getStaticError());
  118. return $this->success('修改成功');
  119. }
  120. }
  121. }
  122. /**
  123. * 助力用户列表
  124. * @Author: lun
  125. * @DateTime: 2022/5/14 0014 16:39
  126. * @Copyright: copyright (c) 2021 广东七件事集团
  127. * @return mixed|void
  128. */
  129. public function actionHelpList()
  130. {
  131. $retuest = Yii::$app->request;
  132. if ($retuest->isAjax) {
  133. if ($retuest->isGet) {
  134. $get = Yii::$app->request->get();
  135. // 检查提交的参数
  136. $res = Yii::$app->services->validate->validate($get,[
  137. [['user_id'], 'required'],
  138. [['user_id','limit'], 'integer'],
  139. ]);
  140. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  141. $where = [];
  142. $where[] = ['=', 'pid', $get['user_id']];
  143. $where[] = ['=', 'status', StatusEnum::ENABLED];
  144. $with = ['user'];
  145. $order = 'pos asc,created_at asc';
  146. $select = "user_id,pos,created_at,is_virtual";
  147. $params = array('where' => $where, 'select' => $select, 'order' => $order, 'with' => $with, 'limit' => $get['limit']);
  148. $list = DoubleCopyUser::listPage($params);
  149. $this->success('获取成功', $list);
  150. }
  151. }
  152. }
  153. /**
  154. * 换位处理
  155. * @Author: lun
  156. * @DateTime: 2023/6/3 0003 11:50
  157. * @Copyright: copyright (c) 2021 广东七件事集团
  158. * @return mixed|void
  159. */
  160. public function actionChange()
  161. {
  162. $retuest = Yii::$app->request;
  163. if ($retuest->isAjax) {
  164. if ($retuest->isPost) {
  165. $list = Yii::$app->request->post();
  166. if (empty($list)) return $this->error('请提交更改内容');
  167. if (DoubleCopyChangePos::check($this->mall_id) == false) return $this->error('您有尚未完成的助力换位任务,请等此任务完成再提交');
  168. unset($list['_csrf']);
  169. $change_arr = [];
  170. // 获取需要换位的用户
  171. foreach ($list as $item) {
  172. if ($item['pos'] != $item['now_pos']) {
  173. $change_arr[] = [
  174. 'user_id' => $item['user_id'],
  175. 'old_pos' => $item['pos'],
  176. 'now_pos' => $item['now_pos'],
  177. ];
  178. }
  179. }
  180. if (empty($change_arr)) return $this->error('暂无可交换位置的用户');
  181. $return_id = DoubleCopyChangePos::setData($this->mall_id, $change_arr);
  182. if ($return_id == false) return $this->error('提交失败:' . DoubleCopyChangePos::getStaticError());
  183. Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, ['id' => $return_id], ChangePosLogic::class, 'handle');
  184. // ChangePosLogic::handle(['id' => $return_id]);
  185. return $this->success('换位申请提交成功,请耐性等候!');
  186. }
  187. }
  188. }
  189. /**
  190. * 获取换位信息
  191. * @Author: lun
  192. * @DateTime: 2023/6/3 0003 15:18
  193. * @Copyright: copyright (c) 2021 广东七件事集团
  194. */
  195. public function actionChangeLogs()
  196. {
  197. $retuest = Yii::$app->request;
  198. if ($retuest->isAjax) {
  199. if ($retuest->isGet) {
  200. $where = [];
  201. $where[] = ['=', 'mall_id', $this->mall_id];
  202. $where[] = ['=', 'status', StatusEnum::ENABLED];
  203. $order = 'id desc,created_at desc';
  204. $params = array('where' => $where, 'order' => $order);
  205. $list = DoubleCopyChangePos::listPage($params);
  206. if (!empty($list['list'])) {
  207. foreach ($list['list'] as &$item) {
  208. $users = json_decode($item['content'], true);
  209. $content = [];
  210. foreach ($users as $info) {
  211. // 获取用户信息
  212. $user = User::find()->select('id,mobile,nickname,avatar_url')->where(['id' => $info['user_id']])->asArray()->one();
  213. $content[] = [
  214. 'user_id' => $info['user_id'],
  215. 'nickname' => $user['nickname'],
  216. 'avatar_url' => $user['avatar_url'],
  217. 'mobile' => $user['mobile'],
  218. 'old_pos' => $info['old_pos'],
  219. 'now_pos' => $info['now_pos'],
  220. ];
  221. }
  222. $item['content_arr'] = $content;
  223. }
  224. }
  225. $this->success('获取成功', $list);
  226. }
  227. } else {
  228. return $this->render($this->action->id);
  229. }
  230. }
  231. /**
  232. * 查看换位后团队变动记录
  233. * @Author: lun
  234. * @DateTime: 2023/6/3 0003 16:25
  235. * @Copyright: copyright (c) 2021 广东七件事集团
  236. * @return mixed|string|void
  237. */
  238. public function actionChangeTeamLogs()
  239. {
  240. $retuest = Yii::$app->request;
  241. if ($retuest->isAjax) {
  242. if ($retuest->isGet) {
  243. $get = Yii::$app->request->get();
  244. // 检查提交的参数
  245. $res = Yii::$app->services->validate->validate($get,[
  246. [['change_id'], 'required'],
  247. [['change_id'], 'integer'],
  248. ]);
  249. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  250. $where = [];
  251. $where[] = ['=', 'change_pos_id', $get['change_id']];
  252. $where[] = ['=', 'status', StatusEnum::ENABLED];
  253. $with = ['user', 'oldTop', 'nowTop'];
  254. $order = 'id desc,created_at desc';
  255. $params = array('where' => $where, 'order' => $order, 'with' => $with, 'limit' => 5);
  256. $list = DoubleCopyChangeTopid::listPage($params);
  257. $this->success('获取成功', $list);
  258. }
  259. } else {
  260. return $this->render($this->action->id);
  261. }
  262. }
  263. /**
  264. * 处理
  265. * @Author: lun
  266. * @DateTime: 2022/5/14 0014 16:47
  267. * @Copyright: copyright (c) 2021 广东七件事集团
  268. * @return mixed|void
  269. */
  270. public function actionCommission()
  271. {
  272. $request = Yii::$app->request;
  273. if ($request->isAjax) {
  274. if ($request->isPost) {
  275. $params = Yii::$app->request->post();
  276. // 检查提交的参数
  277. $res = Yii::$app->services->validate->validate($params,[
  278. [['id','height_commission'], 'required'],
  279. ]);
  280. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  281. $params['mall_id'] = $this->mall_id;
  282. $res = DoubleCopyUser::setData($params);
  283. if (!$res) return $this->error('设置失败:msg=' . DoubleCopyLevel::getStaticError());
  284. return $this->success('设置成功');
  285. }
  286. }
  287. }
  288. public function actionSearchUser()
  289. {
  290. if (\Yii::$app->request->isAjax) {
  291. $keyword = \Yii::$app->request->get('keyword', '');
  292. $params = ['keyword' => $keyword, 'mall_id' => $this->mall_id];
  293. $query = User::find()->alias('u')
  294. ->where(['u.status' => StatusEnum::ENABLED, 'u.mall_id' => $params['mall_id']])
  295. ->andWhere(['u.is_inviter' => 1]);
  296. if (isset($params['keyword']) && !empty($params['keyword'])) {
  297. $query->andWhere(['or', ['like', 'nickname', $params['keyword']], ['like', 'mobile', $params['keyword']], ['like', 'id', $params['keyword']]]);
  298. }
  299. $list = $query->limit(20)->select('u.id,u.nickname,u.mobile,u.avatar_url')->asArray()->all();
  300. foreach ($list as &$item) {
  301. if (empty($item['nickname'])) {
  302. $item['nickname'] = $item['mobile'] . "(id:{$item['id']})";
  303. }
  304. }
  305. $list['list'] = $list;
  306. return $this->success('操作成功', $list);
  307. }
  308. return $this->error();
  309. }
  310. }