User.php 28 KB

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