UserController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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, &$teamUids = [])
  122. {
  123. @file_put_contents('quanju.txt', $uid . "-你人呢\r\n", 8);
  124. // 获取直接下级
  125. $directSubordinates = User::where('spread_uid', $uid)->column('uid');
  126. if (!empty($directSubordinates)) {
  127. // 过滤掉最开始传入的UID
  128. $directSubordinates = array_diff($directSubordinates, [$uid]);
  129. // 合并当前直接下级UID到团队UID列表
  130. $teamUids = array_merge($teamUids, $directSubordinates);
  131. // 递归获取下级的下级
  132. foreach ($directSubordinates as $subordinateUid) {
  133. self::getAllTeamMembers($subordinateUid, $teamUids);
  134. }
  135. }
  136. return $teamUids;
  137. }
  138. /**
  139. * 用户资金统计
  140. * @param Request $request
  141. * @return mixed
  142. * @throws \think\Exception
  143. * @throws DataNotFoundException
  144. * @throws ModelNotFoundException
  145. * @throws \think\exception\DbException
  146. */
  147. public function balance(Request $request)
  148. {
  149. $uid = $request->uid();
  150. $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money'];//当前总资金
  151. $user['recharge'] = UserBill::getRecharge($uid);//累计充值
  152. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid);//累计消费
  153. return app('json')->successful($user);
  154. }
  155. /**
  156. * 个人中心
  157. * @param Request $request
  158. * @return mixed
  159. */
  160. public function user(Request $request)
  161. {
  162. $user = $request->user();
  163. $user = $user->toArray();
  164. $user['couponCount'] = StoreCouponUser::getUserValidCouponCount($user['uid']);
  165. $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
  166. $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']);
  167. $user['notice'] = UserNotice::getNotice($user['uid']);
  168. $user['brokerage'] = UserBill::getBrokerage($user['uid']);//获取总佣金
  169. $user['recharge'] = UserBill::getRecharge($user['uid']);//累计充值
  170. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']);//累计消费
  171. $user['extractTotalPrice'] = UserExtract::userExtractTotalPrice($user['uid']);//累计提现
  172. $user['extractPrice'] = $user['brokerage_price'];//可提现
  173. $user['statu'] = (int)sys_config('store_brokerage_statu');
  174. $broken_time = intval(sys_config('extract_time'));
  175. $search_time = time() - 86400 * $broken_time;
  176. if (!$user['is_promoter'] && $user['statu'] == 2) {
  177. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price');
  178. $status = is_brokerage_statu($price);
  179. if ($status) {
  180. User::where('uid', $user['uid'])->update(['is_promoter' => 1]);
  181. $user['is_promoter'] = 1;
  182. } else {
  183. $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
  184. $user['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
  185. }
  186. }
  187. //可提现佣金
  188. //返佣 +
  189. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'brokerage_price'])
  190. ->where('add_time', '>', $search_time)
  191. ->where('pm', 1)
  192. ->sum('number');
  193. //退款退的佣金 -
  194. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'brokerage_price'])
  195. ->where('add_time', '>', $search_time)
  196. ->where('pm', 0)
  197. ->sum('number');
  198. $user['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  199. if ($user['broken_commission'] < 0)
  200. $user['broken_commission'] = 0;
  201. $user['commissionCount'] = bcsub($user['brokerage_price'], $user['broken_commission'], 2);
  202. if ($user['commissionCount'] < 0)
  203. $user['commissionCount'] = 0;
  204. if (!sys_config('vip_open'))
  205. $user['vip'] = false;
  206. else {
  207. $vipId = UserLevel::getUserLevel($user['uid']);
  208. $user['vip'] = $vipId !== false ? true : false;
  209. if ($user['vip']) {
  210. $user['vip_id'] = $vipId;
  211. $user['vip_icon'] = UserLevel::getUserLevelInfo($vipId, 'icon');
  212. $user['vip_name'] = UserLevel::getUserLevelInfo($vipId, 'name');
  213. }
  214. }
  215. $user['yesterDay'] = UserBill::yesterdayCommissionSum($user['uid']);
  216. $user['recharge_switch'] = (int)sys_config('recharge_switch');//充值开关
  217. $user['adminid'] = (boolean)\app\models\store\StoreService::orderServiceStatus($user['uid']);
  218. if ($user['phone'] && $user['user_type'] != 'h5') {
  219. $user['switchUserInfo'][] = $request->user();
  220. if ($h5UserInfo = User::where('account', $user['phone'])->where('user_type', 'h5')->find()) {
  221. $user['switchUserInfo'][] = $h5UserInfo;
  222. }
  223. } else if ($user['phone'] && $user['user_type'] == 'h5') {
  224. if ($wechatUserInfo = User::where('phone', $user['phone'])->where('user_type', '<>', 'h5')->find()) {
  225. $user['switchUserInfo'][] = $wechatUserInfo;
  226. }
  227. $user['switchUserInfo'][] = $request->user();
  228. } else if (!$user['phone']) {
  229. $user['switchUserInfo'][] = $request->user();
  230. }
  231. return app('json')->successful($user);
  232. }
  233. /**
  234. * 地址 获取单个
  235. * @param Request $request
  236. * @param $id
  237. * @return mixed
  238. * @throws DataNotFoundException
  239. * @throws ModelNotFoundException
  240. * @throws \think\exception\DbException
  241. */
  242. public function address(Request $request, $id)
  243. {
  244. $addressInfo = [];
  245. if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
  246. $addressInfo = UserAddress::find($id)->toArray();
  247. }
  248. return app('json')->successful($addressInfo);
  249. }
  250. /**
  251. * 地址列表
  252. * @param Request $request
  253. * @param $page
  254. * @param $limit
  255. * @return mixed
  256. */
  257. public function address_list(Request $request)
  258. {
  259. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true);
  260. $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default');
  261. return app('json')->successful($list);
  262. }
  263. /**
  264. * 设置默认地址
  265. *
  266. * @param Request $request
  267. * @return mixed
  268. */
  269. public function address_default_set(Request $request)
  270. {
  271. list($id) = UtilService::getMore([['id', 0]], $request, true);
  272. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  273. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  274. return app('json')->fail('地址不存在!');
  275. $res = UserAddress::setDefaultAddress($id, $request->uid());
  276. if (!$res)
  277. return app('json')->fail('地址不存在!');
  278. else
  279. return app('json')->successful();
  280. }
  281. /**
  282. * 获取默认地址
  283. * @param Request $request
  284. * @return mixed
  285. */
  286. public function address_default(Request $request)
  287. {
  288. $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default');
  289. if ($defaultAddress) {
  290. $defaultAddress = $defaultAddress->toArray();
  291. return app('json')->successful('ok', $defaultAddress);
  292. }
  293. return app('json')->successful('empty', []);
  294. }
  295. /**
  296. * 修改 添加地址
  297. * @param Request $request
  298. * @return mixed
  299. */
  300. public function address_edit(Request $request)
  301. {
  302. $addressInfo = UtilService::postMore([
  303. ['address', []],
  304. ['is_default', false],
  305. ['real_name', ''],
  306. ['post_code', ''],
  307. ['phone', ''],
  308. ['detail', ''],
  309. ['id', 0],
  310. ['type', 0]
  311. ], $request);
  312. if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!');
  313. if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!');
  314. if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!');
  315. if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) {
  316. return app('json')->fail('收货地址格式错误!请重新选择!');
  317. } else if ($addressInfo['type'] == 1) {
  318. $city = $addressInfo['address']['city'];
  319. $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id');
  320. if ($cityId) {
  321. $addressInfo['address']['city_id'] = $cityId;
  322. } else {
  323. if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) {
  324. return app('json')->fail('收货地址格式错误!修改后请重新导入!');
  325. }
  326. $addressInfo['address']['city_id'] = $cityId;
  327. }
  328. }
  329. $addressInfo['province'] = $addressInfo['address']['province'];
  330. $addressInfo['city'] = $addressInfo['address']['city'];
  331. $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
  332. $addressInfo['district'] = $addressInfo['address']['district'];
  333. $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
  334. $addressInfo['uid'] = $request->uid();
  335. unset($addressInfo['address'], $addressInfo['type']);
  336. try {
  337. validate(AddressValidate::class)->check($addressInfo);
  338. } catch (ValidateException $e) {
  339. return app('json')->fail($e->getError());
  340. }
  341. if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
  342. $id = $addressInfo['id'];
  343. unset($addressInfo['id']);
  344. if (UserAddress::edit($addressInfo, $id, 'id')) {
  345. if ($addressInfo['is_default'])
  346. UserAddress::setDefaultAddress($id, $request->uid());
  347. return app('json')->successful();
  348. } else
  349. return app('json')->fail('编辑收货地址失败!');
  350. } else {
  351. $addressInfo['add_time'] = time();
  352. if ($address = UserAddress::create($addressInfo)) {
  353. if ($addressInfo['is_default']) {
  354. UserAddress::setDefaultAddress($address->id, $request->uid());
  355. }
  356. return app('json')->successful(['id' => $address->id]);
  357. } else {
  358. return app('json')->fail('添加收货地址失败!');
  359. }
  360. }
  361. }
  362. /**
  363. * 删除地址
  364. *
  365. * @param Request $request
  366. * @return mixed
  367. */
  368. public function address_del(Request $request)
  369. {
  370. list($id) = UtilService::postMore([['id', 0]], $request, true);
  371. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  372. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  373. return app('json')->fail('地址不存在!');
  374. if (UserAddress::edit(['is_del' => '1'], $id, 'id'))
  375. return app('json')->successful();
  376. else
  377. return app('json')->fail('删除地址失败!');
  378. }
  379. /**
  380. * 获取收藏产品
  381. *
  382. * @param Request $request
  383. * @return mixed
  384. */
  385. public function collect_user(Request $request)
  386. {
  387. list($page, $limit) = UtilService::getMore([
  388. ['page', 0],
  389. ['limit', 0]
  390. ], $request, true);
  391. if (!(int)$limit) return app('json')->successful([]);
  392. $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit);
  393. return app('json')->successful($productRelationList);
  394. }
  395. /**
  396. * 添加收藏
  397. * @param Request $request
  398. * @param $id
  399. * @param $category
  400. * @return mixed
  401. */
  402. public function collect_add(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::productRelation($id, $request->uid(), 'collect', $category);
  407. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  408. else return app('json')->successful();
  409. }
  410. /**
  411. * 取消收藏
  412. *
  413. * @param Request $request
  414. * @return mixed
  415. */
  416. public function collect_del(Request $request)
  417. {
  418. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  419. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  420. $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category);
  421. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  422. else return app('json')->successful();
  423. }
  424. /**
  425. * 批量收藏
  426. * @param Request $request
  427. * @return mixed
  428. */
  429. public function collect_all(Request $request)
  430. {
  431. $collectInfo = UtilService::postMore([
  432. ['id', []],
  433. ['category', 'product'],
  434. ], $request);
  435. if (!count($collectInfo['id'])) return app('json')->fail('参数错误');
  436. $productIdS = $collectInfo['id'];
  437. $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['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_add(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::productRelation($id,$request->uid(),'like',$category);
  452. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  453. // else return app('json')->successful();
  454. // }
  455. /**
  456. * 取消点赞
  457. *
  458. * @param Request $request
  459. * @return mixed
  460. */
  461. // public function like_del(Request $request)
  462. // {
  463. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  464. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  465. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  466. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  467. // else return app('json')->successful();
  468. // }
  469. /**
  470. * 签到 配置
  471. * @return mixed
  472. * @throws DataNotFoundException
  473. * @throws ModelNotFoundException
  474. * @throws \think\exception\DbException
  475. */
  476. public function sign_config()
  477. {
  478. $signConfig = sys_data('sign_day_num') ?? [];
  479. return app('json')->successful($signConfig);
  480. }
  481. /**
  482. * 签到 列表
  483. * @param Request $request
  484. * @param $page
  485. * @param $limit
  486. * @return mixed
  487. */
  488. public function sign_list(Request $request)
  489. {
  490. list($page, $limit) = UtilService::getMore([
  491. ['page', 0],
  492. ['limit', 0]
  493. ], $request, true);
  494. if (!$limit) return app('json')->successful([]);
  495. $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit);
  496. if ($signList) $signList = $signList->toArray();
  497. return app('json')->successful($signList);
  498. }
  499. /**
  500. * 签到
  501. * @param Request $request
  502. * @return mixed
  503. */
  504. public function sign_integral(Request $request)
  505. {
  506. $signed = UserSign::getIsSign($request->uid());
  507. if ($signed) return app('json')->fail('已签到');
  508. if (false !== ($integral = UserSign::sign($request->uid())))
  509. return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]);
  510. return app('json')->fail(UserSign::getErrorInfo('签到失败'));
  511. }
  512. /**
  513. * 签到用户信息
  514. * @param Request $request
  515. * @return mixed
  516. */
  517. public function sign_user(Request $request)
  518. {
  519. list($sign, $integral, $all) = UtilService::postMore([
  520. ['sign', 0],
  521. ['integral', 0],
  522. ['all', 0],
  523. ], $request, true);
  524. $user = $request->user();
  525. //是否统计签到
  526. if ($sign || $all) {
  527. $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']);
  528. $user['is_day_sgin'] = UserSign::getIsSign($user['uid']);
  529. $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday');
  530. if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) {
  531. $user['sign_num'] = 0;
  532. }
  533. }
  534. //是否统计积分使用情况
  535. if ($integral || $all) {
  536. $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain');
  537. $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
  538. $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
  539. }
  540. unset($user['pwd']);
  541. if (!$user['is_promoter']) {
  542. $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == 2 ? true : false;
  543. }
  544. 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());
  545. }
  546. /**
  547. * 签到列表(年月)
  548. *
  549. * @param Request $request
  550. * @return mixed
  551. */
  552. public function sign_month(Request $request)
  553. {
  554. list($page, $limit) = UtilService::getMore([
  555. ['page', 0],
  556. ['limit', 0]
  557. ], $request, true);
  558. if (!$limit) return app('json')->successful([]);
  559. $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
  560. return app('json')->successful($userSignList);
  561. }
  562. /**
  563. * 获取活动状态
  564. * @return mixed
  565. */
  566. public function activity()
  567. {
  568. $data['is_bargin'] = StoreBargain::validBargain() ? true : false;
  569. $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false;
  570. $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false;
  571. return app('json')->successful($data);
  572. }
  573. /**
  574. * 用户修改信息
  575. * @param Request $request
  576. * @return mixed
  577. */
  578. public function edit(Request $request)
  579. {
  580. list($avatar, $nickname) = UtilService::postMore([
  581. ['avatar', ''],
  582. ['nickname', ''],
  583. ], $request, true);
  584. if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
  585. return app('json')->fail('修改失败');
  586. }
  587. /**
  588. * 推广人排行
  589. * @param Request $request
  590. * @return mixed
  591. * @throws DataNotFoundException
  592. * @throws ModelNotFoundException
  593. * @throws \think\exception\DbException
  594. */
  595. public function rank(Request $request)
  596. {
  597. $data = UtilService::getMore([
  598. ['page', ''],
  599. ['limit', ''],
  600. ['type', '']
  601. ], $request);
  602. $users = User::getRankList($data);
  603. return app('json')->success($users);
  604. }
  605. /**
  606. * 佣金排行
  607. * @param Request $request
  608. * @return mixed
  609. */
  610. public function brokerage_rank(Request $request)
  611. {
  612. $data = UtilService::getMore([
  613. ['page', ''],
  614. ['limit'],
  615. ['type']
  616. ], $request);
  617. return app('json')->success([
  618. 'rank' => User::brokerageRank($data),
  619. 'position' => User::currentUserRank($data['type'], $request->user()['brokerage_price'])
  620. ]);
  621. }
  622. /**
  623. * 添加访问记录
  624. * @param Request $request
  625. * @return mixed
  626. */
  627. public function set_visit(Request $request)
  628. {
  629. $data = UtilService::postMore([
  630. ['url', ''],
  631. ['stay_time', 0]
  632. ], $request);
  633. if ($data['url'] == '') return app('json')->fail('未获取页面路径');
  634. $data['uid'] = $request->uid();
  635. $data['ip'] = $request->ip();
  636. $data['add_time'] = time();
  637. $res = UserVisit::insert($data);
  638. if ($res) {
  639. return app('json')->success('添加访问记录成功');
  640. } else {
  641. return app('json')->fail('添加访问记录失败');
  642. }
  643. }
  644. /**
  645. * 静默绑定推广人
  646. * @param Request $request
  647. * @return mixed
  648. * @throws DataNotFoundException
  649. * @throws DbException
  650. * @throws ModelNotFoundException
  651. */
  652. public function spread(Request $request)
  653. {
  654. $puid = $request->post('puid/d', 0);
  655. return app('json')->success(User::setSpread($puid, $request->uid()));
  656. }
  657. }