UserController.php 28 KB

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