User.php 26 KB

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