UserController.php 24 KB

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