UserController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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\user\UserCoin;
  6. use think\exception\ValidateException;
  7. use app\Request;
  8. use app\models\user\UserLevel;
  9. use app\models\user\UserSign;
  10. use app\models\store\StoreBargain;
  11. use app\models\store\StoreCombination;
  12. use app\models\store\StoreOrder;
  13. use app\models\store\StoreProductRelation;
  14. use app\models\store\StoreSeckill;
  15. use app\models\user\User;
  16. use app\models\user\UserAddress;
  17. use app\models\user\UserBill;
  18. use app\models\user\UserExtract;
  19. use app\models\user\UserNotice;
  20. use crmeb\services\UtilService;
  21. /**
  22. * 用户类
  23. * Class UserController
  24. * @package app\api\controller\store
  25. */
  26. class UserController
  27. {
  28. /**
  29. * @api {get} /userinfo 获取用户信息
  30. * @apiName GetUserinfo
  31. * @apiGroup User
  32. *
  33. */
  34. public function userinfo(Request $request)
  35. {
  36. $info = $request->user()->toArray();
  37. $broken_time = intval(sys_config('extract_time'));
  38. $search_time = time() - 86400 * $broken_time;
  39. //返佣 +
  40. $brokerage_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  41. ->where('add_time', '>', $search_time)
  42. ->where('pm', 1)
  43. ->sum('number');
  44. //退款退的佣金 -
  45. $refund_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  46. ->where('add_time', '>', $search_time)
  47. ->where('pm', 0)
  48. ->sum('number');
  49. $info['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  50. if ($info['broken_commission'] < 0)
  51. $info['broken_commission'] = 0;
  52. $info['commissionCount'] = bcsub($info['brokerage_price'], $info['broken_commission'], 2);
  53. if ($info['commissionCount'] < 0)
  54. $info['commissionCount'] = 0;
  55. return app('json')->success($info);
  56. }
  57. /**
  58. * @api {get} /user/balance 用户资金统计
  59. * @apiName GetUserBalance
  60. * @apiGroup User
  61. *
  62. * @apiSuccessExample Succeed
  63. * {
  64. *
  65. * }
  66. */
  67. public function balance(Request $request)
  68. {
  69. $uid = $request->uid();
  70. $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money']; //当前总资金
  71. $user['recharge'] = UserBill::getRecharge($uid); //累计充值
  72. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid); //累计消费
  73. $coins = UserCoin::alias('uc')
  74. ->join('dict_coin dc', 'uc.symbol=dc.symbol')->field('uc.symbol, dc.icon, uc.addr, uc.balance as total')
  75. ->where('uid', $uid)->select();
  76. $user['coins'] = $coins ? $coins->toArray() : [];
  77. return app('json')->successful($user);
  78. }
  79. /**
  80. * @api {get} /user 个人中心
  81. * @apiName GetUser
  82. * @apiGroup User
  83. *
  84. * @apiParam none None
  85. *
  86. * @apiSuccessExample Succeed
  87. * {
  88. * }
  89. */
  90. public function user(Request $request)
  91. {
  92. $user = $request->user();
  93. $user = $user->toArray();
  94. $user['couponCount'] = 0; //StoreCouponUser::getUserValidCouponCount($user['uid']);
  95. $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
  96. $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']);
  97. $user['notice'] = UserNotice::getNotice($user['uid']);
  98. // $user['brokerage'] = UserBill::getBrokerage($user['uid']);//获取总佣金
  99. $user['recharge'] = UserBill::getRecharge($user['uid']); //累计充值
  100. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']); //累计消费
  101. $user['extractTotalPrice'] = UserExtract::userExtractTotalPrice($user['uid']); //累计提现
  102. $user['extractPrice'] = $user['brokerage_price']; //可提现
  103. $user['statu'] = (int)sys_config('store_brokerage_statu');
  104. $broken_time = intval(sys_config('extract_time'));
  105. $search_time = time() - 86400 * $broken_time;
  106. if (!$user['is_promoter'] && $user['statu'] == DISTRIBUTE_EVERYONE) { // 人人分销
  107. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price');
  108. $status = is_brokerage_statu($price);
  109. if ($status) {
  110. User::where('uid', $user['uid'])->update(['is_promoter' => 1]);
  111. $user['is_promoter'] = 1;
  112. event('UserBecomedPromoter', [$user]);
  113. } else {
  114. $storeBrokeragePrice = sys_config('store_brokerage_price', 0); // 分銷滿足金額
  115. $user['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
  116. }
  117. }
  118. //可提现佣金
  119. //返佣 +
  120. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  121. ->where('add_time', '>', $search_time)
  122. ->where('pm', 1)
  123. ->sum('number');
  124. //退款退的佣金 -
  125. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  126. ->where('add_time', '>', $search_time)
  127. ->where('pm', 0)
  128. ->sum('number');
  129. $user['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  130. if ($user['broken_commission'] < 0)
  131. $user['broken_commission'] = 0;
  132. $user['commissionCount'] = bcsub($user['brokerage_price'], $user['broken_commission'], 2);
  133. if ($user['commissionCount'] < 0)
  134. $user['commissionCount'] = 0;
  135. if (!sys_config('vip_open'))
  136. $user['vip'] = false;
  137. else {
  138. $vipId = UserLevel::getUserLevel($user['uid']);
  139. $user['vip'] = $vipId !== false ? true : false;
  140. if ($user['vip']) {
  141. $user['vip_id'] = $vipId;
  142. $vipInfo = UserLevel::getUserLevelInfo($vipId);
  143. if ($vipInfo) {
  144. $user['vip_icon'] = $vipInfo['icon'];
  145. $user['vip_name'] = $vipInfo['name'];
  146. }
  147. }
  148. }
  149. $user['yesterDay'] = UserBill::yesterdayCommissionSum($user['uid']);
  150. $user['recharge_switch'] = (int)sys_config('recharge_switch'); //充值开关
  151. $user['adminid'] = (bool)\app\models\store\StoreService::orderServiceStatus($user['uid']);
  152. if ($user['phone'] && $user['user_type'] != 'h5') {
  153. $user['switchUserInfo'][] = $request->user();
  154. if ($h5UserInfo = User::where('account', $user['phone'])->where('user_type', 'h5')->find()) {
  155. $user['switchUserInfo'][] = $h5UserInfo;
  156. }
  157. } else if ($user['phone'] && $user['user_type'] == 'h5') {
  158. if ($wechatUserInfo = User::where('phone', $user['phone'])->where('user_type', '<>', 'h5')->find()) {
  159. $user['switchUserInfo'][] = $wechatUserInfo;
  160. }
  161. $user['switchUserInfo'][] = $request->user();
  162. } else if (!$user['phone']) {
  163. $user['switchUserInfo'][] = $request->user();
  164. }
  165. $coins = UserCoin::alias('uc')
  166. ->join('dict_coin dc', 'uc.symbol=dc.symbol')->field('uc.symbol, dc.icon, uc.addr, uc.balance as total')
  167. ->where('uid', $user['uid'])->select();
  168. $user['coins'] = $coins ? $coins->toArray() : [];
  169. return app('json')->successful($user);
  170. }
  171. /**
  172. * @api {get} /address/detail/:id 地址获取单个
  173. * @apiName GetAddress
  174. * @apiGroup User.Address
  175. *
  176. * @apiParam {int} id address_id
  177. *
  178. * @apiSuccessExample Succeed
  179. * {
  180. * }
  181. */
  182. public function address(Request $request, $id)
  183. {
  184. $addressInfo = [];
  185. if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
  186. $addressInfo = UserAddress::find($id)->toArray();
  187. }
  188. return app('json')->successful($addressInfo);
  189. }
  190. /**
  191. * @api {get} /address/list 地址列表
  192. * @apiName GetAddressList
  193. * @apiGroup User.Address
  194. *
  195. * @apiQuery {int} page
  196. * @apiQuery {int} limit
  197. *
  198. * @apiSuccessExample Succeed
  199. * {
  200. *
  201. * }
  202. */
  203. public function address_list(Request $request)
  204. {
  205. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true);
  206. $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default');
  207. return app('json')->successful($list);
  208. }
  209. /**
  210. * @api {post} /address/default/set 设置默认地址
  211. * @apiName PostAddressDefaultSet
  212. * @apiGroup User.Address
  213. *
  214. * @apiQuery {int} id address_id
  215. *
  216. * @apiSuccessExample Succeed
  217. * {
  218. * }
  219. * @apiErrorExample Failed
  220. * {
  221. *
  222. * }
  223. */
  224. public function address_default_set(Request $request)
  225. {
  226. list($id) = UtilService::getMore([['id', 0]], $request, true);
  227. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  228. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  229. return app('json')->fail('地址不存在!');
  230. $res = UserAddress::setDefaultAddress($id, $request->uid());
  231. if (!$res)
  232. return app('json')->fail('地址不存在!');
  233. else
  234. return app('json')->successful();
  235. }
  236. /**
  237. * @api {get} /address/default 获取默认地址
  238. * @apiName GetAddressDefault
  239. * @apiGroup User.Address
  240. *
  241. * @apiSuccessExample Succeed
  242. * {
  243. * }
  244. * @apiErrorExample Failed
  245. * {
  246. * }
  247. */
  248. public function address_default(Request $request)
  249. {
  250. $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default');
  251. if ($defaultAddress) {
  252. $defaultAddress = $defaultAddress->toArray();
  253. return app('json')->successful('ok', $defaultAddress);
  254. }
  255. return app('json')->successful('empty', []);
  256. }
  257. /**
  258. * @api {post} /address/edit 修改添加地址
  259. * @apiName PostAddressEdit
  260. * @apiGroup User.Address
  261. *
  262. * @apiBody none None
  263. *
  264. * @apiSuccessExample Succeed
  265. * {
  266. * }
  267. * @apiErrorExample Failed
  268. * {
  269. * }
  270. */
  271. public function address_edit(Request $request)
  272. {
  273. $addressInfo = UtilService::postMore([
  274. ['address', []],
  275. ['is_default', false],
  276. ['real_name', ''],
  277. ['post_code', ''],
  278. ['phone', ''],
  279. ['detail', ''],
  280. ['id', 0],
  281. ['type', 0]
  282. ], $request);
  283. if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!');
  284. if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!');
  285. if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!');
  286. if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) {
  287. return app('json')->fail('收货地址格式错误!请重新选择!');
  288. } else if ($addressInfo['type'] == 1 && !$addressInfo['id']) {
  289. $city = $addressInfo['address']['city'];
  290. $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id');
  291. if ($cityId) {
  292. $addressInfo['address']['city_id'] = $cityId;
  293. } else {
  294. if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) {
  295. return app('json')->fail('收货地址格式错误!修改后请重新导入!');
  296. }
  297. }
  298. }
  299. $addressInfo['province'] = $addressInfo['address']['province'];
  300. $addressInfo['city'] = $addressInfo['address']['city'];
  301. $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
  302. $addressInfo['district'] = $addressInfo['address']['district'];
  303. $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
  304. $addressInfo['uid'] = $request->uid();
  305. unset($addressInfo['address'], $addressInfo['type']);
  306. try {
  307. validate(AddressValidate::class)->check($addressInfo);
  308. } catch (ValidateException $e) {
  309. return app('json')->fail($e->getError());
  310. }
  311. //编辑
  312. if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
  313. $id = $addressInfo['id'];
  314. unset($addressInfo['id']);
  315. if ($addressInfo['city_id'] == 0)
  316. unset($addressInfo['city_id']);
  317. if (UserAddress::edit($addressInfo, $id, 'id')) {
  318. if ($addressInfo['is_default'])
  319. UserAddress::setDefaultAddress($id, $request->uid());
  320. return app('json')->successful();
  321. } else
  322. return app('json')->fail('编辑收货地址失败!');
  323. } else {
  324. $addressInfo['add_time'] = time();
  325. if ($address = UserAddress::create($addressInfo)) {
  326. if ($addressInfo['is_default']) {
  327. UserAddress::setDefaultAddress($address->id, $request->uid());
  328. }
  329. return app('json')->successful(['id' => $address->id]);
  330. } else {
  331. return app('json')->fail('添加收货地址失败!');
  332. }
  333. }
  334. }
  335. /**
  336. * @api {post} /address/del 删除地址
  337. * @apiName PostAddressDel
  338. * @apiGroup User.Address
  339. *
  340. * @apiSuccessExample Succeed
  341. * {
  342. * }
  343. * @apiErrorExample Failed
  344. * {
  345. * }
  346. */
  347. public function address_del(Request $request)
  348. {
  349. list($id) = UtilService::postMore([['id', 0]], $request, true);
  350. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  351. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  352. return app('json')->fail('地址不存在!');
  353. if (UserAddress::edit(['is_del' => '1'], $id, 'id'))
  354. return app('json')->successful();
  355. else
  356. return app('json')->fail('删除地址失败!');
  357. }
  358. /**
  359. * @api {get} /collect/user 获取收藏产品
  360. * @apiName GetCollectUser
  361. * @apiGroup User.Collect
  362. *
  363. * @apiSuccessExample Succeed
  364. * {
  365. * }
  366. * @apiErrorExample Failed
  367. * {
  368. * }
  369. */
  370. public function collect_user(Request $request)
  371. {
  372. list($page, $limit) = UtilService::getMore([
  373. ['page', 0],
  374. ['limit', 0]
  375. ], $request, true);
  376. if (!(int)$limit) return app('json')->successful([]);
  377. $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit);
  378. return app('json')->successful($productRelationList);
  379. }
  380. /**
  381. * @api {post} /collect/add 添加收藏
  382. * @apiName PostCollectAdd
  383. * @apiGroup User.Collect
  384. *
  385. * @apiSuccessExample Succeed
  386. * {
  387. * }
  388. * @apiErrorExample Failed
  389. * {
  390. * }
  391. */
  392. public function collect_add(Request $request)
  393. {
  394. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  395. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  396. $res = StoreProductRelation::productRelation($id, $request->uid(), 'collect', $category);
  397. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  398. else return app('json')->successful();
  399. }
  400. /**
  401. * @api {post} /collect/del 取消收藏
  402. * @apiName PostCollectDel
  403. * @apiGroup User.Collect
  404. *
  405. * @apiSuccessExample Succeed
  406. * {
  407. * }
  408. * @apiErrorExample Failed
  409. * {
  410. * }
  411. */
  412. public function collect_del(Request $request)
  413. {
  414. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  415. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  416. $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category);
  417. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  418. else return app('json')->successful();
  419. }
  420. /**
  421. * @api {post} /collect/all 批量收藏
  422. * @apiName PostCollectAll
  423. * @apiGroup User.Collect
  424. *
  425. * @apiSuccessExample Succeed
  426. * {
  427. * }
  428. * @apiErrorExample Failed
  429. * {
  430. * }
  431. */
  432. public function collect_all(Request $request)
  433. {
  434. $collectInfo = UtilService::postMore([
  435. ['id', []],
  436. ['category', 'product'],
  437. ], $request);
  438. if (!count($collectInfo['id'])) return app('json')->fail('参数错误');
  439. $productIdS = $collectInfo['id'];
  440. $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['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_add(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::productRelation($id,$request->uid(),'like',$category);
  455. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  456. // else return app('json')->successful();
  457. // }
  458. /**
  459. * 取消点赞
  460. *
  461. * @param Request $request
  462. * @return mixed
  463. */
  464. // public function like_del(Request $request)
  465. // {
  466. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  467. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  468. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  469. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  470. // else return app('json')->successful();
  471. // }
  472. /**
  473. * @api {get} /sign/config 签到配置
  474. * @apiName GetSignConfig
  475. * @apiGroup User.Sign
  476. *
  477. * @apiSuccessExample Succeed
  478. * {
  479. *
  480. * }
  481. */
  482. public function sign_config()
  483. {
  484. $signConfig = sys_data('sign_day_num') ?? [];
  485. return app('json')->successful($signConfig);
  486. }
  487. /**
  488. * @api {get} /sign/list 签到列表
  489. * @apiName GetSignList
  490. * @apiGroup User.Sign
  491. *
  492. * @apiSuccessExample Succeed
  493. * {
  494. *
  495. * }
  496. */
  497. public function sign_list(Request $request)
  498. {
  499. list($page, $limit) = UtilService::getMore([
  500. ['page', 0],
  501. ['limit', 0]
  502. ], $request, true);
  503. if (!$limit) return app('json')->successful([]);
  504. $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit);
  505. if ($signList) $signList = $signList->toArray();
  506. return app('json')->successful($signList);
  507. }
  508. /**
  509. * @api {post} /sign/integral 签到
  510. * @apiName PostSignIntegral
  511. * @apiGroup User.Sign
  512. *
  513. */
  514. public function sign_integral(Request $request)
  515. {
  516. $signed = UserSign::getIsSign($request->uid());
  517. if ($signed) return app('json')->fail('已签到');
  518. if (false !== ($integral = UserSign::sign($request->uid())))
  519. return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]);
  520. return app('json')->fail(UserSign::getErrorInfo('签到失败'));
  521. }
  522. /**
  523. * @api {post} /sign/user 签到用户信息
  524. * @apiName PostSignUser
  525. * @apiGroup User.Sign
  526. *
  527. */
  528. public function sign_user(Request $request)
  529. {
  530. list($sign, $integral, $all) = UtilService::postMore([
  531. ['sign', 0],
  532. ['integral', 0],
  533. ['all', 0],
  534. ], $request, true);
  535. $user = $request->user();
  536. //是否统计签到
  537. if ($sign || $all) {
  538. $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']);
  539. $user['is_day_sgin'] = UserSign::getIsSign($user['uid']);
  540. $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday');
  541. if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) {
  542. $user['sign_num'] = 0;
  543. }
  544. }
  545. //是否统计积分使用情况
  546. if ($integral || $all) {
  547. $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain');
  548. $refund_integral = (int)UserBill::where(['uid' => $user['uid'], 'category' => 'integral', 'status' => 1, 'pm' => 0])->where('type', 'in', 'sign,system_add,gain')->sum('number');
  549. if ($user['sum_integral'] > $refund_integral)
  550. $user['sum_integral'] = $user['sum_integral'] - $refund_integral;
  551. else
  552. $user['sum_integral'] = 0;
  553. $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
  554. $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
  555. }
  556. unset($user['pwd']);
  557. if (!$user['is_promoter']) {
  558. $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == DISTRIBUTE_EVERYONE ? true : false;
  559. }
  560. 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());
  561. }
  562. /**
  563. * @api {get} /sign/month 签到列表(年月)
  564. * @apiName GetSignMonth
  565. * @apiGroup User.Sign
  566. *
  567. */
  568. public function sign_month(Request $request)
  569. {
  570. list($page, $limit) = UtilService::getMore([
  571. ['page', 0],
  572. ['limit', 0]
  573. ], $request, true);
  574. if (!$limit) return app('json')->successful([]);
  575. $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
  576. return app('json')->successful($userSignList);
  577. }
  578. /**
  579. * @api {get} /user/activity 获取活动状态
  580. * @apiName GetUserActivity
  581. * @apiGroup User
  582. *
  583. */
  584. public function activity()
  585. {
  586. $data['is_bargin'] = StoreBargain::validBargain() ? true : false;
  587. $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false;
  588. $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false;
  589. return app('json')->successful($data);
  590. }
  591. /**
  592. * @api {post} /user/edit 用户修改信息
  593. * @apiName PostUserEdit
  594. * @apiGroup User
  595. *
  596. * @apiBody {string} avatar 头像
  597. * @apiBody {string} nickname 昵称
  598. *
  599. * @apiSuccessExample Succeed
  600. * {
  601. *
  602. * }
  603. */
  604. public function edit(Request $request)
  605. {
  606. list($avatar, $nickname) = UtilService::postMore([
  607. ['avatar', ''],
  608. ['nickname', ''],
  609. ], $request, true);
  610. if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
  611. return app('json')->fail('修改失败');
  612. }
  613. /**
  614. * @api {get} /rank 推广人排行
  615. * @apiName GetRank
  616. * @apiGroup User
  617. *
  618. *
  619. */
  620. public function rank(Request $request)
  621. {
  622. $data = UtilService::getMore([
  623. ['page', ''],
  624. ['limit', ''],
  625. ['type', '']
  626. ], $request);
  627. $users = User::getRankList($data);
  628. return app('json')->success($users);
  629. }
  630. /**
  631. * @api {get} /brokerage_rank 佣金排行
  632. * @apiName GetBrokerage_rank
  633. * @apiGroup User
  634. *
  635. * @apiBody {string} avatar 头像
  636. * @apiBody {string} nickname 昵称
  637. *
  638. * @apiSuccessExample Succeed
  639. * {
  640. *
  641. * }
  642. */
  643. public function brokerage_rank(Request $request)
  644. {
  645. $data = UtilService::getMore([
  646. ['page', ''],
  647. ['limit'],
  648. ['type']
  649. ], $request);
  650. $users = User::brokerageRank($data);
  651. foreach ($users as $key => $item) {
  652. if ($item['brokerage_price'] == '0.00' || $item['brokerage_price'] == 0 || !$item['brokerage_price']) {
  653. unset($users[$key]);
  654. }
  655. }
  656. $position_tmp = User::brokerageRank(['type' => $data['type'], 'page' => 0, 'limit' => 99999]);
  657. $position_tmp_one = array_column($position_tmp, 'uid');
  658. $position_tmp_two = array_column($position_tmp, 'brokerage_price', 'uid');
  659. if (!in_array($request->uid(), $position_tmp_one)) {
  660. $position = 0;
  661. } else {
  662. if ($position_tmp_two[$request->uid()] == 0.00) {
  663. $position = 0;
  664. } else {
  665. $position = array_search($request->uid(), $position_tmp_one) + 1;
  666. }
  667. }
  668. return app('json')->success([
  669. 'rank' => $users,
  670. 'position' => $position
  671. ]);
  672. }
  673. }