UserController.php 25 KB

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