UserController.php 27 KB

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