User.php 34 KB

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