User.php 29 KB

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