UserController.php 27 KB

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