UserController.php 24 KB

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