User.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\user;
  12. use app\common\repositories\store\ExcelRepository;
  13. use app\common\repositories\system\config\ConfigRepository;
  14. use app\common\repositories\system\config\ConfigValueRepository;
  15. use app\common\repositories\user\UserBrokerageRepository;
  16. use app\common\repositories\user\UserHistoryRepository;
  17. use app\common\repositories\user\UserSignRepository;
  18. use app\common\repositories\user\UserSpreadLogRepository;
  19. use app\common\repositories\user\UserVisitRepository;
  20. use app\validate\admin\UserAwardIntegralValidate;
  21. use app\validate\admin\UserAwardRangeValidate;
  22. use app\validate\admin\UserRegisterValidate;
  23. use crmeb\basic\BaseController;
  24. use app\common\repositories\store\coupon\StoreCouponRepository;
  25. use app\common\repositories\store\coupon\StoreCouponUserRepository;
  26. use app\common\repositories\store\order\StoreOrderRepository;
  27. use app\common\repositories\user\UserBillRepository;
  28. use app\common\repositories\user\UserGroupRepository;
  29. use app\common\repositories\user\UserLabelRepository;
  30. use app\common\repositories\user\UserRepository;
  31. use app\common\repositories\wechat\WechatNewsRepository;
  32. use app\common\repositories\wechat\WechatUserRepository;
  33. use app\validate\admin\UserNowMoneyValidate;
  34. use app\validate\admin\UserValidate;
  35. use crmeb\services\ExcelService;
  36. use crmeb\services\SearchUtilsServices;
  37. use FormBuilder\Exception\FormBuilderException;
  38. use think\App;
  39. use think\db\exception\DataNotFoundException;
  40. use think\db\exception\DbException;
  41. use think\db\exception\ModelNotFoundException;
  42. use think\facade\Db;
  43. /**
  44. * 用户
  45. * Class User
  46. * @package app\controller\admin\user
  47. * @author xaboy
  48. * @day 2020-05-07
  49. */
  50. class User extends BaseController
  51. {
  52. /**
  53. * @var UserRepository
  54. */
  55. protected $repository;
  56. /**
  57. * User constructor.
  58. * @param App $app
  59. * @param UserRepository $repository
  60. */
  61. public function __construct(App $app, UserRepository $repository)
  62. {
  63. parent::__construct($app);
  64. $this->repository = $repository;
  65. }
  66. /**
  67. * 列表
  68. * @return mixed
  69. * @throws DataNotFoundException
  70. * @throws DbException
  71. * @throws ModelNotFoundException
  72. * @author xaboy
  73. * @day 2020-05-07
  74. */
  75. public function lst()
  76. {
  77. /*
  78. * 昵称,分组,标签,地址,性别,
  79. */
  80. /*
  81. {
  82. "filter_conditions" : [
  83. {
  84. "field_name":"uid", //搜索字段
  85. "operator":"in", // 搜索方式
  86. "value":"10697", //搜索值
  87. "form_value":"input" //搜索框类型
  88. }
  89. ],
  90. "boolean":"and" //各种条件存在关系 and 或 or
  91. }
  92. */
  93. $filter_conditions = $this->request->param('filter_conditions',[]);
  94. $where = $this->request->params([
  95. 'nickname', 'phone','uid','user_type',
  96. 'label_id','user_type','sex','is_promoter','country','pay_count','user_time_type','user_time','province','city','group_id','is_svip','fields_type','fields_value','member_level','keyword','birthday'
  97. ]);
  98. [$page, $limit] = $this->getPage();
  99. return app('json')->success($this->repository->getList($where, $page, $limit,$filter_conditions));
  100. }
  101. /**
  102. * 推广人列表
  103. * @param $uid
  104. * @return \think\response\Json
  105. * @author Qinii
  106. */
  107. public function spreadList($uid)
  108. {
  109. $where = $this->request->params(['level', 'keyword', 'date']);
  110. [$page, $limit] = $this->getPage();
  111. return app('json')->success($this->repository->getLevelList($uid, $where, $page, $limit));
  112. }
  113. /**
  114. * 推广订单
  115. * @param $uid
  116. * @return \think\response\Json
  117. * @author Qinii
  118. */
  119. public function spreadOrder($uid)
  120. {
  121. $where = $this->request->params(['level', 'keyword', 'date']);
  122. [$page, $limit] = $this->getPage();
  123. return app('json')->success($this->repository->subOrder($uid, $page, $limit, $where));
  124. }
  125. /**
  126. * 清除推广人
  127. * @param $uid
  128. * @return \think\response\Json
  129. * @author Qinii
  130. */
  131. public function clearSpread($uid)
  132. {
  133. $this->repository->update($uid, ['spread_uid' => 0]);
  134. return app('json')->success('清除成功');
  135. }
  136. /**
  137. * 添加用户 - 弃用
  138. * @return mixed
  139. * @throws FormBuilderException
  140. * @author xaboy
  141. * @day 2020-05-07
  142. */
  143. public function createForm()
  144. {
  145. return app('json')->success(formToData($this->repository->createForm()));
  146. }
  147. /**
  148. * 获取扩展字段数据
  149. * @return mixed
  150. * @throws DataNotFoundException
  151. * @throws DbException
  152. * @throws ModelNotFoundException
  153. */
  154. public function getFields()
  155. {
  156. return app('json')->success($this->repository->getFields());
  157. }
  158. /**
  159. * 添加用户
  160. * @param UserValidate $validate
  161. * @return mixed
  162. * @author xaboy
  163. * @day 2020-05-07
  164. */
  165. public function create(UserValidate $validate)
  166. {
  167. $data = $this->request->params([
  168. 'account',
  169. 'pwd',
  170. 'repwd',
  171. 'nickname',
  172. 'avatar',
  173. 'real_name',
  174. 'phone',
  175. 'sex',
  176. 'status',
  177. 'card_id',
  178. ['is_promoter', 0],
  179. ['extend_info', []],
  180. ['promoter_switch',1],
  181. ]);
  182. $validate->scene('create')->check($data);
  183. $data['pwd'] = $this->repository->encodePassword($data['repwd']);
  184. unset($data['repwd']);
  185. if ($data['is_promoter']) $data['promoter_time'] = date('Y-m-d H:i:s');
  186. if (empty($data['nickname'])) {
  187. $data['nickname'] = substr_replace($data['account'], '****', 3, 4);;
  188. }
  189. $this->repository->create('h5', $data);
  190. return app('json')->success('添加成功');
  191. }
  192. /**
  193. * 修改用户密码表单
  194. * @param $id
  195. * @param UserValidate $validate
  196. * @return mixed
  197. * @author xaboy
  198. * @day 2020-05-07
  199. */
  200. public function changePasswordForm($id)
  201. {
  202. return app('json')->success(formToData($this->repository->changePasswordForm($id)));
  203. }
  204. /**
  205. * 修改用户密码
  206. * @param $id
  207. * @param UserValidate $validate
  208. * @return mixed
  209. * @author xaboy
  210. * @day 2020-05-07
  211. */
  212. public function changePassword($id)
  213. {
  214. $data = $this->request->params([
  215. 'pwd',
  216. 'repwd',
  217. ]);
  218. if (!$data['pwd'] || !$data['repwd'])
  219. return app('json')->fail('密码不能为空');
  220. if ($data['pwd'] !== $data['repwd'])
  221. return app('json')->fail('密码不一致');
  222. $data['pwd'] = $this->repository->encodePassword($data['repwd']);
  223. unset($data['repwd']);
  224. $this->repository->update($id, $data);
  225. return app('json')->success('修改成功');
  226. }
  227. /**
  228. * 修改用户表单 - 弃用
  229. * @param $id
  230. * @return mixed
  231. * @throws DataNotFoundException
  232. * @throws DbException
  233. * @throws FormBuilderException
  234. * @throws ModelNotFoundException
  235. * @author xaboy
  236. * @day 2020-05-09
  237. */
  238. public function updateForm($id)
  239. {
  240. if (!$this->repository->exists($id))
  241. return app('json')->fail('数据不存在');
  242. return app('json')->success(formToData($this->repository->userForm($id)));
  243. }
  244. /**
  245. * 修改用户
  246. * @param $id
  247. * @param UserValidate $validate
  248. * @param UserLabelRepository $labelRepository
  249. * @param UserGroupRepository $groupRepository
  250. * @return mixed
  251. * @throws DbException
  252. * @author xaboy
  253. * @day 2020-05-09
  254. */
  255. public function update($id, UserValidate $validate, UserLabelRepository $labelRepository, UserGroupRepository $groupRepository)
  256. {
  257. $data = $this->request->params(['phone', 'card_id', 'mark', 'group_id', ['label_id', []], ['is_promoter', 0],
  258. ['status', 0], ['member_level', ''], ['extend_info', []],'promoter_switch']);
  259. $extend_info = $data['extend_info'];
  260. unset($data['extend_info']);
  261. $validate->check($data);
  262. if (!$user = $this->repository->get($id))
  263. return app('json')->fail('数据不存在');
  264. if ($data['group_id'] && !$groupRepository->exists($data['group_id']))
  265. return app('json')->fail('分组不存在');
  266. $label_id = (array)$data['label_id'];
  267. foreach ($label_id as $k => $value) {
  268. $label_id[$k] = (int)$value;
  269. if (!$labelRepository->exists((int)$value))
  270. return app('json')->fail('标签不存在');
  271. }
  272. $data['label_id'] = implode(',', $label_id);
  273. if ($data['is_promoter'])
  274. $data['promoter_time'] = date('Y-m-d H:i:s');
  275. // if (!$data['birthday']) unset($data['birthday']);
  276. if ($data['member_level'] !== '') {
  277. $make = app()->make(UserBrokerageRepository::class);
  278. if ($data['member_level'] == $user->member_level) {
  279. unset($data['member_level']);
  280. } else {
  281. $has = $make->fieldExists('brokerage_level', $data['member_level'], null, 1);
  282. if (!$has) return app('json')->fail('等级不存在');
  283. $data['member_value'] = 0;
  284. // 记录用户等级变化时成长值变化
  285. if ($user->member_value > 0) {
  286. app()->make(UserBillRepository::class)->decBill($user->uid, 'sys_members', 'platform_clearing', [
  287. 'number' => $user->member_value,
  288. 'title' => '平台修改等级',
  289. 'balance' => $data['member_value'],
  290. 'status' => 0,
  291. 'mark' => '平台修改等级清除成长值' . ':' . $user->member_value,
  292. ]);
  293. }
  294. }
  295. } else {
  296. unset($data['member_level']);
  297. }
  298. // 更新扩展字段
  299. $this->repository->saveFields((int)$id, $extend_info);
  300. $this->repository->update($id, $data);
  301. return app('json')->success('编辑成功');
  302. }
  303. /**
  304. * 修改用户标签
  305. * @param $id
  306. * @param UserLabelRepository $labelRepository
  307. * @return mixed
  308. * @throws DbException
  309. * @author xaboy
  310. * @day 2020-05-08
  311. */
  312. public function changeLabel($id, UserLabelRepository $labelRepository)
  313. {
  314. $label_id = (array)$this->request->param('label_id', []);
  315. if (!$this->repository->exists($id))
  316. return app('json')->fail('数据不存在');
  317. foreach ($label_id as $k => $value) {
  318. $label_id[$k] = (int)$value;
  319. if (!$labelRepository->exists((int)$value))
  320. return app('json')->fail('标签不存在');
  321. }
  322. $label_id = implode(',', $label_id);
  323. $this->repository->update($id, compact('label_id'));
  324. return app('json')->success('修改成功');
  325. }
  326. /**
  327. * 批量修改用户标签
  328. * @param UserLabelRepository $labelRepository
  329. * @return mixed
  330. * @throws DbException
  331. * @author xaboy
  332. * @day 2020-05-08
  333. */
  334. public function batchChangeLabel(UserLabelRepository $labelRepository)
  335. {
  336. $label_id = (array)$this->request->param('label_id', []);
  337. $ids = (array)$this->request->param('ids', []);
  338. if (!count($ids))
  339. return app('json')->fail('数据不存在');
  340. foreach ($label_id as $k => $value) {
  341. $label_id[$k] = (int)$value;
  342. if (!$labelRepository->exists((int)$value))
  343. return app('json')->fail('标签不存在');
  344. }
  345. $this->repository->batchChangeLabelId($ids, $label_id);
  346. return app('json')->success('修改成功');
  347. }
  348. /**
  349. * 修改用户标签表单
  350. * @param $id
  351. * @return mixed
  352. * @throws DataNotFoundException
  353. * @throws DbException
  354. * @throws FormBuilderException
  355. * @throws ModelNotFoundException
  356. * @author xaboy
  357. * @day 2020-05-08
  358. */
  359. public function changeLabelForm($id)
  360. {
  361. if (!$this->repository->exists($id))
  362. return app('json')->fail('数据不存在');
  363. return app('json')->success(formToData($this->repository->changeLabelForm($id)));
  364. }
  365. /**
  366. * 批量修改用户标签表单
  367. * @return mixed
  368. * @throws DataNotFoundException
  369. * @throws DbException
  370. * @throws FormBuilderException
  371. * @throws ModelNotFoundException
  372. * @author xaboy
  373. * @day 2020-05-08
  374. */
  375. public function batchChangeLabelForm()
  376. {
  377. $ids = $this->request->param('ids', '');
  378. $ids = array_filter(explode(',', $ids));
  379. if (!count($ids))
  380. return app('json')->fail('数据不存在');
  381. return app('json')->success(formToData($this->repository->changeLabelForm($ids)));
  382. }
  383. /**
  384. * 批量修改用户分组表单
  385. * @return mixed
  386. * @throws DataNotFoundException
  387. * @throws DbException
  388. * @throws FormBuilderException
  389. * @throws ModelNotFoundException
  390. * @author xaboy
  391. * @day 2020-05-08
  392. */
  393. public function batchChangeGroupForm()
  394. {
  395. $ids = $this->request->param('ids', '');
  396. $ids = array_filter(explode(',', $ids));
  397. if (!count($ids))
  398. return app('json')->fail('数据不存在');
  399. return app('json')->success(formToData($this->repository->changeGroupForm($ids)));
  400. }
  401. /**
  402. * 修改用户分组
  403. * @param $id
  404. * @param UserGroupRepository $groupRepository
  405. * @return mixed
  406. * @throws DbException
  407. * @author xaboy
  408. * @day 2020-05-07
  409. */
  410. public function changeGroup($id, UserGroupRepository $groupRepository)
  411. {
  412. $group_id = (int)$this->request->param('group_id', 0);
  413. if (!$this->repository->exists($id))
  414. return app('json')->fail('数据不存在');
  415. if ($group_id && !$groupRepository->exists($group_id))
  416. return app('json')->fail('分组不存在');
  417. $this->repository->update($id, compact('group_id'));
  418. return app('json')->success('修改成功');
  419. }
  420. /**
  421. * 批量修改用户分组
  422. * @param UserGroupRepository $groupRepository
  423. * @return mixed
  424. * @throws DbException
  425. * @author xaboy
  426. * @day 2020-05-07
  427. */
  428. public function batchChangeGroup(UserGroupRepository $groupRepository)
  429. {
  430. $group_id = (int)$this->request->param('group_id', 0);
  431. $ids = (array)$this->request->param('ids', []);
  432. if (!count($ids))
  433. return app('json')->fail('数据不存在');
  434. if ($group_id && !$groupRepository->exists($group_id))
  435. return app('json')->fail('分组不存在');
  436. $this->repository->batchChangeGroupId($ids, $group_id);
  437. return app('json')->success('修改成功');
  438. }
  439. /**
  440. * 修改用户分组表单
  441. * @param $id
  442. * @return mixed
  443. * @throws FormBuilderException
  444. * @throws DataNotFoundException
  445. * @throws DbException
  446. * @throws ModelNotFoundException
  447. * @author xaboy
  448. * @day 2020-05-07
  449. */
  450. public function changeGroupForm($id)
  451. {
  452. if (!$this->repository->exists($id))
  453. return app('json')->fail('数据不存在');
  454. return app('json')->success(formToData($this->repository->changeGroupForm($id)));
  455. }
  456. /**
  457. * 修改用户余额表单
  458. * @param $id
  459. * @return mixed
  460. * @throws FormBuilderException
  461. * @author xaboy
  462. * @day 2020-05-07
  463. */
  464. public function changeNowMoneyForm($id)
  465. {
  466. if (!$this->repository->exists($id))
  467. return app('json')->fail('数据不存在');
  468. return app('json')->success(formToData($this->repository->changeNowMoneyForm($id)));
  469. }
  470. /**
  471. * 修改用户分红积分表单
  472. * @param $id
  473. * @return mixed
  474. * @throws FormBuilderException
  475. * @author xaboy
  476. * @day 2020-05-07
  477. */
  478. public function changeAwardIntegralForm($id)
  479. {
  480. if (!$this->repository->exists($id))
  481. return app('json')->fail('数据不存在');
  482. return app('json')->success(formToData($this->repository->changeAwardIntegralForm($id)));
  483. }
  484. /**
  485. * 修改用户分红额度表单
  486. * @param $id
  487. * @return mixed
  488. * @throws FormBuilderException
  489. * @author xaboy
  490. * @day 2020-05-07
  491. */
  492. public function changeAwardRangeForm($id)
  493. {
  494. if (!$this->repository->exists($id))
  495. return app('json')->fail('数据不存在');
  496. return app('json')->success(formToData($this->repository->changeAwardRangeForm($id)));
  497. }
  498. /**
  499. * 修改用户积分表单
  500. * @param $id
  501. * @return mixed
  502. * @throws FormBuilderException
  503. * @author xaboy
  504. * @day 2020-05-07
  505. */
  506. public function changeIntegralForm($id)
  507. {
  508. if (!$this->repository->exists($id))
  509. return app('json')->fail('数据不存在');
  510. return app('json')->success(formToData($this->repository->changeIntegralForm($id)));
  511. }
  512. /**
  513. * 修改用户余额
  514. * @param $id
  515. * @param UserNowMoneyValidate $validate
  516. * @return mixed
  517. * @throws DataNotFoundException
  518. * @throws DbException
  519. * @throws ModelNotFoundException
  520. * @author xaboy
  521. * @day 2020-05-07
  522. */
  523. public function changeNowMoney($id, UserNowMoneyValidate $validate)
  524. {
  525. $data = $this->request->params(['now_money', 'type']);
  526. $validate->check($data);
  527. if (!$this->repository->exists($id))
  528. return app('json')->fail('数据不存在');
  529. $this->repository->changeNowMoney($id, $this->request->adminId(), $data['type'], $data['now_money']);
  530. return app('json')->success('修改成功');
  531. }
  532. /**
  533. * 修改用户分红积分
  534. * @param $id
  535. * @param UserNowMoneyValidate $validate
  536. * @return mixed
  537. * @throws DataNotFoundException
  538. * @throws DbException
  539. * @throws ModelNotFoundException
  540. * @author xaboy
  541. * @day 2020-05-07
  542. */
  543. public function changeAwardIntegral($id, UserAwardIntegralValidate $validate)
  544. {
  545. $data = $this->request->params(['award_integral', 'type']);
  546. $validate->check($data);
  547. if (!$this->repository->exists($id))
  548. return app('json')->fail('数据不存在');
  549. $this->repository->changeAwardIntegral($id, $this->request->adminId(), $data['type'], $data['award_integral']);
  550. return app('json')->success('修改成功');
  551. }
  552. /**
  553. * 修改用户分红额度
  554. * @param $id
  555. * @param UserNowMoneyValidate $validate
  556. * @return mixed
  557. * @throws DataNotFoundException
  558. * @throws DbException
  559. * @throws ModelNotFoundException
  560. * @author xaboy
  561. * @day 2020-05-07
  562. */
  563. public function changeAwardRange($id, UserAwardRangeValidate $validate)
  564. {
  565. $data = $this->request->params(['award_range', 'type']);
  566. $validate->check($data);
  567. if (!$this->repository->exists($id))
  568. return app('json')->fail('数据不存在');
  569. $this->repository->changeAwardRange($id, $this->request->adminId(), $data['type'], $data['award_range']);
  570. return app('json')->success('修改成功');
  571. }
  572. /**
  573. * 修改用户积分
  574. * @param $id
  575. * @param UserNowMoneyValidate $validate
  576. * @return mixed
  577. * @throws DataNotFoundException
  578. * @throws DbException
  579. * @throws ModelNotFoundException
  580. * @author xaboy
  581. * @day 2020-05-07
  582. */
  583. public function changeIntegral($id, UserNowMoneyValidate $validate)
  584. {
  585. $data = $this->request->params(['now_money', 'type']);
  586. $validate->check($data);
  587. if (!$this->repository->exists($id))
  588. return app('json')->fail('数据不存在');
  589. $this->repository->changeIntegral($id, $this->request->adminId(), $data['type'], $data['now_money']);
  590. return app('json')->success('修改成功');
  591. }
  592. /**
  593. * 发送微信消息
  594. * @param WechatNewsRepository $wechatNewsRepository
  595. * @param WechatUserRepository $wechatUserRepository
  596. * @return mixed
  597. * @author xaboy
  598. * @day 2020-05-11
  599. */
  600. public function sendNews(WechatNewsRepository $wechatNewsRepository, WechatUserRepository $wechatUserRepository)
  601. {
  602. $ids = $this->request->param('ids');
  603. if (!is_array($ids)) $ids = explode(',', $this->request->param('ids'));
  604. $ids = array_filter(array_unique($ids));
  605. $news_id = (int)$this->request->param('news_id', 0);
  606. if (!$news_id)
  607. return app('json')->fail('请选择图文消息');
  608. if (!$wechatNewsRepository->exists($news_id))
  609. return app('json')->fail('数据不存在');
  610. if (!count($ids))
  611. return app('json')->fail('请选择微信用户');
  612. $wechatUserRepository->sendNews($news_id, $ids);
  613. return app('json')->success('发送成功');
  614. }
  615. /**
  616. * 推广人列表
  617. * @return mixed
  618. * @author xaboy
  619. * @day 2020-05-11
  620. */
  621. public function promoterList()
  622. {
  623. $where = $this->request->params(['keyword', 'date', 'brokerage_level','uid','nickname','phone','real_name']);
  624. [$page, $limit] = $this->getPage();
  625. return app('json')->success($this->repository->promoterList($where, $page, $limit));
  626. }
  627. /**
  628. * 推广人统计
  629. * @return mixed
  630. * @author xaboy
  631. * @day 2020-05-11
  632. */
  633. public function promoterCount()
  634. {
  635. $where = $this->request->params(['keyword', 'date', 'brokerage_level']);
  636. return app('json')->success($this->repository->promoterCount($where));
  637. }
  638. /**
  639. * 推广订单列表
  640. * @return mixed
  641. * @author xaboy
  642. * @day 2020-05-11
  643. */
  644. public function detail($id)
  645. {
  646. if (!$this->repository->exists($id))
  647. return app('json')->fail('数据不存在');
  648. return app('json')->success($this->repository->userOrderDetail($id));
  649. }
  650. public function order($id, StoreOrderRepository $repository)
  651. {
  652. if (!$this->repository->exists($id))
  653. return app('json')->fail('数据不存在');
  654. [$page, $limit] = $this->getPage();
  655. return app('json')->success($repository->userList($id, $page, $limit));
  656. }
  657. public function coupon($id, StoreCouponUserRepository $repository)
  658. {
  659. if (!$this->repository->exists($id))
  660. return app('json')->fail('数据不存在');
  661. [$page, $limit] = $this->getPage();
  662. return app('json')->success($repository->userList(['uid' => $id], $page, $limit));
  663. }
  664. public function bill($id, UserBillRepository $repository)
  665. {
  666. if (!$this->repository->exists(intval($id)))
  667. return app('json')->fail('数据不存在');
  668. [$page, $limit] = $this->getPage();
  669. return app('json')->success($repository->userList([
  670. 'now_money' => 0,
  671. 'status' => 1
  672. ], $id, $page, $limit));
  673. }
  674. public function spreadLog($id)
  675. {
  676. if (!$this->repository->exists((int)$id))
  677. return app('json')->fail('数据不存在');
  678. [$page, $limit] = $this->getPage();
  679. return app('json')->success(app()->make(UserSpreadLogRepository::class)->getList(['uid' => $id], $page, $limit));
  680. }
  681. public function spreadForm($id)
  682. {
  683. if (!$this->repository->exists((int)$id))
  684. return app('json')->fail('数据不存在');
  685. return app('json')->success(formToData($this->repository->changeSpreadForm($id)));
  686. }
  687. public function spread($id)
  688. {
  689. if (!$this->repository->exists((int)$id))
  690. return app('json')->fail('数据不存在');
  691. $spid = $this->request->param('spid');
  692. $spid = (int)($spid['id'] ?? $spid);
  693. if ($spid == $id)
  694. return app('json')->fail('不能选自己');
  695. if ($spid && !$this->repository->exists($spid))
  696. return app('json')->fail('推荐人不存在');
  697. $this->repository->changeSpread($id, $spid, $this->request->adminId());
  698. return app('json')->success('修改成功');
  699. }
  700. public function searchLog()
  701. {
  702. $where = $this->request->params(['date', 'keyword', 'nickname', 'user_type','uid','phone','real_name']);
  703. $merId = $this->request->merId();
  704. $where['type'] = ['searchMerchant', 'searchProduct'];
  705. if ($merId) {
  706. $where['mer_id'] = $merId;
  707. }
  708. [$page, $limit] = $this->getPage();
  709. return app('json')->success(app()->make(UserVisitRepository::class)->getSearchLog($where, $page, $limit));
  710. }
  711. public function clearSearchLog()
  712. {
  713. $merId = $this->request->merId();
  714. $where['type'] = ['searchMerchant', 'searchProduct'];
  715. if ($merId) {
  716. $where['mer_id'] = $merId;
  717. }
  718. $res = app()->make(UserVisitRepository::class)->clearSearchLog($where);
  719. if (!$res) {
  720. return app('json')->fail('清除失败');
  721. }
  722. return app('json')->success('清除成功');
  723. }
  724. public function exportSearchLog()
  725. {
  726. $where = $this->request->params(['date', 'keyword', 'nickname', 'user_type']);
  727. $merId = $this->request->merId();
  728. $where['type'] = ['searchMerchant', 'searchProduct'];
  729. if ($merId) {
  730. $where['mer_id'] = $merId;
  731. }
  732. [$page, $limit] = $this->getPage();
  733. $data = app()->make(ExcelService::class)->searchLog($where, $page, $limit);
  734. return app('json')->success($data);
  735. }
  736. public function memberForm($id)
  737. {
  738. return app('json')->success(formToData($this->repository->memberForm($id, 1)));
  739. }
  740. public function memberSave($id)
  741. {
  742. $data = $this->request->params(['member_level']);
  743. if (!$this->repository->exists((int)$id))
  744. return app('json')->fail('数据不存在');
  745. $this->repository->updateLevel($id, $data, 1);
  746. return app('json')->success('修改成功');
  747. }
  748. public function spreadLevelForm($id)
  749. {
  750. return app('json')->success(formToData($this->repository->memberForm($id, 0)));
  751. }
  752. public function spreadLevelSave($id)
  753. {
  754. $brokerage_level = $this->request->params(['brokerage_level']);
  755. if (!$this->repository->exists((int)$id))
  756. return app('json')->fail('数据不存在');
  757. $this->repository->updateLevel($id, $brokerage_level, 0);
  758. return app('json')->success('修改成功');
  759. }
  760. public function svipForm($id)
  761. {
  762. return app('json')->success(formToData($this->repository->svipForm($id)));
  763. }
  764. public function svipUpdate($id)
  765. {
  766. $data = $this->request->params(['is_svip', 'add_time', 'type']);
  767. $this->repository->svipUpdate($id, $data, $this->request->adminId());
  768. return app('json')->success('修改成功');
  769. }
  770. /**
  771. * 积分记录
  772. * @param $id
  773. * @author Qinii
  774. * @day 2023/4/25
  775. */
  776. public function integralList($id, UserBillRepository $repository)
  777. {
  778. [$page, $limit] = $this->getPage();
  779. $data = $repository->userList(['category' => 'integral'], $id, $page, $limit);
  780. return app('json')->success($data);
  781. }
  782. /**
  783. * 分红积分记录
  784. * @param $id
  785. * @author Qinii
  786. * @day 2023/4/25
  787. */
  788. public function awardIntegralList($id, UserBillRepository $repository)
  789. {
  790. [$page, $limit] = $this->getPage();
  791. $data = $repository->userList(['category' => 'award_integral'], $id, $page, $limit);
  792. return app('json')->success($data);
  793. }
  794. /**
  795. * 分红额度记录
  796. * @param $id
  797. * @author Qinii
  798. * @day 2023/4/25
  799. */
  800. public function awardRangeList($id, UserBillRepository $repository)
  801. {
  802. [$page, $limit] = $this->getPage();
  803. $data = $repository->userList(['category' => 'award_range'], $id, $page, $limit);
  804. return app('json')->success($data);
  805. }
  806. /**
  807. * 签到记录
  808. * @param $id
  809. * @param UserSignRepository $signRepository
  810. * @return \think\response\Json
  811. * @author Qinii
  812. * @day 2023/4/25
  813. */
  814. public function sign_log($id, UserSignRepository $signRepository)
  815. {
  816. [$page, $limit] = $this->getPage();
  817. $where = ['uid' => $id];
  818. $data = $signRepository->getList($where, $page, $limit);
  819. return app('json')->success($data);
  820. }
  821. public function history($id, UserHistoryRepository $repository)
  822. {
  823. [$page, $limit] = $this->getPage();
  824. return app('json')->success($repository->getList($page, $limit, $id, 1));
  825. }
  826. public function excel()
  827. {
  828. /*
  829. * 昵称,分组,标签,地址,性别,
  830. */
  831. $where = $this->request->params([
  832. 'label_id',
  833. 'user_type',
  834. 'sex',
  835. 'is_promoter',
  836. 'country',
  837. 'pay_count',
  838. 'user_time_type',
  839. 'user_time',
  840. 'nickname',
  841. 'province',
  842. 'city',
  843. 'group_id',
  844. 'phone',
  845. 'uid',
  846. 'is_svip',
  847. 'fields_type',
  848. 'fields_value',
  849. 'ids'
  850. ]);
  851. $where['uids'] = $where['ids'];
  852. $viewSearch = $this->request->param('filter_conditions',[]);
  853. [$page, $limit] = $this->getPage();
  854. $data = app()->make(ExcelService::class)->user($where, $page, $limit, $viewSearch);
  855. return app('json')->success($data);
  856. }
  857. public function getMemberLevelSelectList()
  858. {
  859. return app('json')->success($this->repository->getMemberLevelSelectList());
  860. }
  861. /**
  862. * 批量设置分销员表单
  863. * @return \think\response\Json
  864. * @author Qinii
  865. * @day 2023/10/26
  866. */
  867. public function batchSpreadForm()
  868. {
  869. $ids = $this->request->param('ids', '');
  870. $ids = array_filter(explode(',', $ids));
  871. if (!count($ids))
  872. return app('json')->fail('数据不存在');
  873. $data = $this->repository->batchSpreadForm($ids);
  874. return app('json')->success(formToData($data));
  875. }
  876. /**
  877. * 批量设置分销员
  878. * @return \think\response\Json
  879. * @author Qinii
  880. * @day 2023/10/26
  881. */
  882. public function batchSpread()
  883. {
  884. $uids = $this->request->param('uids', []);
  885. $is_promoter = $this->request->param('is_promoter') == 1 ? 1 : 0;
  886. $promoter_switch = $this->request->param('promoter_switch') == 1 ? 1 : 0;
  887. $this->repository->updates($uids, compact('promoter_switch','is_promoter'));
  888. return app('json')->success('修改成功');
  889. }
  890. /**
  891. * 保存用户注册配置信息
  892. * @return \think\response\Json
  893. * @author Qinii
  894. */
  895. public function saveRegisterConfig()
  896. {
  897. $configKey = app()->make(ConfigRepository::class)->getConfigKey('user_register');
  898. $params = array_column($configKey['config_keys'],'config_key');
  899. //$params = ['first_avatar_switch','is_phone_login','newcomer_status','open_update_info',
  900. //'register_coupon_status','register_give_coupon','register_give_integral','register_give_money','register_integral_status','register_money_status','register_popup_pic','wechat_phone_switch'];
  901. $data = $this->request->params($params);
  902. if ($data['register_money_status'] && !$data['register_give_money'])
  903. return app('json')->fail('请填写余额赠送金额');
  904. if ($data['register_integral_status'] && !$data['register_give_integral'])
  905. return app('json')->fail('请填写积分赠送金额');
  906. app()->make(UserRegisterValidate::class)->check($data);
  907. if (is_array($data['register_give_coupon'])) $data['register_give_coupon'] = implode(',',$data['register_give_coupon']);
  908. app()->make(ConfigValueRepository::class)->setFormData($data,0);
  909. return app('json')->success('修改成功');
  910. }
  911. /**
  912. * 获取注册赠送优惠券列表
  913. * @return \think\response\Json
  914. * @author Qinii
  915. */
  916. public function getRegisterCoupon()
  917. {
  918. [$page, $limit] = $this->getPage();
  919. $storeCouponRepository = app()->make(StoreCouponRepository::class);
  920. if (!systemConfig('register_give_coupon')) return app('json')->success([]);
  921. $data = $storeCouponRepository->getList(0,['coupon_ids' => systemConfig('register_give_coupon')],$page, $limit);
  922. return app('json')->success($data);
  923. }
  924. }