UserController.php 27 KB

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