User.php 26 KB

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