UserController.php 28 KB

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