User.php 39 KB

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