UserController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\http\validates\user\AddressValidate;
  4. use app\models\system\SystemCity;
  5. use app\models\user\UserRechargeExamine;
  6. use app\models\user\UserVisit;
  7. use crmeb\services\CacheService;
  8. use think\db\exception\DataNotFoundException;
  9. use think\db\exception\DbException;
  10. use think\db\exception\ModelNotFoundException;
  11. use think\exception\ValidateException;
  12. use app\Request;
  13. use app\models\user\UserLevel;
  14. use app\models\user\UserSign;
  15. use app\models\store\StoreBargain;
  16. use app\models\store\StoreCombination;
  17. use app\models\store\StoreCouponUser;
  18. use app\models\store\StoreOrder;
  19. use app\models\store\StoreProductRelation;
  20. use app\models\store\StoreSeckill;
  21. use app\models\user\User;
  22. use app\models\user\UserAddress;
  23. use app\models\user\UserBill;
  24. use app\models\user\UserExtract;
  25. use app\models\user\UserNotice;
  26. use crmeb\services\GroupDataService;
  27. use crmeb\services\UtilService;
  28. use think\facade\Validate;
  29. /**
  30. * 用户类
  31. * Class UserController
  32. * @package app\api\controller\store
  33. */
  34. class UserController
  35. {
  36. /**
  37. * 获取用户信息
  38. * @param Request $request
  39. * @return mixed
  40. */
  41. public function userInfo(Request $request)
  42. {
  43. $info = $request->user()->toArray();
  44. $broken_time = intval(sys_config('extract_time'));
  45. $search_time = time() - 86400 * $broken_time;
  46. //返佣 +
  47. $brokerage_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  48. ->where('add_time', '>', $search_time)
  49. ->where('pm', 1)
  50. ->sum('number');
  51. //退款退的佣金 -
  52. $refund_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  53. ->where('add_time', '>', $search_time)
  54. ->where('pm', 0)
  55. ->sum('number');
  56. $info['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  57. if ($info['broken_commission'] < 0)
  58. $info['broken_commission'] = 0;
  59. $info['commissionCount'] = bcsub($info['brokerage_price'], $info['broken_commission'], 2);
  60. if ($info['commissionCount'] < 0)
  61. $info['commissionCount'] = 0;
  62. $info['kpi'] = UserBill::where('type', 'add_sp_final_kpi')->where('uid', $request->uid())->where('add_time', '>', strtotime(date('Y-m-d', time())))->sum('number');
  63. if ($info['kpi'] < 0){
  64. $info['kpi'] = 0;
  65. }
  66. $info['user_dow'] = User::where('spread_uid', $request->uid())->count();
  67. $user = User::select();
  68. $team = get_downline($user, $request->uid());
  69. $info['team'] = count($team) < 1 ? 0 : count($team);
  70. return app('json')->success($info);
  71. }
  72. /**
  73. * 用户资金统计
  74. * @param Request $request
  75. * @return mixed
  76. * @throws \think\Exception
  77. * @throws DataNotFoundException
  78. * @throws ModelNotFoundException
  79. * @throws \think\exception\DbException
  80. */
  81. public function balance(Request $request)
  82. {
  83. $uid = $request->uid();
  84. $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money'];//当前总资金
  85. $user['recharge'] = UserBill::getRecharge($uid);//累计充值
  86. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid);//累计消费
  87. return app('json')->successful($user);
  88. }
  89. /**
  90. * 个人中心
  91. * @param Request $request
  92. * @return mixed
  93. */
  94. public function user(Request $request)
  95. {
  96. $user = $request->user();
  97. $user = $user->toArray();
  98. $user['couponCount'] = StoreCouponUser::getUserValidCouponCount($user['uid']);
  99. $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
  100. $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']);
  101. $user['notice'] = UserNotice::getNotice($user['uid']);
  102. // $user['brokerage'] = UserBill::getBrokerage($user['uid']);//获取总佣金
  103. $user['recharge'] = UserBill::getRecharge($user['uid']);//累计充值
  104. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']);//累计消费
  105. $user['extractTotalPrice'] = UserExtract::userExtractTotalPrice($user['uid']);//累计提现
  106. $user['extractPrice'] = $user['brokerage_price'];//可提现
  107. $user['statu'] = (int)sys_config('store_brokerage_statu');
  108. $broken_time = intval(sys_config('extract_time'));
  109. $search_time = time() - 86400 * $broken_time;
  110. if (!$user['is_promoter'] && $user['statu'] == 2) {
  111. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price');
  112. $status = is_brokerage_statu($price);
  113. if ($status) {
  114. User::where('uid', $user['uid'])->update(['is_promoter' => 1]);
  115. $user['is_promoter'] = 1;
  116. } else {
  117. $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
  118. $user['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
  119. }
  120. }
  121. //可提现佣金
  122. //返佣 +
  123. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  124. ->where('add_time', '>', $search_time)
  125. ->where('pm', 1)
  126. ->sum('number');
  127. //退款退的佣金 -
  128. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  129. ->where('add_time', '>', $search_time)
  130. ->where('pm', 0)
  131. ->sum('number');
  132. $user['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  133. if ($user['broken_commission'] < 0)
  134. $user['broken_commission'] = 0;
  135. $user['commissionCount'] = bcsub($user['brokerage_price'], $user['broken_commission'], 2);
  136. if ($user['commissionCount'] < 0)
  137. $user['commissionCount'] = 0;
  138. if (!sys_config('vip_open'))
  139. $user['vip'] = false;
  140. else {
  141. $vipId = UserLevel::getUserLevel($user['uid']);
  142. $user['vip'] = $vipId !== false ? true : false;
  143. if ($user['vip']) {
  144. $user['vip_id'] = $vipId;
  145. $user['vip_icon'] = UserLevel::getUserLevelInfo($vipId, 'icon');
  146. $user['vip_name'] = UserLevel::getUserLevelInfo($vipId, 'name');
  147. }
  148. }
  149. $user['yesterDay'] = UserBill::yesterdayCommissionSum($user['uid']);
  150. $user['recharge_switch'] = (int)sys_config('recharge_switch');//充值开关
  151. $user['adminid'] = (boolean)\app\models\store\StoreService::orderServiceStatus($user['uid']);
  152. if ($user['phone'] && $user['user_type'] != 'h5') {
  153. $user['switchUserInfo'][] = $request->user();
  154. if ($h5UserInfo = User::where('account', $user['phone'])->where('user_type', 'h5')->find()) {
  155. $user['switchUserInfo'][] = $h5UserInfo;
  156. }
  157. } else if ($user['phone'] && $user['user_type'] == 'h5') {
  158. if ($wechatUserInfo = User::where('phone', $user['phone'])->where('user_type', '<>', 'h5')->find()) {
  159. $user['switchUserInfo'][] = $wechatUserInfo;
  160. }
  161. $user['switchUserInfo'][] = $request->user();
  162. } else if (!$user['phone']) {
  163. $user['switchUserInfo'][] = $request->user();
  164. }
  165. return app('json')->successful($user);
  166. }
  167. /**
  168. * 地址 获取单个
  169. * @param Request $request
  170. * @param $id
  171. * @return mixed
  172. * @throws DataNotFoundException
  173. * @throws ModelNotFoundException
  174. * @throws \think\exception\DbException
  175. */
  176. public function address(Request $request, $id)
  177. {
  178. $addressInfo = [];
  179. if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
  180. $addressInfo = UserAddress::find($id)->toArray();
  181. }
  182. return app('json')->successful($addressInfo);
  183. }
  184. /**
  185. * 地址列表
  186. * @param Request $request
  187. * @param $page
  188. * @param $limit
  189. * @return mixed
  190. */
  191. public function address_list(Request $request)
  192. {
  193. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true);
  194. $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default');
  195. return app('json')->successful($list);
  196. }
  197. /**
  198. * 设置默认地址
  199. *
  200. * @param Request $request
  201. * @return mixed
  202. */
  203. public function address_default_set(Request $request)
  204. {
  205. list($id) = UtilService::getMore([['id', 0]], $request, true);
  206. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  207. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  208. return app('json')->fail('地址不存在!');
  209. $res = UserAddress::setDefaultAddress($id, $request->uid());
  210. if (!$res)
  211. return app('json')->fail('地址不存在!');
  212. else
  213. return app('json')->successful();
  214. }
  215. /**
  216. * 获取默认地址
  217. * @param Request $request
  218. * @return mixed
  219. */
  220. public function address_default(Request $request)
  221. {
  222. $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default');
  223. if ($defaultAddress) {
  224. $defaultAddress = $defaultAddress->toArray();
  225. return app('json')->successful('ok', $defaultAddress);
  226. }
  227. return app('json')->successful('empty', []);
  228. }
  229. /**
  230. * 转换
  231. * @param Request $request
  232. * @return mixed
  233. */
  234. public function coral(Request $request){
  235. $uid=$request->user();
  236. $data=$request->Post();
  237. if($data['amount']==''){
  238. return app('json')->fail('数值不能为空!');
  239. }
  240. $datas=[];
  241. $datas['amount']=$data['amount'];
  242. $datas['uid']=$uid['uid'];
  243. $datas['type']=$data['type'];
  244. // 消费余额转购物积分
  245. if($data['type']==1){
  246. if ($request->user()['now_money'] < $datas['amount']) return app('json')->fail('消费积分不足!');
  247. $datas['type1']='now_money';
  248. $datas['type2']='sp_final';
  249. }
  250. // 购物积分转换成提货券
  251. if($data['type']==2){
  252. if ($request->user()['sp_final'] < $datas['amount']) return app('json')->fail('购物积分不足!');
  253. $datas['type1']='sp_final';
  254. $datas['type2']='top_ticket';
  255. }
  256. $res=$this->change($datas);
  257. if($res=0){
  258. return app('json')->fail('转换失败!');
  259. }
  260. return app('json')->successful("转换成功");
  261. }
  262. /**
  263. * 账户转换
  264. * @param Request $request
  265. * @return mixed
  266. */
  267. public function change($data){
  268. //取出类型1的值
  269. $res=User::where('uid',$data['uid'])->find();
  270. $type1=floatval($res[$data['type1']]-$data['amount']);
  271. $type2=floatval($res[$data['type2']]+$data['amount']);
  272. $type3=floatval($res['aid_val']+$data['amount']);
  273. if($data['type']==2){
  274. $res1=User::where('uid',$data['uid'])->update([$data['type1'] =>$type1,$data['type2']=>$type2,'aid_val'=>$type3]);
  275. UserBill::expend('购物积分转换提货券', $data['uid'], 'sp_final', 'sub_sp_final', $data['amount'], 0,$type1, '购物积分转换提货券');
  276. UserBill::income('购物积分转换提货券', $data['uid'], 'top_ticket', 'add_top_ticket', $data['amount'], 0,$type2, '购物积分转换提货券');
  277. UserBill::income('转换增加广告值', $data['uid'], 'aid_val', 'add_aid_val', $data['amount'], 0,$type3, '转换增加广告值');
  278. }else{
  279. $res1=User::where('uid',$data['uid'])->update([$data['type1'] =>$type1,$data['type2']=>$type2]);
  280. UserBill::expend('余额转换购物积分', $data['uid'], 'now_money', 'sub_now_money', $data['amount'], 0,$type1, '余额转换购物积分');
  281. UserBill::income('余额转换购物积分', $data['uid'], 'sp_final', 'add_sp_final', $data['amount'], 0,$type2, '余额转换购物积分');
  282. }
  283. return $res1;
  284. }
  285. /**
  286. * 修改 添加地址
  287. * @param Request $request
  288. * @return mixed
  289. */
  290. public function address_edit(Request $request)
  291. {
  292. $addressInfo = UtilService::postMore([
  293. ['address', []],
  294. ['is_default', false],
  295. ['real_name', ''],
  296. ['post_code', ''],
  297. ['phone', ''],
  298. ['detail', ''],
  299. ['id', 0],
  300. ['type', 0]
  301. ], $request);
  302. if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!');
  303. if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!');
  304. if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!');
  305. if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) {
  306. return app('json')->fail('收货地址格式错误!请重新选择!');
  307. } else if ($addressInfo['type'] == 1) {
  308. $city = $addressInfo['address']['city'];
  309. $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id');
  310. if ($cityId) {
  311. $addressInfo['address']['city_id'] = $cityId;
  312. } else {
  313. if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) {
  314. return app('json')->fail('收货地址格式错误!修改后请重新导入!');
  315. }
  316. $addressInfo['address']['city_id'] = $cityId;
  317. }
  318. }
  319. $addressInfo['province'] = $addressInfo['address']['province'];
  320. $addressInfo['city'] = $addressInfo['address']['city'];
  321. $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
  322. $addressInfo['district'] = $addressInfo['address']['district'];
  323. $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
  324. $addressInfo['uid'] = $request->uid();
  325. unset($addressInfo['address'], $addressInfo['type']);
  326. try {
  327. validate(AddressValidate::class)->check($addressInfo);
  328. } catch (ValidateException $e) {
  329. return app('json')->fail($e->getError());
  330. }
  331. if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
  332. $id = $addressInfo['id'];
  333. unset($addressInfo['id']);
  334. if (UserAddress::edit($addressInfo, $id, 'id')) {
  335. if ($addressInfo['is_default'])
  336. UserAddress::setDefaultAddress($id, $request->uid());
  337. return app('json')->successful();
  338. } else
  339. return app('json')->fail('编辑收货地址失败!');
  340. } else {
  341. $addressInfo['add_time'] = time();
  342. if ($address = UserAddress::create($addressInfo)) {
  343. if ($addressInfo['is_default']) {
  344. UserAddress::setDefaultAddress($address->id, $request->uid());
  345. }
  346. return app('json')->successful(['id' => $address->id]);
  347. } else {
  348. return app('json')->fail('添加收货地址失败!');
  349. }
  350. }
  351. }
  352. /**
  353. * 删除地址
  354. *
  355. * @param Request $request
  356. * @return mixed
  357. */
  358. public function address_del(Request $request)
  359. {
  360. list($id) = UtilService::postMore([['id', 0]], $request, true);
  361. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  362. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  363. return app('json')->fail('地址不存在!');
  364. if (UserAddress::edit(['is_del' => '1'], $id, 'id'))
  365. return app('json')->successful();
  366. else
  367. return app('json')->fail('删除地址失败!');
  368. }
  369. /**
  370. * 获取收藏产品
  371. *
  372. * @param Request $request
  373. * @return mixed
  374. */
  375. public function collect_user(Request $request)
  376. {
  377. list($page, $limit) = UtilService::getMore([
  378. ['page', 0],
  379. ['limit', 0]
  380. ], $request, true);
  381. if (!(int)$limit) return app('json')->successful([]);
  382. $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit);
  383. return app('json')->successful($productRelationList);
  384. }
  385. /**
  386. * 添加收藏
  387. * @param Request $request
  388. * @param $id
  389. * @param $category
  390. * @return mixed
  391. */
  392. public function collect_add(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::productRelation($id, $request->uid(), 'collect', $category);
  397. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  398. else return app('json')->successful();
  399. }
  400. /**
  401. * 取消收藏
  402. *
  403. * @param Request $request
  404. * @return mixed
  405. */
  406. public function collect_del(Request $request)
  407. {
  408. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  409. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  410. $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category);
  411. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  412. else return app('json')->successful();
  413. }
  414. /**
  415. * 批量收藏
  416. * @param Request $request
  417. * @return mixed
  418. */
  419. public function collect_all(Request $request)
  420. {
  421. $collectInfo = UtilService::postMore([
  422. ['id', []],
  423. ['category', 'product'],
  424. ], $request);
  425. if (!count($collectInfo['id'])) return app('json')->fail('参数错误');
  426. $productIdS = $collectInfo['id'];
  427. $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['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_add(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::productRelation($id,$request->uid(),'like',$category);
  442. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  443. // else return app('json')->successful();
  444. // }
  445. /**
  446. * 取消点赞
  447. *
  448. * @param Request $request
  449. * @return mixed
  450. */
  451. // public function like_del(Request $request)
  452. // {
  453. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  454. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  455. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  456. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  457. // else return app('json')->successful();
  458. // }
  459. /**
  460. * 签到 配置
  461. * @return mixed
  462. * @throws DataNotFoundException
  463. * @throws ModelNotFoundException
  464. * @throws \think\exception\DbException
  465. */
  466. public function sign_config()
  467. {
  468. $signConfig = sys_data('sign_day_num') ?? [];
  469. return app('json')->successful($signConfig);
  470. }
  471. /**
  472. * 签到 列表
  473. * @param Request $request
  474. * @param $page
  475. * @param $limit
  476. * @return mixed
  477. */
  478. public function sign_list(Request $request)
  479. {
  480. list($page, $limit) = UtilService::getMore([
  481. ['page', 0],
  482. ['limit', 0]
  483. ], $request, true);
  484. if (!$limit) return app('json')->successful([]);
  485. $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit);
  486. if ($signList) $signList = $signList->toArray();
  487. return app('json')->successful($signList);
  488. }
  489. /**
  490. * 签到
  491. * @param Request $request
  492. * @return mixed
  493. */
  494. public function sign_integral(Request $request)
  495. {
  496. $signed = UserSign::getIsSign($request->uid());
  497. if ($signed) return app('json')->fail('已签到');
  498. if (false !== ($integral = UserSign::sign($request->uid())))
  499. return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]);
  500. return app('json')->fail(UserSign::getErrorInfo('签到失败'));
  501. }
  502. /**
  503. * 签到用户信息
  504. * @param Request $request
  505. * @return mixed
  506. */
  507. public function sign_user(Request $request)
  508. {
  509. list($sign, $integral, $all) = UtilService::postMore([
  510. ['sign', 0],
  511. ['integral', 0],
  512. ['all', 0],
  513. ], $request, true);
  514. $user = $request->user();
  515. //是否统计签到
  516. if ($sign || $all) {
  517. $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']);
  518. $user['is_day_sgin'] = UserSign::getIsSign($user['uid']);
  519. $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday');
  520. if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) {
  521. $user['sign_num'] = 0;
  522. }
  523. }
  524. //是否统计积分使用情况
  525. if ($integral || $all) {
  526. $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain');
  527. $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
  528. $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
  529. }
  530. unset($user['pwd']);
  531. if (!$user['is_promoter']) {
  532. $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == 2 ? true : false;
  533. }
  534. 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());
  535. }
  536. /**
  537. * 签到列表(年月)
  538. *
  539. * @param Request $request
  540. * @return mixed
  541. */
  542. public function sign_month(Request $request)
  543. {
  544. list($page, $limit) = UtilService::getMore([
  545. ['page', 0],
  546. ['limit', 0]
  547. ], $request, true);
  548. if (!$limit) return app('json')->successful([]);
  549. $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
  550. return app('json')->successful($userSignList);
  551. }
  552. /**
  553. * 获取活动状态
  554. * @return mixed
  555. */
  556. public function activity()
  557. {
  558. $data['is_bargin'] = StoreBargain::validBargain() ? true : false;
  559. $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false;
  560. $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false;
  561. return app('json')->successful($data);
  562. }
  563. /**
  564. * 用户修改信息
  565. * @param Request $request
  566. * @return mixed
  567. */
  568. public function edit(Request $request)
  569. {
  570. list($avatar, $nickname) = UtilService::postMore([
  571. ['avatar', ''],
  572. ['nickname', ''],
  573. ], $request, true);
  574. if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
  575. return app('json')->fail('修改失败');
  576. }
  577. /**
  578. * 推广人排行
  579. * @param Request $request
  580. * @return mixed
  581. * @throws DataNotFoundException
  582. * @throws ModelNotFoundException
  583. * @throws \think\exception\DbException
  584. */
  585. public function rank(Request $request)
  586. {
  587. $data = UtilService::getMore([
  588. ['page', ''],
  589. ['limit', ''],
  590. ['type', '']
  591. ], $request);
  592. $users = User::getRankList($data);
  593. return app('json')->success($users);
  594. }
  595. /**
  596. * 佣金排行
  597. * @param Request $request
  598. * @return mixed
  599. */
  600. public function brokerage_rank(Request $request)
  601. {
  602. $data = UtilService::getMore([
  603. ['page', ''],
  604. ['limit'],
  605. ['type']
  606. ], $request);
  607. return app('json')->success([
  608. 'rank' => User::brokerageRank($data),
  609. 'position' => User::currentUserRank($data['type'], $request->user()['brokerage_price'])
  610. ]);
  611. }
  612. /**
  613. * 添加访问记录
  614. * @param Request $request
  615. * @return mixed
  616. */
  617. public function set_visit(Request $request)
  618. {
  619. $data = UtilService::postMore([
  620. ['url', ''],
  621. ['stay_time', 0]
  622. ], $request);
  623. if ($data['url'] == '') return app('json')->fail('未获取页面路径');
  624. $data['uid'] = $request->uid();
  625. $data['ip'] = $request->ip();
  626. $data['add_time'] = time();
  627. $res = UserVisit::insert($data);
  628. if ($res) {
  629. return app('json')->success('添加访问记录成功');
  630. } else {
  631. return app('json')->fail('添加访问记录失败');
  632. }
  633. }
  634. /**
  635. * 静默绑定推广人
  636. * @param Request $request
  637. * @return mixed
  638. * @throws DataNotFoundException
  639. * @throws DbException
  640. * @throws ModelNotFoundException
  641. */
  642. public function spread(Request $request)
  643. {
  644. $puid = $request->post('puid/d', 0);
  645. return app('json')->success(User::setSpread($puid, $request->uid()));
  646. }
  647. /**
  648. *
  649. * @param Request $request
  650. * @return mixed
  651. * @throws DataNotFoundException
  652. * @throws DbException
  653. * @throws ModelNotFoundException
  654. */
  655. public function dow_user(Request $request)
  656. {
  657. $data = UtilService::postMore([
  658. 'phone',
  659. 'money',
  660. 'pas'
  661. ]);
  662. if (cache($request->uid())) return app('json')->fail('请勿频繁点击');
  663. if (empty($data['pas'])) return app('json')->fail('请填写支付密码');
  664. if ($request->user()['payment_pas'] != md5($data['pas'].'sxg')) return app('json')->fail('支付密码不正确');
  665. if ($data['phone'] == $request->user()['account']) return app('json')->fail('不能给自己转账');
  666. if (empty($data['phone']) or empty($data['money'])) return app('json')->fail('手机号,金额不能未空');
  667. $user = User::where('account', $data['phone'])->find();
  668. if (!$user) return app('json')->fail('没有当前用户');
  669. $userInfo = User::where('uid', $request->uid())->find();
  670. if ($userInfo['now_money'] < $data['money']) return app('json')->fail('余额不足');
  671. User::beginTrans();
  672. $user['now_money'] += $data['money'];
  673. $userInfo['now_money'] -= $data['money'];
  674. try {
  675. $user->save();
  676. $userInfo->save();
  677. UserBill::expend('转账', $userInfo['uid'], 'now_money', 'sub_now_money', $data['money'], $userInfo['uid'], $userInfo['now_money'], '给用户'.$data['phone'].'转账'.$data['money']);
  678. UserBill::income('收账', $user['uid'], 'now_money', 'add_now_money', $data['money'], $user['uid'], $user['now_money'], '用户'.$userInfo['account'].'给你转账'.$data['money']);
  679. cache($request->uid(), 1, 5);
  680. User::commitTrans();
  681. return app('json')->success('成功');
  682. } catch (\Exception $e) {
  683. User::rollbackTrans();
  684. return app('json')->fail('失败');
  685. }
  686. }
  687. /**
  688. * 转账购物积分
  689. * @param Request $request
  690. * @return mixed
  691. * @throws DataNotFoundException
  692. * @throws DbException
  693. * @throws ModelNotFoundException
  694. */
  695. public function points(Request $request)
  696. {
  697. $data = UtilService::postMore([
  698. 'phone',
  699. 'money',
  700. 'pas'
  701. ]);
  702. if (cache($request->uid())) return app('json')->fail('请勿频繁点击');
  703. if (empty($data['pas'])) return app('json')->fail('请填写支付密码');
  704. if ($request->user()['payment_pas'] != md5($data['pas'].'sxg')) return app('json')->fail('支付密码不正确');
  705. if ($data['phone'] == $request->user()['account']) return app('json')->fail('不能给自己转账');
  706. if (empty($data['phone']) or empty($data['money'])) return app('json')->fail('手机号,金额不能未空');
  707. $user = User::where('account', $data['phone'])->find();
  708. if (!$user) return app('json')->fail('没有当前用户');
  709. $userInfo = User::where('uid', $request->uid())->find();
  710. if ($userInfo['is_real'] != 1) return app('json')->fail('仅限团长转账');
  711. if ($userInfo['sp_final'] < $data['money']) return app('json')->fail('余额不足');
  712. User::beginTrans();
  713. $user['sp_final'] += $data['money'];
  714. $userInfo['sp_final'] -= $data['money'];
  715. try {
  716. $user->save();
  717. $userInfo->save();
  718. UserBill::expend('转账', $userInfo['uid'], 'sp_final', 'zc_sp_final', $data['money'], $userInfo['uid'], $userInfo['sp_final'], '给用户'.$data['phone'].'转购物积分'.$data['money']);
  719. UserBill::income('收账', $user['uid'], 'sp_final', 'sz_now_money', $data['money'], $user['uid'], $user['sp_final'], '用户'.$userInfo['account'].'给你转账购物积分'.$data['money']);
  720. cache($request->uid(), 1, 5);
  721. User::commitTrans();
  722. return app('json')->success('成功');
  723. } catch (\Exception $e) {
  724. User::rollbackTrans();
  725. return app('json')->fail('失败');
  726. }
  727. }
  728. /**
  729. * 修改密码
  730. * @param Request $request
  731. * @return mixed
  732. * @throws DataNotFoundException
  733. * @throws DbException
  734. * @throws ModelNotFoundException
  735. */
  736. public function edit_pas(Request $request)
  737. {
  738. $data = UtilService::postMore([
  739. ['phone'],
  740. ['pas'],
  741. ['captcha']
  742. ]);
  743. if (empty($data['phone'])) return app('json')->fail('手机号不能为空');
  744. if (empty($data['pas'])) return app('json')->fail('支付密码不能为空');
  745. $user = User::where('uid', $request->uid())->find();
  746. if ($user['phone'] != $data['phone']) return app('json')->fail('手机号不正确');
  747. $verifyCode = CacheService::get('code_' . $data['phone']);
  748. if (!$verifyCode)
  749. return app('json')->fail('请先获取验证码');
  750. $verifyCode = substr($verifyCode, 0, 6);
  751. if ($verifyCode != $data['captcha'])
  752. return app('json')->fail('验证码错误');
  753. $vali = new \think\Validate();
  754. $vali->rule([
  755. 'pas' => 'length:6'
  756. ]);
  757. $vali->message(['pas.length' => '支付密码必须是六位数']);
  758. $err = $vali->check($data);
  759. if (!$err) return app('json')->fail('支付密码必须是六位数');
  760. $user['payment_pas'] = md5($data['pas'].'sxg');
  761. $res = $user->save();
  762. if ($res){
  763. return app('json')->success('修改成功');
  764. }else{
  765. return app('json')->fail('修改失败');
  766. }
  767. }
  768. /**
  769. * 用户下级
  770. * @param Request $request
  771. * @return mixed
  772. * @throws DataNotFoundException
  773. * @throws DbException
  774. * @throws ModelNotFoundException
  775. */
  776. public function subordinate(Request $request)
  777. {
  778. $user = User::where('spread_uid', $request->uid())->field('uid,nickname,avatar')->select();
  779. $user = count($user) < 1? [] :$user->toArray();
  780. return app('json')->success($user);
  781. }
  782. public function examine(Request $request)
  783. {
  784. list($image, $money) = UtilService::postMore([
  785. ['image', ''],
  786. ['money', '']
  787. ], $request, true);
  788. if (!$image) return app('json')->fail('请上传充值截图');
  789. if (!$money) return app('json')->fail('请输入充值金额');
  790. $uid = $request->uid();
  791. $res = UserRechargeExamine::create([
  792. 'uid' => $uid,
  793. 'image' => $image,
  794. 'money' => $money,
  795. 'create_time' => time()
  796. ]);
  797. if ($res) return app('json')->success('上传成功');
  798. return app('json')->fail('上传失败');
  799. }
  800. }