UserController.php 29 KB

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