UserController.php 27 KB

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