UserController.php 27 KB

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