UserController.php 27 KB

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