UserController.php 23 KB

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