UserController.php 27 KB

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