UserController.php 24 KB

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