UserController.php 24 KB

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