User.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  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 changeIntegralForm($id)
  477. {
  478. if (!$this->repository->exists($id))
  479. return app('json')->fail('数据不存在');
  480. return app('json')->success(formToData($this->repository->changeIntegralForm($id)));
  481. }
  482. /**
  483. * 修改用户余额
  484. * @param $id
  485. * @param UserNowMoneyValidate $validate
  486. * @return mixed
  487. * @throws DataNotFoundException
  488. * @throws DbException
  489. * @throws ModelNotFoundException
  490. * @author xaboy
  491. * @day 2020-05-07
  492. */
  493. public function changeNowMoney($id, UserNowMoneyValidate $validate)
  494. {
  495. $data = $this->request->params(['now_money', 'type']);
  496. $validate->check($data);
  497. if (!$this->repository->exists($id))
  498. return app('json')->fail('数据不存在');
  499. $this->repository->changeNowMoney($id, $this->request->adminId(), $data['type'], $data['now_money']);
  500. return app('json')->success('修改成功');
  501. }
  502. /**
  503. * 修改用户积分
  504. * @param $id
  505. * @param UserNowMoneyValidate $validate
  506. * @return mixed
  507. * @throws DataNotFoundException
  508. * @throws DbException
  509. * @throws ModelNotFoundException
  510. * @author xaboy
  511. * @day 2020-05-07
  512. */
  513. public function changeIntegral($id, UserNowMoneyValidate $validate)
  514. {
  515. $data = $this->request->params(['now_money', 'type']);
  516. $validate->check($data);
  517. if (!$this->repository->exists($id))
  518. return app('json')->fail('数据不存在');
  519. $this->repository->changeIntegral($id, $this->request->adminId(), $data['type'], $data['now_money']);
  520. return app('json')->success('修改成功');
  521. }
  522. /**
  523. * 发送微信消息
  524. * @param WechatNewsRepository $wechatNewsRepository
  525. * @param WechatUserRepository $wechatUserRepository
  526. * @return mixed
  527. * @author xaboy
  528. * @day 2020-05-11
  529. */
  530. public function sendNews(WechatNewsRepository $wechatNewsRepository, WechatUserRepository $wechatUserRepository)
  531. {
  532. $ids = $this->request->param('ids');
  533. if (!is_array($ids)) $ids = explode(',', $this->request->param('ids'));
  534. $ids = array_filter(array_unique($ids));
  535. $news_id = (int)$this->request->param('news_id', 0);
  536. if (!$news_id)
  537. return app('json')->fail('请选择图文消息');
  538. if (!$wechatNewsRepository->exists($news_id))
  539. return app('json')->fail('数据不存在');
  540. if (!count($ids))
  541. return app('json')->fail('请选择微信用户');
  542. $wechatUserRepository->sendNews($news_id, $ids);
  543. return app('json')->success('发送成功');
  544. }
  545. /**
  546. * 推广人列表
  547. * @return mixed
  548. * @author xaboy
  549. * @day 2020-05-11
  550. */
  551. public function promoterList()
  552. {
  553. $where = $this->request->params(['keyword', 'date', 'brokerage_level','uid','nickname','phone','real_name']);
  554. [$page, $limit] = $this->getPage();
  555. return app('json')->success($this->repository->promoterList($where, $page, $limit));
  556. }
  557. /**
  558. * 推广人统计
  559. * @return mixed
  560. * @author xaboy
  561. * @day 2020-05-11
  562. */
  563. public function promoterCount()
  564. {
  565. $where = $this->request->params(['keyword', 'date', 'brokerage_level']);
  566. return app('json')->success($this->repository->promoterCount($where));
  567. }
  568. /**
  569. * 推广订单列表
  570. * @return mixed
  571. * @author xaboy
  572. * @day 2020-05-11
  573. */
  574. public function detail($id)
  575. {
  576. if (!$this->repository->exists($id))
  577. return app('json')->fail('数据不存在');
  578. return app('json')->success($this->repository->userOrderDetail($id));
  579. }
  580. public function order($id, StoreOrderRepository $repository)
  581. {
  582. if (!$this->repository->exists($id))
  583. return app('json')->fail('数据不存在');
  584. [$page, $limit] = $this->getPage();
  585. return app('json')->success($repository->userList($id, $page, $limit));
  586. }
  587. public function coupon($id, StoreCouponUserRepository $repository)
  588. {
  589. if (!$this->repository->exists($id))
  590. return app('json')->fail('数据不存在');
  591. [$page, $limit] = $this->getPage();
  592. return app('json')->success($repository->userList(['uid' => $id], $page, $limit));
  593. }
  594. public function bill($id, UserBillRepository $repository)
  595. {
  596. if (!$this->repository->exists(intval($id)))
  597. return app('json')->fail('数据不存在');
  598. [$page, $limit] = $this->getPage();
  599. return app('json')->success($repository->userList([
  600. 'now_money' => 0,
  601. 'status' => 1
  602. ], $id, $page, $limit));
  603. }
  604. public function spreadLog($id)
  605. {
  606. if (!$this->repository->exists((int)$id))
  607. return app('json')->fail('数据不存在');
  608. [$page, $limit] = $this->getPage();
  609. return app('json')->success(app()->make(UserSpreadLogRepository::class)->getList(['uid' => $id], $page, $limit));
  610. }
  611. public function spreadForm($id)
  612. {
  613. if (!$this->repository->exists((int)$id))
  614. return app('json')->fail('数据不存在');
  615. return app('json')->success(formToData($this->repository->changeSpreadForm($id)));
  616. }
  617. public function spread($id)
  618. {
  619. if (!$this->repository->exists((int)$id))
  620. return app('json')->fail('数据不存在');
  621. $spid = $this->request->param('spid');
  622. $spid = (int)($spid['id'] ?? $spid);
  623. if ($spid == $id)
  624. return app('json')->fail('不能选自己');
  625. if ($spid && !$this->repository->exists($spid))
  626. return app('json')->fail('推荐人不存在');
  627. $this->repository->changeSpread($id, $spid, $this->request->adminId());
  628. return app('json')->success('修改成功');
  629. }
  630. public function searchLog()
  631. {
  632. $where = $this->request->params(['date', 'keyword', 'nickname', 'user_type','uid','phone','real_name']);
  633. $merId = $this->request->merId();
  634. $where['type'] = ['searchMerchant', 'searchProduct'];
  635. if ($merId) {
  636. $where['mer_id'] = $merId;
  637. }
  638. [$page, $limit] = $this->getPage();
  639. return app('json')->success(app()->make(UserVisitRepository::class)->getSearchLog($where, $page, $limit));
  640. }
  641. public function clearSearchLog()
  642. {
  643. $merId = $this->request->merId();
  644. $where['type'] = ['searchMerchant', 'searchProduct'];
  645. if ($merId) {
  646. $where['mer_id'] = $merId;
  647. }
  648. $res = app()->make(UserVisitRepository::class)->clearSearchLog($where);
  649. if (!$res) {
  650. return app('json')->fail('清除失败');
  651. }
  652. return app('json')->success('清除成功');
  653. }
  654. public function exportSearchLog()
  655. {
  656. $where = $this->request->params(['date', 'keyword', 'nickname', 'user_type']);
  657. $merId = $this->request->merId();
  658. $where['type'] = ['searchMerchant', 'searchProduct'];
  659. if ($merId) {
  660. $where['mer_id'] = $merId;
  661. }
  662. [$page, $limit] = $this->getPage();
  663. $data = app()->make(ExcelService::class)->searchLog($where, $page, $limit);
  664. return app('json')->success($data);
  665. }
  666. public function memberForm($id)
  667. {
  668. return app('json')->success(formToData($this->repository->memberForm($id, 1)));
  669. }
  670. public function memberSave($id)
  671. {
  672. $data = $this->request->params(['member_level']);
  673. if (!$this->repository->exists((int)$id))
  674. return app('json')->fail('数据不存在');
  675. $this->repository->updateLevel($id, $data, 1);
  676. return app('json')->success('修改成功');
  677. }
  678. public function spreadLevelForm($id)
  679. {
  680. return app('json')->success(formToData($this->repository->memberForm($id, 0)));
  681. }
  682. public function spreadLevelSave($id)
  683. {
  684. $brokerage_level = $this->request->params(['brokerage_level']);
  685. if (!$this->repository->exists((int)$id))
  686. return app('json')->fail('数据不存在');
  687. $this->repository->updateLevel($id, $brokerage_level, 0);
  688. return app('json')->success('修改成功');
  689. }
  690. public function svipForm($id)
  691. {
  692. return app('json')->success(formToData($this->repository->svipForm($id)));
  693. }
  694. public function svipUpdate($id)
  695. {
  696. $data = $this->request->params(['is_svip', 'add_time', 'type']);
  697. $this->repository->svipUpdate($id, $data, $this->request->adminId());
  698. return app('json')->success('修改成功');
  699. }
  700. /**
  701. * 积分记录
  702. * @param $id
  703. * @author Qinii
  704. * @day 2023/4/25
  705. */
  706. public function integralList($id, UserBillRepository $repository)
  707. {
  708. [$page, $limit] = $this->getPage();
  709. $data = $repository->userList(['category' => 'integral'], $id, $page, $limit);
  710. return app('json')->success($data);
  711. }
  712. /**
  713. * 签到记录
  714. * @param $id
  715. * @param UserSignRepository $signRepository
  716. * @return \think\response\Json
  717. * @author Qinii
  718. * @day 2023/4/25
  719. */
  720. public function sign_log($id, UserSignRepository $signRepository)
  721. {
  722. [$page, $limit] = $this->getPage();
  723. $where = ['uid' => $id];
  724. $data = $signRepository->getList($where, $page, $limit);
  725. return app('json')->success($data);
  726. }
  727. public function history($id, UserHistoryRepository $repository)
  728. {
  729. [$page, $limit] = $this->getPage();
  730. return app('json')->success($repository->getList($page, $limit, $id, 1));
  731. }
  732. public function excel()
  733. {
  734. /*
  735. * 昵称,分组,标签,地址,性别,
  736. */
  737. $where = $this->request->params([
  738. 'label_id',
  739. 'user_type',
  740. 'sex',
  741. 'is_promoter',
  742. 'country',
  743. 'pay_count',
  744. 'user_time_type',
  745. 'user_time',
  746. 'nickname',
  747. 'province',
  748. 'city',
  749. 'group_id',
  750. 'phone',
  751. 'uid',
  752. 'is_svip',
  753. 'fields_type',
  754. 'fields_value',
  755. 'ids'
  756. ]);
  757. $where['uids'] = $where['ids'];
  758. $viewSearch = $this->request->param('filter_conditions',[]);
  759. [$page, $limit] = $this->getPage();
  760. $data = app()->make(ExcelService::class)->user($where, $page, $limit, $viewSearch);
  761. return app('json')->success($data);
  762. }
  763. public function getMemberLevelSelectList()
  764. {
  765. return app('json')->success($this->repository->getMemberLevelSelectList());
  766. }
  767. /**
  768. * 批量设置分销员表单
  769. * @return \think\response\Json
  770. * @author Qinii
  771. * @day 2023/10/26
  772. */
  773. public function batchSpreadForm()
  774. {
  775. $ids = $this->request->param('ids', '');
  776. $ids = array_filter(explode(',', $ids));
  777. if (!count($ids))
  778. return app('json')->fail('数据不存在');
  779. $data = $this->repository->batchSpreadForm($ids);
  780. return app('json')->success(formToData($data));
  781. }
  782. /**
  783. * 批量设置分销员
  784. * @return \think\response\Json
  785. * @author Qinii
  786. * @day 2023/10/26
  787. */
  788. public function batchSpread()
  789. {
  790. $uids = $this->request->param('uids', []);
  791. $is_promoter = $this->request->param('is_promoter') == 1 ? 1 : 0;
  792. $promoter_switch = $this->request->param('promoter_switch') == 1 ? 1 : 0;
  793. $this->repository->updates($uids, compact('promoter_switch','is_promoter'));
  794. return app('json')->success('修改成功');
  795. }
  796. /**
  797. * 保存用户注册配置信息
  798. * @return \think\response\Json
  799. * @author Qinii
  800. */
  801. public function saveRegisterConfig()
  802. {
  803. $configKey = app()->make(ConfigRepository::class)->getConfigKey('user_register');
  804. $params = array_column($configKey['config_keys'],'config_key');
  805. //$params = ['first_avatar_switch','is_phone_login','newcomer_status','open_update_info',
  806. //'register_coupon_status','register_give_coupon','register_give_integral','register_give_money','register_integral_status','register_money_status','register_popup_pic','wechat_phone_switch'];
  807. $data = $this->request->params($params);
  808. if ($data['register_money_status'] && !$data['register_give_money'])
  809. return app('json')->fail('请填写余额赠送金额');
  810. if ($data['register_integral_status'] && !$data['register_give_integral'])
  811. return app('json')->fail('请填写积分赠送金额');
  812. app()->make(UserRegisterValidate::class)->check($data);
  813. if (is_array($data['register_give_coupon'])) $data['register_give_coupon'] = implode(',',$data['register_give_coupon']);
  814. app()->make(ConfigValueRepository::class)->setFormData($data,0);
  815. return app('json')->success('修改成功');
  816. }
  817. /**
  818. * 获取注册赠送优惠券列表
  819. * @return \think\response\Json
  820. * @author Qinii
  821. */
  822. public function getRegisterCoupon()
  823. {
  824. [$page, $limit] = $this->getPage();
  825. $storeCouponRepository = app()->make(StoreCouponRepository::class);
  826. if (!systemConfig('register_give_coupon')) return app('json')->success([]);
  827. $data = $storeCouponRepository->getList(0,['coupon_ids' => systemConfig('register_give_coupon')],$page, $limit);
  828. return app('json')->success($data);
  829. }
  830. }