UserController.php 26 KB

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