User.php 32 KB

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