UserController.php 24 KB

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