User.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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. * @return mixed
  195. * @throws DataNotFoundException
  196. * @throws DbException
  197. * @throws ModelNotFoundException
  198. * @author xaboy
  199. * @day 2020/6/22
  200. */
  201. public function spread_order()
  202. {
  203. [$page, $limit] = $this->getPage();
  204. $where= $this->request->params(['keyword']);
  205. [$start,$stop]= $this->request->params(['start','stop'],true);
  206. $where['create_time'] = $start&&$stop ? date('Y/m/d',$start).'-'.date('Y/m/d',$stop) : '';
  207. $data = $this->repository->subOrder($this->request->uid(), $page, $limit,$where);
  208. return app('json')->success($data);
  209. }
  210. /**
  211. * 绑定手机号
  212. * @return mixed
  213. * @author Qinii
  214. * @day 2020-06-18
  215. */
  216. public function binding()
  217. {
  218. $data = $this->request->params(['phone', 'sms_code']);
  219. $sms_code = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['sms_code'], 'binding');
  220. if (!$data['sms_code'] || !$sms_code)
  221. return app('json')->fail('验证码不正确');
  222. $user = $this->repository->accountByUser($data['phone']);
  223. if ($user) {
  224. // if (systemConfig('is_phone_login') === '1') {
  225. // return app('json')->fail('已开启强制绑定手机号功能');
  226. // }
  227. $data = ['phone' => $data['phone']];
  228. } else {
  229. $data = ['account' => $data['phone'], 'phone' => $data['phone']];
  230. }
  231. $this->repository->update($this->request->uid(), $data);
  232. return app('json')->success('绑定成功');
  233. }
  234. /**
  235. * 小程序获取手机号绑定
  236. * @author Qinii
  237. * @day 10/11/21
  238. */
  239. public function mpPhone()
  240. {
  241. $code = $this->request->param('code');
  242. $iv = $this->request->param('iv');
  243. $encryptedData = $this->request->param('encryptedData');
  244. $miniProgramService = MiniProgramService::create();
  245. $userInfoCong = $miniProgramService->getUserInfo($code);
  246. $session_key = $userInfoCong['session_key'];
  247. $data = $miniProgramService->encryptor($session_key, $iv, $encryptedData);
  248. $user = $this->repository->accountByUser($data['purePhoneNumber']);
  249. if ($user) {
  250. $data = ['phone' => $data['purePhoneNumber']];
  251. } else {
  252. $data = ['account' => $data['purePhoneNumber'], 'phone' => $data['purePhoneNumber']];
  253. }
  254. $this->repository->update($this->request->uid(), $data);
  255. return app('json')->success('绑定成功');
  256. }
  257. /**
  258. * 推广的用户列表
  259. * @return mixed
  260. * @throws DataNotFoundException
  261. * @throws DbException
  262. * @throws ModelNotFoundException
  263. * @author xaboy
  264. * @day 2020/6/22
  265. */
  266. public function spread_list()
  267. {
  268. $where = $this->request->params([ 'sort', 'keyword']);
  269. [$start,$stop]= $this->request->params(['start','stop'],true);
  270. $where['spread_time'] = $start&&$stop ? date('Y/m/d',$start).'-'.date('Y/m/d',$stop) : '';
  271. $level = $this->request->param('level');
  272. [$page, $limit] = $this->getPage();
  273. return app('json')->success($level == 2
  274. ? $this->repository->getTwoLevelList($this->request->uid(),$where, $page, $limit)
  275. : $this->repository->getOneLevelList($this->request->uid(),$where, $page, $limit));
  276. }
  277. /**
  278. * 推广人数排行
  279. * @return mixed
  280. * @author xaboy
  281. * @day 2020/6/22
  282. */
  283. public function spread_top()
  284. {
  285. [$page, $limit] = $this->getPage();
  286. $type = $this->request->param('type', 0);
  287. $func = $type == 1 ? 'spreadMonthTop' : 'spreadWeekTop';
  288. $data = $this->repository->{$func}($page, $limit);
  289. return app('json')->success($data);
  290. }
  291. /**
  292. * 推广佣金排行
  293. * @return mixed
  294. * @author xaboy
  295. * @day 2020/6/22
  296. */
  297. public function brokerage_top()
  298. {
  299. [$page, $limit] = $this->getPage();
  300. $type = $this->request->param('type', 'week');
  301. $uid = $this->request->uid();
  302. $func = $type == 'month' ? 'brokerageMonthTop' : 'brokerageWeekTop';
  303. $data = $this->repository->{$func}($uid, $page, $limit);
  304. return app('json')->success($data);
  305. }
  306. /**
  307. * 访问记录
  308. * @param UserVisitRepository $repository
  309. * @return \think\response\Json
  310. * @author wuhaotian
  311. * @email 442384644@qq.com
  312. * @date 2024/7/10
  313. */
  314. public function history(UserVisitRepository $repository)
  315. {
  316. $uid = $this->request->uid();
  317. [$page, $limit] = $this->getPage();
  318. return app('json')->success($repository->getHistory($uid, $page, $limit));
  319. }
  320. /**
  321. * 删除访问记录
  322. * @param $id
  323. * @param UserVisitRepository $repository
  324. * @return \think\response\Json
  325. * @throws DbException
  326. * @author wuhaotian
  327. * @email 442384644@qq.com
  328. * @date 2024/7/10
  329. */
  330. public function deleteHistory($id, UserVisitRepository $repository)
  331. {
  332. $uid = $this->request->uid();
  333. if (!$repository->getWhereCount(['user_visit_id' => $id, 'uid' => $uid]))
  334. return app('json')->fail('数据不存在');
  335. $repository->delete($id);
  336. return app('json')->success('删除成功');
  337. }
  338. /**
  339. * 批量删除访问记录
  340. * @param UserVisitRepository $repository
  341. * @return \think\response\Json
  342. * @author wuhaotian
  343. * @email 442384644@qq.com
  344. * @date 2024/7/10
  345. */
  346. public function deleteHistoryBatch(UserVisitRepository $repository)
  347. {
  348. $uid = $this->request->uid();
  349. $data = $this->request->param('ids');
  350. if (!empty($data) && is_array($data)) {
  351. foreach ($data as $id) {
  352. if (!$repository->getWhereCount(['user_visit_id' => $id, 'uid' => $uid]))
  353. return app('json')->fail('数据不存在');
  354. }
  355. $repository->batchDelete($data, null);
  356. }
  357. if ($data == 1)
  358. $repository->batchDelete(null, $uid);
  359. return app('json')->success('删除成功');
  360. }
  361. /**
  362. * 获取多账号信息
  363. * @return \think\response\Json
  364. * @author wuhaotian
  365. * @email 442384644@qq.com
  366. * @date 2024/7/10
  367. */
  368. public function account()
  369. {
  370. $user = $this->user;
  371. if (!$user->phone) return app('json')->fail('请绑定手机号');
  372. return app('json')->success($this->repository->selfUserList($user->phone));
  373. }
  374. /**
  375. * 切换账号
  376. * @return \think\response\Json
  377. * @author wuhaotian
  378. * @email 442384644@qq.com
  379. * @date 2024/7/10
  380. */
  381. public function switchUser()
  382. {
  383. $uid = (int)$this->request->param('uid');
  384. if (!$uid) return app('json')->fail('用户不存在');
  385. $userInfo = $this->user;
  386. if (!$userInfo->phone) return app('json')->fail('请绑定手机号');
  387. $user = $this->repository->switchUser($userInfo, $uid);
  388. $tokenInfo = $this->repository->createToken($user);
  389. $this->repository->loginAfter($user);
  390. return app('json')->success($this->repository->returnToken($user, $tokenInfo));
  391. }
  392. /**
  393. * 编辑用户信息
  394. * @return \think\response\Json
  395. * @throws DbException
  396. * @author wuhaotian
  397. * @email 442384644@qq.com
  398. * @date 2024/7/10
  399. */
  400. public function edit()
  401. {
  402. $data = $this->request->params(['avatar', 'nickname']);
  403. $uid = (int)$this->request->param('uid');
  404. if (!$uid) return app('json')->fail('用户不存在');
  405. if (empty($data['avatar'])) unset($data['avatar']);
  406. if (empty($data['nickname'])) unset($data['nickname']);
  407. if (empty($data)) return app('json')->fail('参数丢失');
  408. $this->repository->update($this->request->uid(), $data);
  409. return app('json')->success('修改成功');
  410. }
  411. /**
  412. * 修改密码
  413. * @return \think\response\Json
  414. * @throws DbException
  415. * @author wuhaotian
  416. * @email 442384644@qq.com
  417. * @date 2024/7/10
  418. */
  419. public function changePassword()
  420. {
  421. $data = $this->request->params(['repassword','password', 'sms_code']);
  422. if (!$this->user->phone)
  423. return app('json')->fail('请先绑定手机号');
  424. if (empty($data['repassword']) || empty($data['password']))
  425. return app('json')->fail('请输入密码');
  426. if ($data['repassword'] !== $data['password'])
  427. return app('json')->fail('两次密码不一致');
  428. $sms_code = app()->make(SmsService::class)->checkSmsCode($this->user->phone, $data['sms_code'], 'change_pwd');
  429. if (!$data['sms_code'] || !$sms_code)
  430. return app('json')->fail('验证码不正确');
  431. $password = $this->repository->encodePassword($data['password']);
  432. $this->repository->update($this->request->uid(), ['pwd' => $password]);
  433. return app('json')->success('绑定成功');
  434. }
  435. /**
  436. * 修改手机号
  437. * @return \think\response\Json
  438. * @throws DataNotFoundException
  439. * @throws DbException
  440. * @throws ModelNotFoundException
  441. * @author wuhaotian
  442. * @email 442384644@qq.com
  443. * @date 2024/7/10
  444. */
  445. public function changePhone()
  446. {
  447. $data = $this->request->params(['phone', 'sms_code']);
  448. $sms_code = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['sms_code'], 'change_phone');
  449. if (!$data['sms_code'] || !$sms_code)
  450. return app('json')->fail('验证码不正确');
  451. $user = $this->repository->accountByUser($data['phone']);
  452. $data['main_uid'] = 0;
  453. if ($user) {
  454. if ($this->request->userInfo()->account !== $data['phone']) {
  455. $data['account'] = $this->request->userInfo()->account.'_'.$this->request->uid();
  456. }
  457. } else {
  458. $data['account'] = $data['phone'];
  459. }
  460. unset($data['sms_code']);
  461. $this->repository->update($this->request->uid(), $data);
  462. return app('json')->success('修改成功');
  463. }
  464. /**
  465. * 获取协议
  466. * @param $key
  467. * @return \think\response\Json
  468. * @author wuhaotian
  469. * @email 442384644@qq.com
  470. * @date 2024/7/10
  471. */
  472. public function getAgree($key)
  473. {
  474. $make = app()->make(CacheRepository::class);
  475. $data = $make->getResult($key);
  476. return app('json')->success($data);
  477. }
  478. /**
  479. * 积分信息
  480. * @param UserBillRepository $make
  481. * @return \think\response\Json
  482. * @author wuhaotian
  483. * @email 442384644@qq.com
  484. * @date 2024/7/10
  485. */
  486. public function integralInfo(UserBillRepository $make)
  487. {
  488. if (!systemConfig('integral_status')) {
  489. return app('json')->fail('积分功能未开启');
  490. }
  491. $integral = $this->user->integral;
  492. $lockIntegral = $make->lockIntegral($this->user->uid);
  493. $deductionIntegral = $make->deductionIntegral($this->user->uid);
  494. $totalGainIntegral = $make->totalGainIntegral($this->user->uid);
  495. $make1 = app()->make(IntegralRepository::class);
  496. $nextClearDay = $make1->getTimeoutDay();
  497. $status = $nextClearDay < strtotime('+20 day');
  498. $invalidDay = $make1->getInvalidDay();
  499. if ($status && $integral > 0 && $invalidDay) {
  500. $validIntegral = $make->validIntegral($this->user->uid, date('Y-m-d H:i:s', $invalidDay), date('Y-m-d H:i:s', $nextClearDay));
  501. if ($integral > $validIntegral) {
  502. $nextClearIntegral = (int)bcsub($integral, $validIntegral, 0);
  503. } else {
  504. $nextClearIntegral = 0;
  505. }
  506. } else {
  507. $nextClearIntegral = 0;
  508. }
  509. $nextClearDay = date('m月d日', $nextClearDay);
  510. $clear = compact('nextClearDay', 'status', 'nextClearIntegral');
  511. return app('json')->success(compact('integral', 'lockIntegral', 'deductionIntegral', 'totalGainIntegral', 'clear'));
  512. }
  513. /**
  514. * 积分列表
  515. * @param UserBillRepository $repository
  516. * @return \think\response\Json
  517. * @author wuhaotian
  518. * @email 442384644@qq.com
  519. * @date 2024/7/10
  520. */
  521. public function integralList(UserBillRepository $repository)
  522. {
  523. if (!systemConfig('integral_status')) {
  524. return app('json')->fail('积分功能未开启');
  525. }
  526. [$page, $limit] = $this->getPage();
  527. $data = $repository->userList(['category' => 'integral'], $this->user->uid, $page, $limit);
  528. return app('json')->success($data);
  529. }
  530. /**
  531. * 客服列表
  532. * @return \think\response\Json
  533. * @author wuhaotian
  534. * @email 442384644@qq.com
  535. * @date 2024/7/10
  536. */
  537. public function services()
  538. {
  539. $uid = $this->user->uid;
  540. $where = $this->request->params(['is_verify', 'customer', 'is_goods', ['is_open',1]]);
  541. $is_sys = $this->request->param('is_sys');
  542. return app('json')->success(app()->make(StoreServiceRepository::class)->getServices($uid, $where,$is_sys));
  543. }
  544. /**
  545. * 会员信息
  546. * @return \think\response\Json
  547. * @author wuhaotian
  548. * @email 442384644@qq.com
  549. * @date 2024/7/10
  550. */
  551. public function memberInfo()
  552. {
  553. if (!systemConfig('member_status')) return app('json')->fail('未开启会员功能');
  554. $make = app()->make(UserBrokerageRepository::class);
  555. $data['uid'] = $this->user->uid;
  556. $data['avatar'] = $this->user->avatar;
  557. $data['nickname'] = $this->user->nickname;
  558. $data['member_value'] = $this->user->member_value;
  559. $data['member'] = $this->user->member;
  560. $next_level = $make->getNextLevel($this->user->member_level, 1);
  561. if (!$next_level && $data['member']) {
  562. $next_level = $this->user->member->toArray();
  563. $next_level['brokerage_rule']['value'] = 0;
  564. }
  565. $data['next_level'] = $next_level;
  566. $makeInteres = app()->make(MemberinterestsRepository::class);
  567. $data['interests'] = systemConfig('member_interests_status') ? $makeInteres->getInterestsByLevel($makeInteres::TYPE_FREE,$this->user->member_level) : [] ;
  568. $data['today'] = app()->make(UserBillRepository::class)->search([
  569. 'category' => 'sys_members',
  570. 'uid' => $this->user->uid,
  571. 'day' => date('Y-m-d', time()),
  572. 'pm' => 1,
  573. ])->sum('number');
  574. $config_key = ['member_pay_num', 'member_sign_num', 'member_reply_num', 'member_share_num'];
  575. if (systemConfig('community_status')) $config_key[] = 'member_community_num';
  576. $config= systemConfig($config_key);
  577. if ($this->user->is_svip > 0) {
  578. foreach ($config as $key => $item) {
  579. $data['config'][$key] = $item .' x' . $makeInteres->getSvipInterestVal($makeInteres::HAS_TYPE_MEMBER).' ';
  580. }
  581. } else {
  582. $data['config'] = $config;
  583. }
  584. return app('json')->success($data);
  585. }
  586. /**
  587. * 推广通知
  588. * @return \think\response\Json
  589. * @throws DataNotFoundException
  590. * @throws DbException
  591. * @throws ModelNotFoundException
  592. * @author wuhaotian
  593. * @email 442384644@qq.com
  594. * @date 2024/7/10
  595. */
  596. public function notice()
  597. {
  598. $type = $this->request->param('type',0);
  599. $arr = [
  600. '0' => 'brokerage_level',
  601. '1' => 'member_level',
  602. ];
  603. $filed = $arr[$type];
  604. if (!$this->user->$filed) {
  605. return app('json')->fail('无需通知');
  606. }
  607. $make = app()->make(CacheRepository::class);
  608. $key = 'notice_' . $filed . '_' . $this->user->uid;
  609. if ($ret = $make->getWhere(['key' => $key])) {
  610. $userBrokerageRepository = app()->make(UserBrokerageRepository::class);
  611. $level = app()->make(UserBrokerageRepository::class)->getWhere(
  612. ['brokerage_level' => $ret->result, 'type' => $type],
  613. 'brokerage_name,brokerage_icon,brokerage_rule'
  614. );
  615. $next_level = $userBrokerageRepository->getNextLevel($this->user->$filed, $type);
  616. $ret->delete();
  617. $type = $next_level ? 'level' : 'top';
  618. return app('json')->success(compact('type', 'level'));
  619. }
  620. return app('json')->fail('已通知');
  621. }
  622. /**
  623. * 修改基本信息
  624. * @param UserBaseInfoValidate $validate
  625. * @return \think\response\Json
  626. * @author wuhaotian
  627. * @email 442384644@qq.com
  628. * @date 2024/7/10
  629. */
  630. public function updateBaseInfo(UserBaseInfoValidate $validate)
  631. {
  632. if (systemConfig('open_update_info') != '1') {
  633. return app('json')->fail('不允许修改基本信息');
  634. }
  635. $nickname = $this->request->param('nickname');
  636. $avatar = $this->request->param('avatar');
  637. if (!$nickname && !$avatar)
  638. return app('json')->fail('未做任何修改');
  639. $user = $this->request->userInfo();
  640. if(!empty($nickname)) {
  641. $validate->check(['nickname' => $nickname]);
  642. $data['nickname'] = $nickname;
  643. MiniProgramService::create()->msgSecCheck($user, $data['nickname'],1,0);
  644. }
  645. if(!empty($avatar)) {
  646. $data['avatar'] = $avatar;
  647. }
  648. $this->repository->updateBaseInfo($data,$user);
  649. return app('json')->success('修改成功');
  650. }
  651. }