User.php 38 KB

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