UserController.php 27 KB

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