User.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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\api\user;
  12. use app\common\repositories\store\IntegralRepository;
  13. use app\common\repositories\store\service\StoreServiceRepository;
  14. use app\common\repositories\system\CacheRepository;
  15. use app\common\repositories\user\MemberinterestsRepository;
  16. use app\common\repositories\user\UserBillRepository;
  17. use app\common\repositories\user\UserBrokerageRepository;
  18. use app\common\repositories\user\UserRepository;
  19. use app\common\repositories\user\UserVisitRepository;
  20. use app\validate\api\UserBaseInfoValidate;
  21. use crmeb\basic\BaseController;
  22. use crmeb\services\MiniProgramService;
  23. use crmeb\services\SmsService;
  24. use think\App;
  25. use think\db\exception\DataNotFoundException;
  26. use think\db\exception\DbException;
  27. use think\db\exception\ModelNotFoundException;
  28. class User extends BaseController
  29. {
  30. protected $repository;
  31. protected $user;
  32. public function __construct(App $app, UserRepository $repository)
  33. {
  34. parent::__construct($app);
  35. $this->repository = $repository;
  36. $this->user = $this->request->userInfo();
  37. }
  38. /**
  39. * 推广图片
  40. * @return mixed
  41. * @author xaboy
  42. * @day 2020/6/22
  43. */
  44. public function spread_image()
  45. {
  46. $type = $this->request->param('type');
  47. $res = $type == 'routine'
  48. ? $this->repository->routineSpreadImage($this->user)
  49. : $this->repository->wxSpreadImage($this->user);
  50. return app('json')->success($res);
  51. }
  52. /**
  53. * 推广图片v2
  54. * @return \think\response\Json
  55. * @author wuhaotian
  56. * @email 442384644@qq.com
  57. * @date 2024/7/10
  58. */
  59. public function spread_image_v2()
  60. {
  61. $type = $this->request->param('type');
  62. $user = $this->user;
  63. $siteName = systemConfig('site_name');
  64. $qrcode = $type == 'routine'
  65. ? $this->repository->mpQrcode($user)
  66. : $this->repository->wxQrcode($user);
  67. $poster = systemGroupData('spread_banner');
  68. $nickname = $user['nickname'];
  69. $mark = '邀请您加入' . $siteName;
  70. return app('json')->success(compact('qrcode', 'poster', 'nickname', 'mark'));
  71. }
  72. /**
  73. * 用户推广信息
  74. * @return \think\response\Json
  75. * @throws DbException
  76. * @author wuhaotian
  77. * @email 442384644@qq.com
  78. * @date 2024/7/10
  79. */
  80. public function spread_info()
  81. {
  82. $user = $this->user;
  83. $extensionInfo = get_extension_info($user);//获取用户是否可以分销以及是否内购
  84. if (!$extensionInfo['isPromoter']) return app('json')->fail('您还不是分销员');
  85. $make = app()->make(UserBrokerageRepository::class);
  86. $user->append(['one_level_count', 'lock_brokerage', 'two_level_count', 'spread_total', 'yesterday_brokerage', 'total_extract', 'total_brokerage', 'total_brokerage_price']);
  87. $show_brokerage = (bool)$make->search(['type' => 0])->count();
  88. $data = [
  89. 'total_brokerage_price' => $user->total_brokerage_price,
  90. 'lock_brokerage' => $user->lock_brokerage,
  91. 'one_level_count' => $user->one_level_count,
  92. 'two_level_count' => $user->two_level_count,
  93. 'spread_total' => $user->spread_total,
  94. 'yesterday_brokerage' => $user->yesterday_brokerage,
  95. 'total_extract' => $user->total_extract,
  96. 'total_brokerage' => $user->total_brokerage,
  97. 'brokerage_price' => $user->brokerage_price,
  98. 'show_brokerage' => $show_brokerage,
  99. 'brokerage' => $show_brokerage ? ($user->brokerage ?: ['brokerage_level' => 0, 'brokerage_name' => '普通分销员']) : null,
  100. 'now_money' => $user->now_money,
  101. 'broken_day' => (int)systemConfig('lock_brokerage_timer'),
  102. 'user_extract_min' => (int)systemConfig('user_extract_min'),
  103. ];
  104. return app('json')->success($data);
  105. }
  106. /**
  107. * 推广佣金列表
  108. * @return \think\response\Json
  109. * @author wuhaotian
  110. * @email 442384644@qq.com
  111. * @date 2024/7/10
  112. */
  113. public function brokerage_all()
  114. {
  115. return app('json')->success(app()->make(UserBrokerageRepository::class)->all(0));
  116. }
  117. /**
  118. * 推广佣金详情
  119. * @return \think\response\Json
  120. * @author wuhaotian
  121. * @email 442384644@qq.com
  122. * @date 2024/7/10
  123. */
  124. public function brokerage_info()
  125. {
  126. $make = app()->make(UserBrokerageRepository::class);
  127. $user = $this->user;
  128. $brokerage = $user->brokerage;
  129. $next_brokerage = $make->getNextLevel($user->brokerage_level) ?: $brokerage;
  130. $brokerage_rate = null;
  131. if ($next_brokerage || $brokerage) {
  132. $brokerage_rate = $make->getLevelRate($user, $next_brokerage);
  133. }
  134. $down_brokerage = null;
  135. if ($next_brokerage) {
  136. $down_brokerage = $make->getNextLevel($next_brokerage->brokerage_level);
  137. }
  138. $brokerage = $brokerage ?: ['brokerage_level' => 0, 'brokerage_name' => '普通分销员'];
  139. return app('json')->success(compact('brokerage', 'next_brokerage', 'brokerage_rate', 'down_brokerage'));
  140. }
  141. /**
  142. * 推广佣金通知
  143. * @return \think\response\Json
  144. * @author wuhaotian
  145. * @email 442384644@qq.com
  146. * @date 2024/7/10
  147. */
  148. public function brokerage_notice()
  149. {
  150. $user = $this->user;
  151. if (!$user->brokerage_level) {
  152. return app('json')->fail('无需通知');
  153. }
  154. $make = app()->make(CacheRepository::class);
  155. $key = 'notice_' . $user->uid . '_' . $user->brokerage_level;
  156. if ($make->getResult($key)) {
  157. return app('json')->fail('已通知');
  158. }
  159. $make->create(['key' => $key, 'result' => 1, 'expire_time' => 0]);
  160. $userBrokerageRepository = app()->make(UserBrokerageRepository::class);
  161. return app('json')->success(['type' => $userBrokerageRepository->getNextLevel($user->brokerage_level) ? 'level' : 'top']);
  162. }
  163. /**
  164. * 推广佣金明细
  165. * @param UserBillRepository $billRepository
  166. * @return mixed
  167. * @author xaboy
  168. * @day 2020/6/22
  169. */
  170. public function bill(UserBillRepository $billRepository)
  171. {
  172. [$page, $limit] = $this->getPage();
  173. return app('json')->success($billRepository->userList([
  174. 'now_money' => $this->request->param('type', 0),
  175. 'status' => 1,
  176. ], $this->request->uid(), $page, $limit));
  177. }
  178. /**
  179. * 佣金明细
  180. * @param UserBillRepository $billRepository
  181. * @return mixed
  182. * @author xaboy
  183. * @day 2020/6/22
  184. */
  185. public function brokerage_list(UserBillRepository $billRepository)
  186. {
  187. [$page, $limit] = $this->getPage();
  188. [$start,$stop]= $this->request->params(['start','stop'],true);
  189. $where['date'] = $start&&$stop ? date('Y/m/d',$start).'-'.date('Y/m/d',$stop) : '';
  190. $where['category'] = 'brokerage';
  191. return app('json')->success($billRepository->userList($where, $this->request->uid(), $page, $limit));
  192. }
  193. /**
  194. * 分红份额明细
  195. * @param UserBillRepository $billRepository
  196. * @return mixed
  197. * @author xaboy
  198. * @day 2020/6/22
  199. */
  200. public function award_range_list(UserBillRepository $billRepository)
  201. {
  202. [$page, $limit] = $this->getPage();
  203. return app('json')->success($billRepository->userList([
  204. // 'award_range' => $this->request->param('type', 0),
  205. 'status' => 1,
  206. 'category' => 'award_range'
  207. ], $this->request->uid(), $page, $limit));
  208. }
  209. /**
  210. * 分红积分明细
  211. * @param UserBillRepository $billRepository
  212. * @return mixed
  213. * @author xaboy
  214. * @day 2020/6/22
  215. */
  216. public function award_integral_list(UserBillRepository $billRepository)
  217. {
  218. [$page, $limit] = $this->getPage();
  219. return app('json')->success($billRepository->userList([
  220. // 'award_integral' => $this->request->param('type', 0),
  221. 'status' => 1,
  222. 'category' => 'award_integral'
  223. ], $this->request->uid(), $page, $limit));
  224. }
  225. /**
  226. * 用户分红积分提现
  227. * @return \think\response\Json
  228. */
  229. public function award_create()
  230. {
  231. $user = $this->request->userInfo();
  232. $where= $this->request->params(['num']);
  233. if ($where['num'] > $user['award_integral']){
  234. throw new \Exception('提现积分不能大于可拥有积分');
  235. }
  236. app()->make(UserRepository::class)->extractIntegral($user['uid'],$where['num']);
  237. return app('json')->success('已提现至佣金');
  238. }
  239. /**
  240. * @return mixed
  241. * @throws DataNotFoundException
  242. * @throws DbException
  243. * @throws ModelNotFoundException
  244. * @author xaboy
  245. * @day 2020/6/22
  246. */
  247. public function spread_order()
  248. {
  249. [$page, $limit] = $this->getPage();
  250. $where= $this->request->params(['keyword']);
  251. [$start,$stop]= $this->request->params(['start','stop'],true);
  252. $where['create_time'] = $start&&$stop ? date('Y/m/d',$start).'-'.date('Y/m/d',$stop) : '';
  253. $data = $this->repository->subOrder($this->request->uid(), $page, $limit,$where);
  254. return app('json')->success($data);
  255. }
  256. /**
  257. * 绑定手机号
  258. * @return mixed
  259. * @author Qinii
  260. * @day 2020-06-18
  261. */
  262. public function binding()
  263. {
  264. $data = $this->request->params(['phone', 'sms_code']);
  265. $sms_code = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['sms_code'], 'binding');
  266. if (!$data['sms_code'] || !$sms_code)
  267. return app('json')->fail('验证码不正确');
  268. $user = $this->repository->accountByUser($data['phone']);
  269. if ($user) {
  270. // if (systemConfig('is_phone_login') === '1') {
  271. // return app('json')->fail('已开启强制绑定手机号功能');
  272. // }
  273. $data = ['phone' => $data['phone']];
  274. } else {
  275. $data = ['account' => $data['phone'], 'phone' => $data['phone']];
  276. }
  277. $this->repository->update($this->request->uid(), $data);
  278. return app('json')->success('绑定成功');
  279. }
  280. /**
  281. * 小程序获取手机号绑定
  282. * @author Qinii
  283. * @day 10/11/21
  284. */
  285. public function mpPhone()
  286. {
  287. $code = $this->request->param('code');
  288. $iv = $this->request->param('iv');
  289. $encryptedData = $this->request->param('encryptedData');
  290. $miniProgramService = MiniProgramService::create();
  291. $userInfoCong = $miniProgramService->getUserInfo($code);
  292. $session_key = $userInfoCong['session_key'];
  293. $data = $miniProgramService->encryptor($session_key, $iv, $encryptedData);
  294. $user = $this->repository->accountByUser($data['purePhoneNumber']);
  295. if ($user) {
  296. $data = ['phone' => $data['purePhoneNumber']];
  297. } else {
  298. $data = ['account' => $data['purePhoneNumber'], 'phone' => $data['purePhoneNumber']];
  299. }
  300. $this->repository->update($this->request->uid(), $data);
  301. return app('json')->success('绑定成功');
  302. }
  303. /**
  304. * 推广的用户列表
  305. * @return mixed
  306. * @throws DataNotFoundException
  307. * @throws DbException
  308. * @throws ModelNotFoundException
  309. * @author xaboy
  310. * @day 2020/6/22
  311. */
  312. public function spread_list()
  313. {
  314. $where = $this->request->params([ 'sort', 'keyword']);
  315. [$start,$stop]= $this->request->params(['start','stop'],true);
  316. $where['spread_time'] = $start&&$stop ? date('Y/m/d',$start).'-'.date('Y/m/d',$stop) : '';
  317. $level = $this->request->param('level');
  318. [$page, $limit] = $this->getPage();
  319. return app('json')->success($level == 2
  320. ? $this->repository->getTwoLevelList($this->request->uid(),$where, $page, $limit)
  321. : $this->repository->getOneLevelList($this->request->uid(),$where, $page, $limit));
  322. }
  323. /**
  324. * 推广人数排行
  325. * @return mixed
  326. * @author xaboy
  327. * @day 2020/6/22
  328. */
  329. public function spread_top()
  330. {
  331. [$page, $limit] = $this->getPage();
  332. $type = $this->request->param('type', 0);
  333. $func = $type == 1 ? 'spreadMonthTop' : 'spreadWeekTop';
  334. $data = $this->repository->{$func}($page, $limit);
  335. return app('json')->success($data);
  336. }
  337. /**
  338. * 推广佣金排行
  339. * @return mixed
  340. * @author xaboy
  341. * @day 2020/6/22
  342. */
  343. public function brokerage_top()
  344. {
  345. [$page, $limit] = $this->getPage();
  346. $type = $this->request->param('type', 'week');
  347. $uid = $this->request->uid();
  348. $func = $type == 'month' ? 'brokerageMonthTop' : 'brokerageWeekTop';
  349. $data = $this->repository->{$func}($uid, $page, $limit);
  350. return app('json')->success($data);
  351. }
  352. /**
  353. * 访问记录
  354. * @param UserVisitRepository $repository
  355. * @return \think\response\Json
  356. * @author wuhaotian
  357. * @email 442384644@qq.com
  358. * @date 2024/7/10
  359. */
  360. public function history(UserVisitRepository $repository)
  361. {
  362. $uid = $this->request->uid();
  363. [$page, $limit] = $this->getPage();
  364. return app('json')->success($repository->getHistory($uid, $page, $limit));
  365. }
  366. /**
  367. * 删除访问记录
  368. * @param $id
  369. * @param UserVisitRepository $repository
  370. * @return \think\response\Json
  371. * @throws DbException
  372. * @author wuhaotian
  373. * @email 442384644@qq.com
  374. * @date 2024/7/10
  375. */
  376. public function deleteHistory($id, UserVisitRepository $repository)
  377. {
  378. $uid = $this->request->uid();
  379. if (!$repository->getWhereCount(['user_visit_id' => $id, 'uid' => $uid]))
  380. return app('json')->fail('数据不存在');
  381. $repository->delete($id);
  382. return app('json')->success('删除成功');
  383. }
  384. /**
  385. * 批量删除访问记录
  386. * @param UserVisitRepository $repository
  387. * @return \think\response\Json
  388. * @author wuhaotian
  389. * @email 442384644@qq.com
  390. * @date 2024/7/10
  391. */
  392. public function deleteHistoryBatch(UserVisitRepository $repository)
  393. {
  394. $uid = $this->request->uid();
  395. $data = $this->request->param('ids');
  396. if (!empty($data) && is_array($data)) {
  397. foreach ($data as $id) {
  398. if (!$repository->getWhereCount(['user_visit_id' => $id, 'uid' => $uid]))
  399. return app('json')->fail('数据不存在');
  400. }
  401. $repository->batchDelete($data, null);
  402. }
  403. if ($data == 1)
  404. $repository->batchDelete(null, $uid);
  405. return app('json')->success('删除成功');
  406. }
  407. /**
  408. * 获取多账号信息
  409. * @return \think\response\Json
  410. * @author wuhaotian
  411. * @email 442384644@qq.com
  412. * @date 2024/7/10
  413. */
  414. public function account()
  415. {
  416. $user = $this->user;
  417. if (!$user->phone) return app('json')->fail('请绑定手机号');
  418. return app('json')->success($this->repository->selfUserList($user->phone));
  419. }
  420. /**
  421. * 切换账号
  422. * @return \think\response\Json
  423. * @author wuhaotian
  424. * @email 442384644@qq.com
  425. * @date 2024/7/10
  426. */
  427. public function switchUser()
  428. {
  429. $uid = (int)$this->request->param('uid');
  430. if (!$uid) return app('json')->fail('用户不存在');
  431. $userInfo = $this->user;
  432. if (!$userInfo->phone) return app('json')->fail('请绑定手机号');
  433. $user = $this->repository->switchUser($userInfo, $uid);
  434. $tokenInfo = $this->repository->createToken($user);
  435. $this->repository->loginAfter($user);
  436. return app('json')->success($this->repository->returnToken($user, $tokenInfo));
  437. }
  438. /**
  439. * 编辑用户信息
  440. * @return \think\response\Json
  441. * @throws DbException
  442. * @author wuhaotian
  443. * @email 442384644@qq.com
  444. * @date 2024/7/10
  445. */
  446. public function edit()
  447. {
  448. $data = $this->request->params(['avatar', 'nickname']);
  449. $uid = (int)$this->request->param('uid');
  450. if (!$uid) return app('json')->fail('用户不存在');
  451. if (empty($data['avatar'])) unset($data['avatar']);
  452. if (empty($data['nickname'])) unset($data['nickname']);
  453. if (empty($data)) return app('json')->fail('参数丢失');
  454. $this->repository->update($this->request->uid(), $data);
  455. return app('json')->success('修改成功');
  456. }
  457. /**
  458. * 修改密码
  459. * @return \think\response\Json
  460. * @throws DbException
  461. * @author wuhaotian
  462. * @email 442384644@qq.com
  463. * @date 2024/7/10
  464. */
  465. public function changePassword()
  466. {
  467. $data = $this->request->params(['repassword','password', 'sms_code']);
  468. if (!$this->user->phone)
  469. return app('json')->fail('请先绑定手机号');
  470. if (empty($data['repassword']) || empty($data['password']))
  471. return app('json')->fail('请输入密码');
  472. if ($data['repassword'] !== $data['password'])
  473. return app('json')->fail('两次密码不一致');
  474. $sms_code = app()->make(SmsService::class)->checkSmsCode($this->user->phone, $data['sms_code'], 'change_pwd');
  475. if (!$data['sms_code'] || !$sms_code)
  476. return app('json')->fail('验证码不正确');
  477. $password = $this->repository->encodePassword($data['password']);
  478. $this->repository->update($this->request->uid(), ['pwd' => $password]);
  479. return app('json')->success('绑定成功');
  480. }
  481. /**
  482. * 修改手机号
  483. * @return \think\response\Json
  484. * @throws DataNotFoundException
  485. * @throws DbException
  486. * @throws ModelNotFoundException
  487. * @author wuhaotian
  488. * @email 442384644@qq.com
  489. * @date 2024/7/10
  490. */
  491. public function changePhone()
  492. {
  493. $data = $this->request->params(['phone', 'sms_code']);
  494. $sms_code = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['sms_code'], 'change_phone');
  495. if (!$data['sms_code'] || !$sms_code)
  496. return app('json')->fail('验证码不正确');
  497. $user = $this->repository->accountByUser($data['phone']);
  498. $data['main_uid'] = 0;
  499. if ($user) {
  500. if ($this->request->userInfo()->account !== $data['phone']) {
  501. $data['account'] = $this->request->userInfo()->account.'_'.$this->request->uid();
  502. }
  503. } else {
  504. $data['account'] = $data['phone'];
  505. }
  506. unset($data['sms_code']);
  507. $this->repository->update($this->request->uid(), $data);
  508. return app('json')->success('修改成功');
  509. }
  510. /**
  511. * 获取协议
  512. * @param $key
  513. * @return \think\response\Json
  514. * @author wuhaotian
  515. * @email 442384644@qq.com
  516. * @date 2024/7/10
  517. */
  518. public function getAgree($key)
  519. {
  520. $make = app()->make(CacheRepository::class);
  521. $data = $make->getResult($key);
  522. return app('json')->success($data);
  523. }
  524. /**
  525. * 积分信息
  526. * @param UserBillRepository $make
  527. * @return \think\response\Json
  528. * @author wuhaotian
  529. * @email 442384644@qq.com
  530. * @date 2024/7/10
  531. */
  532. public function integralInfo(UserBillRepository $make)
  533. {
  534. if (!systemConfig('integral_status')) {
  535. return app('json')->fail('积分功能未开启');
  536. }
  537. $integral = $this->user->integral;
  538. $lockIntegral = $make->lockIntegral($this->user->uid);
  539. $deductionIntegral = $make->deductionIntegral($this->user->uid);
  540. $totalGainIntegral = $make->totalGainIntegral($this->user->uid);
  541. $make1 = app()->make(IntegralRepository::class);
  542. $nextClearDay = $make1->getTimeoutDay();
  543. $status = $nextClearDay < strtotime('+20 day');
  544. $invalidDay = $make1->getInvalidDay();
  545. if ($status && $integral > 0 && $invalidDay) {
  546. $validIntegral = $make->validIntegral($this->user->uid, date('Y-m-d H:i:s', $invalidDay), date('Y-m-d H:i:s', $nextClearDay));
  547. if ($integral > $validIntegral) {
  548. $nextClearIntegral = (int)bcsub($integral, $validIntegral, 0);
  549. } else {
  550. $nextClearIntegral = 0;
  551. }
  552. } else {
  553. $nextClearIntegral = 0;
  554. }
  555. $nextClearDay = date('m月d日', $nextClearDay);
  556. $clear = compact('nextClearDay', 'status', 'nextClearIntegral');
  557. return app('json')->success(compact('integral', 'lockIntegral', 'deductionIntegral', 'totalGainIntegral', 'clear'));
  558. }
  559. /**
  560. * 积分列表
  561. * @param UserBillRepository $repository
  562. * @return \think\response\Json
  563. * @author wuhaotian
  564. * @email 442384644@qq.com
  565. * @date 2024/7/10
  566. */
  567. public function integralList(UserBillRepository $repository)
  568. {
  569. if (!systemConfig('integral_status')) {
  570. return app('json')->fail('积分功能未开启');
  571. }
  572. [$page, $limit] = $this->getPage();
  573. $data = $repository->userList(['category' => 'integral'], $this->user->uid, $page, $limit);
  574. return app('json')->success($data);
  575. }
  576. /**
  577. * 客服列表
  578. * @return \think\response\Json
  579. * @author wuhaotian
  580. * @email 442384644@qq.com
  581. * @date 2024/7/10
  582. */
  583. public function services()
  584. {
  585. $uid = $this->user->uid;
  586. $where = $this->request->params(['is_verify', 'customer', 'is_goods', ['is_open',1]]);
  587. $is_sys = $this->request->param('is_sys');
  588. return app('json')->success(app()->make(StoreServiceRepository::class)->getServices($uid, $where,$is_sys));
  589. }
  590. /**
  591. * 会员信息
  592. * @return \think\response\Json
  593. * @author wuhaotian
  594. * @email 442384644@qq.com
  595. * @date 2024/7/10
  596. */
  597. public function memberInfo()
  598. {
  599. if (!systemConfig('member_status')) return app('json')->fail('未开启会员功能');
  600. $make = app()->make(UserBrokerageRepository::class);
  601. $data['uid'] = $this->user->uid;
  602. $data['avatar'] = $this->user->avatar;
  603. $data['nickname'] = $this->user->nickname;
  604. $data['member_value'] = $this->user->member_value;
  605. $data['member'] = $this->user->member;
  606. $next_level = $make->getNextLevel($this->user->member_level, 1);
  607. if (!$next_level && $data['member']) {
  608. $next_level = $this->user->member->toArray();
  609. $next_level['brokerage_rule']['value'] = 0;
  610. }
  611. $data['next_level'] = $next_level;
  612. $makeInteres = app()->make(MemberinterestsRepository::class);
  613. $data['interests'] = systemConfig('member_interests_status') ? $makeInteres->getInterestsByLevel($makeInteres::TYPE_FREE,$this->user->member_level) : [] ;
  614. $data['today'] = app()->make(UserBillRepository::class)->search([
  615. 'category' => 'sys_members',
  616. 'uid' => $this->user->uid,
  617. 'day' => date('Y-m-d', time()),
  618. 'pm' => 1,
  619. ])->sum('number');
  620. $config_key = ['member_pay_num', 'member_sign_num', 'member_reply_num', 'member_share_num'];
  621. if (systemConfig('community_status')) $config_key[] = 'member_community_num';
  622. $config= systemConfig($config_key);
  623. if ($this->user->is_svip > 0) {
  624. foreach ($config as $key => $item) {
  625. $data['config'][$key] = $item .' x' . $makeInteres->getSvipInterestVal($makeInteres::HAS_TYPE_MEMBER).' ';
  626. }
  627. } else {
  628. $data['config'] = $config;
  629. }
  630. return app('json')->success($data);
  631. }
  632. /**
  633. * 推广通知
  634. * @return \think\response\Json
  635. * @throws DataNotFoundException
  636. * @throws DbException
  637. * @throws ModelNotFoundException
  638. * @author wuhaotian
  639. * @email 442384644@qq.com
  640. * @date 2024/7/10
  641. */
  642. public function notice()
  643. {
  644. $type = $this->request->param('type',0);
  645. $arr = [
  646. '0' => 'brokerage_level',
  647. '1' => 'member_level',
  648. ];
  649. $filed = $arr[$type];
  650. if (!$this->user->$filed) {
  651. return app('json')->fail('无需通知');
  652. }
  653. $make = app()->make(CacheRepository::class);
  654. $key = 'notice_' . $filed . '_' . $this->user->uid;
  655. if ($ret = $make->getWhere(['key' => $key])) {
  656. $userBrokerageRepository = app()->make(UserBrokerageRepository::class);
  657. $level = app()->make(UserBrokerageRepository::class)->getWhere(
  658. ['brokerage_level' => $ret->result, 'type' => $type],
  659. 'brokerage_name,brokerage_icon,brokerage_rule'
  660. );
  661. $next_level = $userBrokerageRepository->getNextLevel($this->user->$filed, $type);
  662. $ret->delete();
  663. $type = $next_level ? 'level' : 'top';
  664. return app('json')->success(compact('type', 'level'));
  665. }
  666. return app('json')->fail('已通知');
  667. }
  668. /**
  669. * 修改基本信息
  670. * @param UserBaseInfoValidate $validate
  671. * @return \think\response\Json
  672. * @author wuhaotian
  673. * @email 442384644@qq.com
  674. * @date 2024/7/10
  675. */
  676. public function updateBaseInfo(UserBaseInfoValidate $validate)
  677. {
  678. if (systemConfig('open_update_info') != '1') {
  679. return app('json')->fail('不允许修改基本信息');
  680. }
  681. $nickname = $this->request->param('nickname');
  682. $avatar = $this->request->param('avatar');
  683. if (!$nickname && !$avatar)
  684. return app('json')->fail('未做任何修改');
  685. $user = $this->request->userInfo();
  686. if(!empty($nickname)) {
  687. $validate->check(['nickname' => $nickname]);
  688. $data['nickname'] = $nickname;
  689. MiniProgramService::create()->msgSecCheck($user, $data['nickname'],1,0);
  690. }
  691. if(!empty($avatar)) {
  692. $data['avatar'] = $avatar;
  693. }
  694. $this->repository->updateBaseInfo($data,$user);
  695. return app('json')->success('修改成功');
  696. }
  697. }