UserController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\http\validates\user\AddressValidate;
  4. use app\models\system\SystemCity;
  5. use app\models\system\SystemGroupLevel;
  6. use app\models\system\SystemUserLevel;
  7. use app\models\user\UserGroupLevel;
  8. use app\models\user\UserVisit;
  9. use think\db\exception\DataNotFoundException;
  10. use think\db\exception\DbException;
  11. use think\db\exception\ModelNotFoundException;
  12. use think\exception\ValidateException;
  13. use app\Request;
  14. use app\models\user\UserLevel;
  15. use app\models\user\UserSign;
  16. use app\models\store\StoreBargain;
  17. use app\models\store\StoreCombination;
  18. use app\models\store\StoreCouponUser;
  19. use app\models\store\StoreOrder;
  20. use app\models\store\StoreProductRelation;
  21. use app\models\store\StoreSeckill;
  22. use app\models\user\User;
  23. use app\models\user\UserAddress;
  24. use app\models\user\UserBill;
  25. use app\models\user\UserExtract;
  26. use app\models\user\UserNotice;
  27. use crmeb\services\GroupDataService;
  28. use crmeb\services\UtilService;
  29. /**
  30. * 用户类
  31. * Class UserController
  32. * @package app\api\controller\store
  33. */
  34. class UserController
  35. {
  36. /**
  37. * 获取用户信息
  38. * @param Request $request
  39. * @return mixed
  40. */
  41. public function userInfo(Request $request)
  42. {
  43. $info = $request->user()->toArray();
  44. $broken_time = intval(sys_config('extract_time'));
  45. $search_time = time() - 86400 * $broken_time;
  46. //返佣 +
  47. $brokerage_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'brokerage_price'])
  48. ->where('add_time', '>', $search_time)
  49. ->where('pm', 1)
  50. ->sum('number');
  51. //退款退的佣金 -
  52. $refund_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'brokerage_price'])
  53. ->where('add_time', '>', $search_time)
  54. ->where('pm', 0)
  55. ->sum('number');
  56. $info['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  57. if ($info['broken_commission'] < 0)
  58. $info['broken_commission'] = 0;
  59. $info['commissionCount'] = bcsub($info['brokerage_price'], $info['broken_commission'], 2);
  60. if ($info['commissionCount'] < 0)
  61. $info['commissionCount'] = 0;
  62. // 1. 添加总收益字段:该用户在user_bill表里category为brokerage_price且pm为1的总收益
  63. $total_income = UserBill::where(['uid' => $info['uid'], 'category' => 'brokerage_price', 'pm' => 1])
  64. ->sum('number');
  65. $info['total_income'] = $total_income > 0 ? $total_income : 0;
  66. // 2. 添加个人业绩字段:该用户下级推荐人(spread_uid是该用户uid)的所有用户的achievement字段值的总和
  67. $directSubordinateUids = User::where('spread_uid', $info['uid'])->column('uid');
  68. $personal_achievement = 0;
  69. if (!empty($directSubordinateUids)) {
  70. $personal_achievement = User::whereIn('uid', $directSubordinateUids)
  71. ->sum('achievement');
  72. }
  73. $info['personal_achievement'] = $personal_achievement > 0 ? $personal_achievement : 0;
  74. // 3. 添加团队业绩字段:包括下级推荐人的所有下级以及不断延续下去的团队所有用户的achievement字段值的总和
  75. $teamUids = $this->getAllTeamMembers($info['uid']);
  76. $team_achievement = 0;
  77. if (!empty($teamUids)) {
  78. $team_achievement = User::whereIn('uid', $teamUids)
  79. ->sum('achievement');
  80. }
  81. $info['team_achievement'] = $team_achievement > 0 ? $team_achievement : 0;
  82. $minGrade = SystemGroupLevel::where('grade', '>', $info['group_level'])
  83. ->min('grade');
  84. if ($minGrade === null){
  85. $quota = SystemGroupLevel::where('grade', $minGrade)->value('quota');
  86. if ($quota <= $info['team_achievement']){
  87. User::where('uid', $info['uid'])->update(['group_level' => $minGrade]);
  88. $level_id = SystemGroupLevel::where('grade', $minGrade)->value('id');
  89. $name = SystemGroupLevel::where('grade', $minGrade)->value('name');
  90. UserGroupLevel::create([
  91. 'is_forever' =>1,
  92. 'status' => 1,
  93. 'is_del' => 0,
  94. 'grade' => $minGrade,
  95. 'uid' => $info['uid'],
  96. 'add_time' => time(),
  97. 'level_id' => $level_id,
  98. 'discount' => 100,
  99. 'valid_time' => 0,
  100. 'mark' => '尊敬的用户【' . $info['nickname'] . '】在' . date('Y-m-d H:i:s', time()) . '成为' . $name . '会员',
  101. ]);
  102. }
  103. }
  104. $info['level_name'] = SystemUserLevel::where('id', $info['level'])->value('name');
  105. $info['group_level_name'] = SystemGroupLevel::where('id', $info['group_level'])->value('name');
  106. // 等级任务
  107. SystemUserLevel::getLevelList($info['uid']);
  108. return app('json')->success($info);
  109. }
  110. /**
  111. * 递归获取所有团队成员
  112. * @param int $uid 用户ID
  113. * @return array
  114. */
  115. protected function getAllTeamMembers($uid)
  116. {
  117. static $teamUids = [];
  118. // 获取直接下级
  119. $directSubordinates = User::where('spread_uid', $uid)->column('uid');
  120. if (!empty($directSubordinates)) {
  121. $teamUids = array_merge($teamUids, $directSubordinates);
  122. // 递归获取下级的下级
  123. foreach ($directSubordinates as $subordinateUid) {
  124. $this->getAllTeamMembers($subordinateUid);
  125. }
  126. }
  127. return $teamUids;
  128. }
  129. /**
  130. * 用户资金统计
  131. * @param Request $request
  132. * @return mixed
  133. * @throws \think\Exception
  134. * @throws DataNotFoundException
  135. * @throws ModelNotFoundException
  136. * @throws \think\exception\DbException
  137. */
  138. public function balance(Request $request)
  139. {
  140. $uid = $request->uid();
  141. $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money'];//当前总资金
  142. $user['recharge'] = UserBill::getRecharge($uid);//累计充值
  143. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid);//累计消费
  144. return app('json')->successful($user);
  145. }
  146. /**
  147. * 个人中心
  148. * @param Request $request
  149. * @return mixed
  150. */
  151. public function user(Request $request)
  152. {
  153. $user = $request->user();
  154. $user = $user->toArray();
  155. $user['couponCount'] = StoreCouponUser::getUserValidCouponCount($user['uid']);
  156. $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
  157. $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']);
  158. $user['notice'] = UserNotice::getNotice($user['uid']);
  159. $user['brokerage'] = UserBill::getBrokerage($user['uid']);//获取总佣金
  160. $user['recharge'] = UserBill::getRecharge($user['uid']);//累计充值
  161. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']);//累计消费
  162. $user['extractTotalPrice'] = UserExtract::userExtractTotalPrice($user['uid']);//累计提现
  163. $user['extractPrice'] = $user['brokerage_price'];//可提现
  164. $user['statu'] = (int)sys_config('store_brokerage_statu');
  165. $broken_time = intval(sys_config('extract_time'));
  166. $search_time = time() - 86400 * $broken_time;
  167. if (!$user['is_promoter'] && $user['statu'] == 2) {
  168. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price');
  169. $status = is_brokerage_statu($price);
  170. if ($status) {
  171. User::where('uid', $user['uid'])->update(['is_promoter' => 1]);
  172. $user['is_promoter'] = 1;
  173. } else {
  174. $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
  175. $user['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
  176. }
  177. }
  178. //可提现佣金
  179. //返佣 +
  180. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'brokerage_price'])
  181. ->where('add_time', '>', $search_time)
  182. ->where('pm', 1)
  183. ->sum('number');
  184. //退款退的佣金 -
  185. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'brokerage_price'])
  186. ->where('add_time', '>', $search_time)
  187. ->where('pm', 0)
  188. ->sum('number');
  189. $user['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  190. if ($user['broken_commission'] < 0)
  191. $user['broken_commission'] = 0;
  192. $user['commissionCount'] = bcsub($user['brokerage_price'], $user['broken_commission'], 2);
  193. if ($user['commissionCount'] < 0)
  194. $user['commissionCount'] = 0;
  195. if (!sys_config('vip_open'))
  196. $user['vip'] = false;
  197. else {
  198. $vipId = UserLevel::getUserLevel($user['uid']);
  199. $user['vip'] = $vipId !== false ? true : false;
  200. if ($user['vip']) {
  201. $user['vip_id'] = $vipId;
  202. $user['vip_icon'] = UserLevel::getUserLevelInfo($vipId, 'icon');
  203. $user['vip_name'] = UserLevel::getUserLevelInfo($vipId, 'name');
  204. }
  205. }
  206. $user['yesterDay'] = UserBill::yesterdayCommissionSum($user['uid']);
  207. $user['recharge_switch'] = (int)sys_config('recharge_switch');//充值开关
  208. $user['adminid'] = (boolean)\app\models\store\StoreService::orderServiceStatus($user['uid']);
  209. if ($user['phone'] && $user['user_type'] != 'h5') {
  210. $user['switchUserInfo'][] = $request->user();
  211. if ($h5UserInfo = User::where('account', $user['phone'])->where('user_type', 'h5')->find()) {
  212. $user['switchUserInfo'][] = $h5UserInfo;
  213. }
  214. } else if ($user['phone'] && $user['user_type'] == 'h5') {
  215. if ($wechatUserInfo = User::where('phone', $user['phone'])->where('user_type', '<>', 'h5')->find()) {
  216. $user['switchUserInfo'][] = $wechatUserInfo;
  217. }
  218. $user['switchUserInfo'][] = $request->user();
  219. } else if (!$user['phone']) {
  220. $user['switchUserInfo'][] = $request->user();
  221. }
  222. return app('json')->successful($user);
  223. }
  224. /**
  225. * 地址 获取单个
  226. * @param Request $request
  227. * @param $id
  228. * @return mixed
  229. * @throws DataNotFoundException
  230. * @throws ModelNotFoundException
  231. * @throws \think\exception\DbException
  232. */
  233. public function address(Request $request, $id)
  234. {
  235. $addressInfo = [];
  236. if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
  237. $addressInfo = UserAddress::find($id)->toArray();
  238. }
  239. return app('json')->successful($addressInfo);
  240. }
  241. /**
  242. * 地址列表
  243. * @param Request $request
  244. * @param $page
  245. * @param $limit
  246. * @return mixed
  247. */
  248. public function address_list(Request $request)
  249. {
  250. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true);
  251. $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default');
  252. return app('json')->successful($list);
  253. }
  254. /**
  255. * 设置默认地址
  256. *
  257. * @param Request $request
  258. * @return mixed
  259. */
  260. public function address_default_set(Request $request)
  261. {
  262. list($id) = UtilService::getMore([['id', 0]], $request, true);
  263. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  264. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  265. return app('json')->fail('地址不存在!');
  266. $res = UserAddress::setDefaultAddress($id, $request->uid());
  267. if (!$res)
  268. return app('json')->fail('地址不存在!');
  269. else
  270. return app('json')->successful();
  271. }
  272. /**
  273. * 获取默认地址
  274. * @param Request $request
  275. * @return mixed
  276. */
  277. public function address_default(Request $request)
  278. {
  279. $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default');
  280. if ($defaultAddress) {
  281. $defaultAddress = $defaultAddress->toArray();
  282. return app('json')->successful('ok', $defaultAddress);
  283. }
  284. return app('json')->successful('empty', []);
  285. }
  286. /**
  287. * 修改 添加地址
  288. * @param Request $request
  289. * @return mixed
  290. */
  291. public function address_edit(Request $request)
  292. {
  293. $addressInfo = UtilService::postMore([
  294. ['address', []],
  295. ['is_default', false],
  296. ['real_name', ''],
  297. ['post_code', ''],
  298. ['phone', ''],
  299. ['detail', ''],
  300. ['id', 0],
  301. ['type', 0]
  302. ], $request);
  303. if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!');
  304. if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!');
  305. if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!');
  306. if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) {
  307. return app('json')->fail('收货地址格式错误!请重新选择!');
  308. } else if ($addressInfo['type'] == 1) {
  309. $city = $addressInfo['address']['city'];
  310. $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id');
  311. if ($cityId) {
  312. $addressInfo['address']['city_id'] = $cityId;
  313. } else {
  314. if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) {
  315. return app('json')->fail('收货地址格式错误!修改后请重新导入!');
  316. }
  317. $addressInfo['address']['city_id'] = $cityId;
  318. }
  319. }
  320. $addressInfo['province'] = $addressInfo['address']['province'];
  321. $addressInfo['city'] = $addressInfo['address']['city'];
  322. $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
  323. $addressInfo['district'] = $addressInfo['address']['district'];
  324. $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
  325. $addressInfo['uid'] = $request->uid();
  326. unset($addressInfo['address'], $addressInfo['type']);
  327. try {
  328. validate(AddressValidate::class)->check($addressInfo);
  329. } catch (ValidateException $e) {
  330. return app('json')->fail($e->getError());
  331. }
  332. if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
  333. $id = $addressInfo['id'];
  334. unset($addressInfo['id']);
  335. if (UserAddress::edit($addressInfo, $id, 'id')) {
  336. if ($addressInfo['is_default'])
  337. UserAddress::setDefaultAddress($id, $request->uid());
  338. return app('json')->successful();
  339. } else
  340. return app('json')->fail('编辑收货地址失败!');
  341. } else {
  342. $addressInfo['add_time'] = time();
  343. if ($address = UserAddress::create($addressInfo)) {
  344. if ($addressInfo['is_default']) {
  345. UserAddress::setDefaultAddress($address->id, $request->uid());
  346. }
  347. return app('json')->successful(['id' => $address->id]);
  348. } else {
  349. return app('json')->fail('添加收货地址失败!');
  350. }
  351. }
  352. }
  353. /**
  354. * 删除地址
  355. *
  356. * @param Request $request
  357. * @return mixed
  358. */
  359. public function address_del(Request $request)
  360. {
  361. list($id) = UtilService::postMore([['id', 0]], $request, true);
  362. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  363. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  364. return app('json')->fail('地址不存在!');
  365. if (UserAddress::edit(['is_del' => '1'], $id, 'id'))
  366. return app('json')->successful();
  367. else
  368. return app('json')->fail('删除地址失败!');
  369. }
  370. /**
  371. * 获取收藏产品
  372. *
  373. * @param Request $request
  374. * @return mixed
  375. */
  376. public function collect_user(Request $request)
  377. {
  378. list($page, $limit) = UtilService::getMore([
  379. ['page', 0],
  380. ['limit', 0]
  381. ], $request, true);
  382. if (!(int)$limit) return app('json')->successful([]);
  383. $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit);
  384. return app('json')->successful($productRelationList);
  385. }
  386. /**
  387. * 添加收藏
  388. * @param Request $request
  389. * @param $id
  390. * @param $category
  391. * @return mixed
  392. */
  393. public function collect_add(Request $request)
  394. {
  395. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  396. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  397. $res = StoreProductRelation::productRelation($id, $request->uid(), 'collect', $category);
  398. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  399. else return app('json')->successful();
  400. }
  401. /**
  402. * 取消收藏
  403. *
  404. * @param Request $request
  405. * @return mixed
  406. */
  407. public function collect_del(Request $request)
  408. {
  409. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  410. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  411. $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category);
  412. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  413. else return app('json')->successful();
  414. }
  415. /**
  416. * 批量收藏
  417. * @param Request $request
  418. * @return mixed
  419. */
  420. public function collect_all(Request $request)
  421. {
  422. $collectInfo = UtilService::postMore([
  423. ['id', []],
  424. ['category', 'product'],
  425. ], $request);
  426. if (!count($collectInfo['id'])) return app('json')->fail('参数错误');
  427. $productIdS = $collectInfo['id'];
  428. $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['category']);
  429. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  430. else return app('json')->successful('收藏成功');
  431. }
  432. /**
  433. * 添加点赞
  434. *
  435. * @param Request $request
  436. * @return mixed
  437. */
  438. // public function like_add(Request $request)
  439. // {
  440. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  441. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  442. // $res = StoreProductRelation::productRelation($id,$request->uid(),'like',$category);
  443. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  444. // else return app('json')->successful();
  445. // }
  446. /**
  447. * 取消点赞
  448. *
  449. * @param Request $request
  450. * @return mixed
  451. */
  452. // public function like_del(Request $request)
  453. // {
  454. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  455. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  456. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  457. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  458. // else return app('json')->successful();
  459. // }
  460. /**
  461. * 签到 配置
  462. * @return mixed
  463. * @throws DataNotFoundException
  464. * @throws ModelNotFoundException
  465. * @throws \think\exception\DbException
  466. */
  467. public function sign_config()
  468. {
  469. $signConfig = sys_data('sign_day_num') ?? [];
  470. return app('json')->successful($signConfig);
  471. }
  472. /**
  473. * 签到 列表
  474. * @param Request $request
  475. * @param $page
  476. * @param $limit
  477. * @return mixed
  478. */
  479. public function sign_list(Request $request)
  480. {
  481. list($page, $limit) = UtilService::getMore([
  482. ['page', 0],
  483. ['limit', 0]
  484. ], $request, true);
  485. if (!$limit) return app('json')->successful([]);
  486. $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit);
  487. if ($signList) $signList = $signList->toArray();
  488. return app('json')->successful($signList);
  489. }
  490. /**
  491. * 签到
  492. * @param Request $request
  493. * @return mixed
  494. */
  495. public function sign_integral(Request $request)
  496. {
  497. $signed = UserSign::getIsSign($request->uid());
  498. if ($signed) return app('json')->fail('已签到');
  499. if (false !== ($integral = UserSign::sign($request->uid())))
  500. return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]);
  501. return app('json')->fail(UserSign::getErrorInfo('签到失败'));
  502. }
  503. /**
  504. * 签到用户信息
  505. * @param Request $request
  506. * @return mixed
  507. */
  508. public function sign_user(Request $request)
  509. {
  510. list($sign, $integral, $all) = UtilService::postMore([
  511. ['sign', 0],
  512. ['integral', 0],
  513. ['all', 0],
  514. ], $request, true);
  515. $user = $request->user();
  516. //是否统计签到
  517. if ($sign || $all) {
  518. $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']);
  519. $user['is_day_sgin'] = UserSign::getIsSign($user['uid']);
  520. $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday');
  521. if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) {
  522. $user['sign_num'] = 0;
  523. }
  524. }
  525. //是否统计积分使用情况
  526. if ($integral || $all) {
  527. $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain');
  528. $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
  529. $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
  530. }
  531. unset($user['pwd']);
  532. if (!$user['is_promoter']) {
  533. $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == 2 ? true : false;
  534. }
  535. return app('json')->successful($user->hidden(['account', 'real_name', 'birthday', 'card_id', 'mark', 'partner_id', 'group_id', 'add_time', 'add_ip', 'phone', 'last_time', 'last_ip', 'spread_uid', 'spread_time', 'user_type', 'status', 'level', 'clean_time', 'addres'])->toArray());
  536. }
  537. /**
  538. * 签到列表(年月)
  539. *
  540. * @param Request $request
  541. * @return mixed
  542. */
  543. public function sign_month(Request $request)
  544. {
  545. list($page, $limit) = UtilService::getMore([
  546. ['page', 0],
  547. ['limit', 0]
  548. ], $request, true);
  549. if (!$limit) return app('json')->successful([]);
  550. $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
  551. return app('json')->successful($userSignList);
  552. }
  553. /**
  554. * 获取活动状态
  555. * @return mixed
  556. */
  557. public function activity()
  558. {
  559. $data['is_bargin'] = StoreBargain::validBargain() ? true : false;
  560. $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false;
  561. $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false;
  562. return app('json')->successful($data);
  563. }
  564. /**
  565. * 用户修改信息
  566. * @param Request $request
  567. * @return mixed
  568. */
  569. public function edit(Request $request)
  570. {
  571. list($avatar, $nickname) = UtilService::postMore([
  572. ['avatar', ''],
  573. ['nickname', ''],
  574. ], $request, true);
  575. if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
  576. return app('json')->fail('修改失败');
  577. }
  578. /**
  579. * 推广人排行
  580. * @param Request $request
  581. * @return mixed
  582. * @throws DataNotFoundException
  583. * @throws ModelNotFoundException
  584. * @throws \think\exception\DbException
  585. */
  586. public function rank(Request $request)
  587. {
  588. $data = UtilService::getMore([
  589. ['page', ''],
  590. ['limit', ''],
  591. ['type', '']
  592. ], $request);
  593. $users = User::getRankList($data);
  594. return app('json')->success($users);
  595. }
  596. /**
  597. * 佣金排行
  598. * @param Request $request
  599. * @return mixed
  600. */
  601. public function brokerage_rank(Request $request)
  602. {
  603. $data = UtilService::getMore([
  604. ['page', ''],
  605. ['limit'],
  606. ['type']
  607. ], $request);
  608. return app('json')->success([
  609. 'rank' => User::brokerageRank($data),
  610. 'position' => User::currentUserRank($data['type'], $request->user()['brokerage_price'])
  611. ]);
  612. }
  613. /**
  614. * 添加访问记录
  615. * @param Request $request
  616. * @return mixed
  617. */
  618. public function set_visit(Request $request)
  619. {
  620. $data = UtilService::postMore([
  621. ['url', ''],
  622. ['stay_time', 0]
  623. ], $request);
  624. if ($data['url'] == '') return app('json')->fail('未获取页面路径');
  625. $data['uid'] = $request->uid();
  626. $data['ip'] = $request->ip();
  627. $data['add_time'] = time();
  628. $res = UserVisit::insert($data);
  629. if ($res) {
  630. return app('json')->success('添加访问记录成功');
  631. } else {
  632. return app('json')->fail('添加访问记录失败');
  633. }
  634. }
  635. /**
  636. * 静默绑定推广人
  637. * @param Request $request
  638. * @return mixed
  639. * @throws DataNotFoundException
  640. * @throws DbException
  641. * @throws ModelNotFoundException
  642. */
  643. public function spread(Request $request)
  644. {
  645. $puid = $request->post('puid/d', 0);
  646. return app('json')->success(User::setSpread($puid, $request->uid()));
  647. }
  648. }