UserController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\http\validates\user\AddressValidate;
  4. use app\models\auction\AuctionOrder;
  5. use app\models\system\SystemCity;
  6. use crmeb\services\CacheService;
  7. use think\exception\ValidateException;
  8. use app\Request;
  9. use app\models\user\UserLevel;
  10. use app\models\user\UserSign;
  11. use app\models\store\StoreBargain;
  12. use app\models\store\StoreCombination;
  13. use app\models\store\StoreCouponUser;
  14. use app\models\store\StoreOrder;
  15. use app\models\store\StoreProductRelation;
  16. use app\models\store\StoreSeckill;
  17. use app\models\user\User;
  18. use app\models\user\UserAddress;
  19. use app\models\user\UserBill;
  20. use app\models\user\UserExtract;
  21. use app\models\user\UserNotice;
  22. use crmeb\services\GroupDataService;
  23. use crmeb\services\UtilService;
  24. use app\http\validates\user\UserValidates as Userva;
  25. /**
  26. * 用户类
  27. * Class UserController
  28. * @package app\api\controller\store
  29. */
  30. class UserController
  31. {
  32. /**
  33. * 获取用户信息
  34. * @param Request $request
  35. * @return mixed
  36. */
  37. public function userInfo(Request $request)
  38. {
  39. $info = $request->user()->toArray();
  40. $broken_time = intval(sys_config('extract_time'));
  41. $search_time = time() - 86400 * $broken_time;
  42. //返佣 +
  43. $brokerage_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  44. ->where('add_time', '>', $search_time)
  45. ->where('pm', 1)
  46. ->sum('number');
  47. //退款退的佣金 -
  48. $refund_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  49. ->where('add_time', '>', $search_time)
  50. ->where('pm', 0)
  51. ->sum('number');
  52. $info['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  53. if ($info['broken_commission'] < 0)
  54. $info['broken_commission'] = 0;
  55. $info['commissionCount'] = bcsub($info['brokerage_price'], $info['broken_commission'], 2);
  56. if ($info['commissionCount'] < 0)
  57. $info['commissionCount'] = 0;
  58. // $buy = AuctionOrder::where([['status', '=', 3], ['uid', '=', $request->uid()]])->sum('price');// 购买商品总额
  59. // $sell = AuctionOrder::where([['status', '=', 3], ['collection_id', '=', $request->uid()]])->sum('price');// 出售商品总额
  60. $sell = UserBill::where('uid', $info['uid'])->where('type', 'gs_integral')->sum('number');
  61. $level = UserLevel::where('id', $info['level'])->find();
  62. $info['level_name'] = $level['name']? $level['name'] : '会员';
  63. if ($sell){
  64. $info['profit'] = bcmul($sell, 2, 2);
  65. }else{
  66. $info['profit'] = 0; // 收益
  67. }
  68. $info['green'] = $info['is_new'] == 1? 1: $info['green_time'] >= strtotime(date('Y-m-d', time()))? 1 :0;
  69. return app('json')->success($info);
  70. }
  71. /**
  72. * 实名信息提交认证
  73. * @param Request $request
  74. * @return mixed
  75. */
  76. public function rname(Request $request){
  77. $validate = new Userva;
  78. $info = UtilService::postMore([
  79. ['rname', ''],
  80. ['cid', ''],
  81. ['cidimg', ''],
  82. ]);
  83. //规则验证
  84. if(!$validate->Check($info)){
  85. return app('json')->fail($validate->getError());
  86. }
  87. $res= User::where('card_id',$info['cid'])->where('is_auth', 2)->count();
  88. if($res >= 2){
  89. return app('json')->fail('身份证最多绑定两个账号');
  90. }
  91. $ress= User::where('uid',$request->uid())->find();
  92. if($ress['is_auth']==1||$ress['is_auth']==2){
  93. return app('json')->fail('您已提交认证,不可重复提交');
  94. }
  95. $res=User::cidUser($info['rname'],$info['cidimg'], $info['cid'],$request->uid());
  96. if ($res)return app('json')->success('上传成功');
  97. return app('json')->fail('上传失败');
  98. }
  99. /**
  100. * 实名信息查询
  101. * @param Request $request
  102. * @return mixed
  103. */
  104. public function rate(Request $request){
  105. $model=new User;
  106. $res=$model->where('uid',$request->uid())->find();
  107. $data=[
  108. 'is_auth'=>$res['is_auth'],
  109. 'off'=>$res['off']
  110. ];
  111. return app('json')->success($data);
  112. }
  113. /**
  114. * 用户资金统计
  115. * @param Request $request
  116. * @return mixed
  117. * @throws \think\Exception
  118. * @throws \think\db\exception\DataNotFoundException
  119. * @throws \think\db\exception\ModelNotFoundException
  120. * @throws \think\exception\DbException
  121. */
  122. public function balance(Request $request)
  123. {
  124. $uid = $request->uid();
  125. $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money'];//当前总资金
  126. $user['recharge'] = UserBill::getRecharge($uid);//累计充值
  127. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid);//累计消费
  128. return app('json')->successful($user);
  129. }
  130. /**
  131. * 个人中心
  132. * @param Request $request
  133. * @return mixed
  134. */
  135. public function user(Request $request)
  136. {
  137. $user = $request->user();
  138. $user = $user->toArray();
  139. $user['couponCount'] = StoreCouponUser::getUserValidCouponCount($user['uid']);
  140. $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
  141. $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']);
  142. $user['notice'] = UserNotice::getNotice($user['uid']);
  143. // $user['brokerage'] = UserBill::getBrokerage($user['uid']);//获取总佣金
  144. $user['recharge'] = UserBill::getRecharge($user['uid']);//累计充值
  145. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']);//累计消费
  146. $user['extractTotalPrice'] = UserExtract::userExtractTotalPrice($user['uid']);//累计提现
  147. $user['extractPrice'] = $user['brokerage_price'];//可提现
  148. $user['statu'] = (int)sys_config('store_brokerage_statu');
  149. $broken_time = intval(sys_config('extract_time'));
  150. $search_time = time() - 86400 * $broken_time;
  151. if (!$user['is_promoter'] && $user['statu'] == 2) {
  152. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price');
  153. $status = is_brokerage_statu($price);
  154. if ($status) {
  155. User::where('uid', $user['uid'])->update(['is_promoter' => 1]);
  156. $user['is_promoter'] = 1;
  157. } else {
  158. $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
  159. $user['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
  160. }
  161. }
  162. //可提现佣金
  163. //返佣 +
  164. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  165. ->where('add_time', '>', $search_time)
  166. ->where('pm', 1)
  167. ->sum('number');
  168. //退款退的佣金 -
  169. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  170. ->where('add_time', '>', $search_time)
  171. ->where('pm', 0)
  172. ->sum('number');
  173. $user['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  174. if ($user['broken_commission'] < 0)
  175. $user['broken_commission'] = 0;
  176. $user['commissionCount'] = bcsub($user['brokerage_price'], $user['broken_commission'], 2);
  177. if ($user['commissionCount'] < 0)
  178. $user['commissionCount'] = 0;
  179. if (!sys_config('vip_open'))
  180. $user['vip'] = false;
  181. else {
  182. $vipId = UserLevel::getUserLevel($user['uid']);
  183. $user['vip'] = $vipId !== false ? true : false;
  184. if ($user['vip']) {
  185. $user['vip_id'] = $vipId;
  186. $user['vip_icon'] = UserLevel::getUserLevelInfo($vipId, 'icon');
  187. $user['vip_name'] = UserLevel::getUserLevelInfo($vipId, 'name');
  188. }
  189. }
  190. $user['yesterDay'] = UserBill::yesterdayCommissionSum($user['uid']);
  191. $user['recharge_switch'] = (int)sys_config('recharge_switch');//充值开关
  192. $user['adminid'] = (boolean)\app\models\store\StoreService::orderServiceStatus($user['uid']);
  193. if ($user['phone'] && $user['user_type'] != 'h5') {
  194. $user['switchUserInfo'][] = $request->user();
  195. if ($h5UserInfo = User::where('account', $user['phone'])->where('user_type', 'h5')->find()) {
  196. $user['switchUserInfo'][] = $h5UserInfo;
  197. }
  198. } else if ($user['phone'] && $user['user_type'] == 'h5') {
  199. if ($wechatUserInfo = User::where('phone', $user['phone'])->where('user_type', '<>', 'h5')->find()) {
  200. $user['switchUserInfo'][] = $wechatUserInfo;
  201. }
  202. $user['switchUserInfo'][] = $request->user();
  203. } else if (!$user['phone']) {
  204. $user['switchUserInfo'][] = $request->user();
  205. }
  206. return app('json')->successful($user);
  207. }
  208. /**
  209. * 地址 获取单个
  210. * @param Request $request
  211. * @param $id
  212. * @return mixed
  213. * @throws \think\db\exception\DataNotFoundException
  214. * @throws \think\db\exception\ModelNotFoundException
  215. * @throws \think\exception\DbException
  216. */
  217. public function address(Request $request, $id)
  218. {
  219. $addressInfo = [];
  220. if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
  221. $addressInfo = UserAddress::find($id)->toArray();
  222. }
  223. return app('json')->successful($addressInfo);
  224. }
  225. /**
  226. * 地址列表
  227. * @param Request $request
  228. * @param $page
  229. * @param $limit
  230. * @return mixed
  231. */
  232. public function address_list(Request $request)
  233. {
  234. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true);
  235. $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default');
  236. return app('json')->successful($list);
  237. }
  238. /**
  239. * 设置默认地址
  240. *
  241. * @param Request $request
  242. * @return mixed
  243. */
  244. public function address_default_set(Request $request)
  245. {
  246. list($id) = UtilService::getMore([['id', 0]], $request, true);
  247. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  248. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  249. return app('json')->fail('地址不存在!');
  250. $res = UserAddress::setDefaultAddress($id, $request->uid());
  251. if (!$res)
  252. return app('json')->fail('地址不存在!');
  253. else
  254. return app('json')->successful();
  255. }
  256. /**
  257. * 获取默认地址
  258. * @param Request $request
  259. * @return mixed
  260. */
  261. public function address_default(Request $request)
  262. {
  263. $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default');
  264. if ($defaultAddress) {
  265. $defaultAddress = $defaultAddress->toArray();
  266. return app('json')->successful('ok', $defaultAddress);
  267. }
  268. return app('json')->successful('empty', []);
  269. }
  270. /**
  271. * 修改 添加地址
  272. * @param Request $request
  273. * @return mixed
  274. */
  275. public function address_edit(Request $request)
  276. {
  277. $addressInfo = UtilService::postMore([
  278. ['address', []],
  279. ['is_default', false],
  280. ['real_name', ''],
  281. ['post_code', ''],
  282. ['phone', ''],
  283. ['detail', ''],
  284. ['id', 0],
  285. ['type', 0]
  286. ], $request);
  287. if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!');
  288. if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!');
  289. if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!');
  290. if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) {
  291. return app('json')->fail('收货地址格式错误!请重新选择!');
  292. } else if ($addressInfo['type'] == 1 && !$addressInfo['id']) {
  293. $city = $addressInfo['address']['city'];
  294. $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id');
  295. if ($cityId) {
  296. $addressInfo['address']['city_id'] = $cityId;
  297. } else {
  298. if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) {
  299. return app('json')->fail('收货地址格式错误!修改后请重新导入!');
  300. }
  301. }
  302. }
  303. $addressInfo['province'] = $addressInfo['address']['province'];
  304. $addressInfo['city'] = $addressInfo['address']['city'];
  305. $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
  306. $addressInfo['district'] = $addressInfo['address']['district'];
  307. $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
  308. $addressInfo['uid'] = $request->uid();
  309. unset($addressInfo['address'], $addressInfo['type']);
  310. try {
  311. validate(AddressValidate::class)->check($addressInfo);
  312. } catch (ValidateException $e) {
  313. return app('json')->fail($e->getError());
  314. }
  315. //编辑
  316. if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
  317. $id = $addressInfo['id'];
  318. unset($addressInfo['id']);
  319. if ($addressInfo['city_id'] == 0)
  320. unset($addressInfo['city_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 \think\db\exception\DataNotFoundException
  450. * @throws \think\db\exception\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. $refund_integral = (int)UserBill::where(['uid' => $user['uid'], 'category' => 'integral', 'status' => 1, 'pm' => 0])->where('type', 'in', 'sign,system_add,gain')->sum('number');
  515. if ($user['sum_integral'] > $refund_integral)
  516. $user['sum_integral'] = $user['sum_integral'] - $refund_integral;
  517. else
  518. $user['sum_integral'] = 0;
  519. $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
  520. $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
  521. }
  522. unset($user['pwd']);
  523. if (!$user['is_promoter']) {
  524. $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == 2 ? true : false;
  525. }
  526. 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());
  527. }
  528. /**
  529. * 签到列表(年月)
  530. *
  531. * @param Request $request
  532. * @return mixed
  533. */
  534. public function sign_month(Request $request)
  535. {
  536. list($page, $limit) = UtilService::getMore([
  537. ['page', 0],
  538. ['limit', 0]
  539. ], $request, true);
  540. if (!$limit) return app('json')->successful([]);
  541. $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
  542. return app('json')->successful($userSignList);
  543. }
  544. /**
  545. * 获取活动状态
  546. * @return mixed
  547. */
  548. public function activity()
  549. {
  550. $data['is_bargin'] = StoreBargain::validBargain() ? true : false;
  551. $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false;
  552. $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false;
  553. return app('json')->successful($data);
  554. }
  555. /**
  556. * 用户修改信息
  557. * @param Request $request
  558. * @return mixed
  559. */
  560. public function edit(Request $request)
  561. {
  562. list($avatar, $nickname) = UtilService::postMore([
  563. ['avatar', ''],
  564. ['nickname', ''],
  565. ], $request, true);
  566. if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
  567. return app('json')->fail('修改失败');
  568. }
  569. /**
  570. * 推广人排行
  571. * @param Request $request
  572. * @return mixed
  573. * @throws \think\db\exception\DataNotFoundException
  574. * @throws \think\db\exception\ModelNotFoundException
  575. * @throws \think\exception\DbException
  576. */
  577. public function rank(Request $request)
  578. {
  579. $data = UtilService::getMore([
  580. ['page', ''],
  581. ['limit', ''],
  582. ['type', '']
  583. ], $request);
  584. $users = User::getRankList($data);
  585. return app('json')->success($users);
  586. }
  587. /**
  588. * 佣金排行
  589. * @param Request $request
  590. * @return mixed
  591. */
  592. public function brokerage_rank(Request $request)
  593. {
  594. $data = UtilService::getMore([
  595. ['page', ''],
  596. ['limit'],
  597. ['type']
  598. ], $request);
  599. $users = User::brokerageRank($data);
  600. foreach ($users as $key => $item) {
  601. if ($item['brokerage_price'] == '0.00' || $item['brokerage_price'] == 0 || !$item['brokerage_price']) {
  602. unset($users[$key]);
  603. }
  604. }
  605. $position_tmp = User::brokerageRank(['type' => $data['type'], 'page' => 0, 'limit' => 99999]);
  606. $position_tmp_one = array_column($position_tmp, 'uid');
  607. $position_tmp_two = array_column($position_tmp, 'brokerage_price', 'uid');
  608. if (!in_array($request->uid(), $position_tmp_one)) {
  609. $position = 0;
  610. } else {
  611. if ($position_tmp_two[$request->uid()] == 0.00) {
  612. $position = 0;
  613. } else {
  614. $position = array_search($request->uid(), $position_tmp_one) + 1;
  615. }
  616. }
  617. return app('json')->success([
  618. 'rank' => $users,
  619. 'position' => $position
  620. ]);
  621. }
  622. /**
  623. * 是否已设置支付密码
  624. * @param Request $request
  625. * @return mixed
  626. */
  627. public function is_pas(Request $request)
  628. {
  629. $user = $request->user();
  630. if ($user['payment']){
  631. return app('json')->success(['status' => 1]);
  632. }else{
  633. return app('json')->success(['status' => 0]);
  634. }
  635. }
  636. /**
  637. * 设置支付密码
  638. * @param Request $request
  639. * @return mixed
  640. * @throws \think\db\exception\DataNotFoundException
  641. * @throws \think\db\exception\DbException
  642. * @throws \think\db\exception\ModelNotFoundException
  643. */
  644. public function set_payment(Request $request)
  645. {
  646. $data = UtilService::postMore([
  647. ['type'],
  648. ['payment'],
  649. ['old_payment'],
  650. ['account'],
  651. ['captcha'],
  652. ], $request);
  653. if (!$data['type']) return app('json')->fail('类型不能为空');
  654. if (!$data['payment']) return app('json')->fail('密码不能为空');
  655. if (strlen($data['payment']) != 6) return app('json')->fail('密码必须为六位');
  656. $validate = new \think\Validate();
  657. $validate->rule('payment' , 'number');
  658. $validate->message(['payment.number' => '密码必须为数字']);
  659. if (!$validate->check($data)) return app('json')->fail($validate->getError());
  660. $user = User::where('uid', $request->uid())->find();
  661. if ($data['type'] == 1){
  662. $user['payment'] = md5($data['payment']);
  663. $res = $user->save();
  664. if ($res){
  665. return app('json')->success('成功');
  666. }else{
  667. return app('json')->fail('失败');
  668. }
  669. }elseif ($data['type'] == 2){
  670. // if (md5($data['old_payment']) != $user['payment']) return app('json')->fail('旧密码错误');
  671. $verifyCode = CacheService::get('code_' . $data['account']);
  672. if (!$verifyCode)
  673. return app('json')->fail('请先获取验证码');
  674. $verifyCode = substr($verifyCode, 0, 6);
  675. if ($verifyCode != $data['captcha'])
  676. return app('json')->fail('验证码错误');
  677. $user['payment'] = md5($data['payment']);
  678. if ($user->save()){
  679. return app('json')->success('成功');
  680. }else{
  681. return app('json')->fail('失败');
  682. }
  683. }
  684. return app('json')->fail('错误');
  685. }
  686. }