User.php 30 KB

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