UserController.php 25 KB

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