UserController.php 25 KB

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