User.php 27 KB

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