UserController.php 23 KB

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