UserController.php 27 KB

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