UserController.php 26 KB

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