UserController.php 30 KB

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