UserController.php 25 KB

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