User.php 30 KB

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