UserController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  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\UserPay;
  6. use app\models\user\UserVisit;
  7. use think\db\exception\DataNotFoundException;
  8. use think\db\exception\DbException;
  9. use think\db\exception\ModelNotFoundException;
  10. use think\exception\ValidateException;
  11. use app\Request;
  12. use app\models\user\UserLevel;
  13. use app\models\user\UserSign;
  14. use app\models\store\StoreBargain;
  15. use app\models\store\StoreCombination;
  16. use app\models\store\StoreCouponUser;
  17. use app\models\store\StoreOrder;
  18. use app\models\store\StoreProductRelation;
  19. use app\models\store\StoreSeckill;
  20. use app\models\user\User;
  21. use app\models\user\UserAddress;
  22. use app\models\user\UserBill;
  23. use app\models\user\UserExtract;
  24. use app\models\user\UserNotice;
  25. use crmeb\services\GroupDataService;
  26. use crmeb\services\UtilService;
  27. use think\facade\Db;
  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. User::upgrade($info['uid']);
  57. UserLevel::setLevelComplete($request->uid());
  58. $info['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  59. if ($info['broken_commission'] < 0)
  60. $info['broken_commission'] = 0;
  61. $info['commissionCount'] = bcsub($info['brokerage_price'], $info['broken_commission'], 2);
  62. if ($info['commissionCount'] < 0)
  63. $info['commissionCount'] = 0;
  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. User::upgrade($user['uid']);
  160. UserLevel::setLevelComplete($request->uid());
  161. return app('json')->successful($user);
  162. }
  163. /**
  164. * 地址 获取单个
  165. * @param Request $request
  166. * @param $id
  167. * @return mixed
  168. * @throws DataNotFoundException
  169. * @throws ModelNotFoundException
  170. * @throws \think\exception\DbException
  171. */
  172. public function address(Request $request, $id)
  173. {
  174. $addressInfo = [];
  175. if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
  176. $addressInfo = UserAddress::find($id)->toArray();
  177. }
  178. return app('json')->successful($addressInfo);
  179. }
  180. /**
  181. * 地址列表
  182. * @param Request $request
  183. * @param $page
  184. * @param $limit
  185. * @return mixed
  186. */
  187. public function address_list(Request $request)
  188. {
  189. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true);
  190. $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default');
  191. return app('json')->successful($list);
  192. }
  193. /**
  194. * 设置默认地址
  195. *
  196. * @param Request $request
  197. * @return mixed
  198. */
  199. public function address_default_set(Request $request)
  200. {
  201. list($id) = UtilService::getMore([['id', 0]], $request, true);
  202. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  203. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  204. return app('json')->fail('地址不存在!');
  205. $res = UserAddress::setDefaultAddress($id, $request->uid());
  206. if (!$res)
  207. return app('json')->fail('地址不存在!');
  208. else
  209. return app('json')->successful();
  210. }
  211. /**
  212. * 获取默认地址
  213. * @param Request $request
  214. * @return mixed
  215. */
  216. public function address_default(Request $request)
  217. {
  218. $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default');
  219. if ($defaultAddress) {
  220. $defaultAddress = $defaultAddress->toArray();
  221. return app('json')->successful('ok', $defaultAddress);
  222. }
  223. return app('json')->successful('empty', []);
  224. }
  225. /**
  226. * 修改 添加地址
  227. * @param Request $request
  228. * @return mixed
  229. */
  230. public function address_edit(Request $request)
  231. {
  232. $addressInfo = UtilService::postMore([
  233. ['address', []],
  234. ['is_default', false],
  235. ['real_name', ''],
  236. ['post_code', ''],
  237. ['phone', ''],
  238. ['detail', ''],
  239. ['id', 0],
  240. ['type', 0]
  241. ], $request);
  242. if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!');
  243. if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!');
  244. if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!');
  245. if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) {
  246. return app('json')->fail('收货地址格式错误!请重新选择!');
  247. } else if ($addressInfo['type'] == 1) {
  248. $city = $addressInfo['address']['city'];
  249. $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id');
  250. if ($cityId) {
  251. $addressInfo['address']['city_id'] = $cityId;
  252. } else {
  253. if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) {
  254. return app('json')->fail('收货地址格式错误!修改后请重新导入!');
  255. }
  256. $addressInfo['address']['city_id'] = $cityId;
  257. }
  258. }
  259. $addressInfo['province'] = $addressInfo['address']['province'];
  260. $addressInfo['city'] = $addressInfo['address']['city'];
  261. $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
  262. $addressInfo['district'] = $addressInfo['address']['district'];
  263. $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
  264. $addressInfo['uid'] = $request->uid();
  265. unset($addressInfo['address'], $addressInfo['type']);
  266. try {
  267. validate(AddressValidate::class)->check($addressInfo);
  268. } catch (ValidateException $e) {
  269. return app('json')->fail($e->getError());
  270. }
  271. if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
  272. $id = $addressInfo['id'];
  273. unset($addressInfo['id']);
  274. if (UserAddress::edit($addressInfo, $id, 'id')) {
  275. if ($addressInfo['is_default'])
  276. UserAddress::setDefaultAddress($id, $request->uid());
  277. return app('json')->successful();
  278. } else
  279. return app('json')->fail('编辑收货地址失败!');
  280. } else {
  281. $addressInfo['add_time'] = time();
  282. if ($address = UserAddress::create($addressInfo)) {
  283. if ($addressInfo['is_default']) {
  284. UserAddress::setDefaultAddress($address->id, $request->uid());
  285. }
  286. return app('json')->successful(['id' => $address->id]);
  287. } else {
  288. return app('json')->fail('添加收货地址失败!');
  289. }
  290. }
  291. }
  292. /**
  293. * 删除地址
  294. *
  295. * @param Request $request
  296. * @return mixed
  297. */
  298. public function address_del(Request $request)
  299. {
  300. list($id) = UtilService::postMore([['id', 0]], $request, true);
  301. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  302. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  303. return app('json')->fail('地址不存在!');
  304. if (UserAddress::edit(['is_del' => '1'], $id, 'id'))
  305. return app('json')->successful();
  306. else
  307. return app('json')->fail('删除地址失败!');
  308. }
  309. /**
  310. * 获取收藏产品
  311. *
  312. * @param Request $request
  313. * @return mixed
  314. */
  315. public function collect_user(Request $request)
  316. {
  317. list($page, $limit) = UtilService::getMore([
  318. ['page', 0],
  319. ['limit', 0]
  320. ], $request, true);
  321. if (!(int)$limit) return app('json')->successful([]);
  322. $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit);
  323. return app('json')->successful($productRelationList);
  324. }
  325. /**
  326. * 添加收藏
  327. * @param Request $request
  328. * @param $id
  329. * @param $category
  330. * @return mixed
  331. */
  332. public function collect_add(Request $request)
  333. {
  334. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  335. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  336. $res = StoreProductRelation::productRelation($id, $request->uid(), 'collect', $category);
  337. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  338. else return app('json')->successful();
  339. }
  340. /**
  341. * 取消收藏
  342. *
  343. * @param Request $request
  344. * @return mixed
  345. */
  346. public function collect_del(Request $request)
  347. {
  348. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  349. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  350. $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category);
  351. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  352. else return app('json')->successful();
  353. }
  354. /**
  355. * 批量收藏
  356. * @param Request $request
  357. * @return mixed
  358. */
  359. public function collect_all(Request $request)
  360. {
  361. $collectInfo = UtilService::postMore([
  362. ['id', []],
  363. ['category', 'product'],
  364. ], $request);
  365. if (!count($collectInfo['id'])) return app('json')->fail('参数错误');
  366. $productIdS = $collectInfo['id'];
  367. $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['category']);
  368. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  369. else return app('json')->successful('收藏成功');
  370. }
  371. /**
  372. * 添加点赞
  373. *
  374. * @param Request $request
  375. * @return mixed
  376. */
  377. // public function like_add(Request $request)
  378. // {
  379. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  380. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  381. // $res = StoreProductRelation::productRelation($id,$request->uid(),'like',$category);
  382. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  383. // else return app('json')->successful();
  384. // }
  385. /**
  386. * 取消点赞
  387. *
  388. * @param Request $request
  389. * @return mixed
  390. */
  391. // public function like_del(Request $request)
  392. // {
  393. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  394. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  395. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  396. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  397. // else return app('json')->successful();
  398. // }
  399. /**
  400. * 签到 配置
  401. * @return mixed
  402. * @throws DataNotFoundException
  403. * @throws ModelNotFoundException
  404. * @throws \think\exception\DbException
  405. */
  406. public function sign_config()
  407. {
  408. $signConfig = sys_data('sign_day_num') ?? [];
  409. return app('json')->successful($signConfig);
  410. }
  411. /**
  412. * 签到 列表
  413. * @param Request $request
  414. * @param $page
  415. * @param $limit
  416. * @return mixed
  417. */
  418. public function sign_list(Request $request)
  419. {
  420. list($page, $limit) = UtilService::getMore([
  421. ['page', 0],
  422. ['limit', 0]
  423. ], $request, true);
  424. if (!$limit) return app('json')->successful([]);
  425. $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit);
  426. if ($signList) $signList = $signList->toArray();
  427. return app('json')->successful($signList);
  428. }
  429. /**
  430. * 签到
  431. * @param Request $request
  432. * @return mixed
  433. */
  434. public function sign_integral(Request $request)
  435. {
  436. $signed = UserSign::getIsSign($request->uid());
  437. if ($signed) return app('json')->fail('已签到');
  438. if (false !== ($integral = UserSign::sign($request->uid())))
  439. return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]);
  440. return app('json')->fail(UserSign::getErrorInfo('签到失败'));
  441. }
  442. /**
  443. * 签到用户信息
  444. * @param Request $request
  445. * @return mixed
  446. */
  447. public function sign_user(Request $request)
  448. {
  449. list($sign, $integral, $all) = UtilService::postMore([
  450. ['sign', 0],
  451. ['integral', 0],
  452. ['all', 0],
  453. ], $request, true);
  454. $user = $request->user();
  455. //是否统计签到
  456. if ($sign || $all) {
  457. $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']);
  458. $user['is_day_sgin'] = UserSign::getIsSign($user['uid']);
  459. $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday');
  460. if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) {
  461. $user['sign_num'] = 0;
  462. }
  463. }
  464. //是否统计积分使用情况
  465. if ($integral || $all) {
  466. $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain');
  467. $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
  468. $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
  469. }
  470. unset($user['pwd']);
  471. if (!$user['is_promoter']) {
  472. $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == 2 ? true : false;
  473. }
  474. 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());
  475. }
  476. /**
  477. * 签到列表(年月)
  478. *
  479. * @param Request $request
  480. * @return mixed
  481. */
  482. public function sign_month(Request $request)
  483. {
  484. list($page, $limit) = UtilService::getMore([
  485. ['page', 0],
  486. ['limit', 0]
  487. ], $request, true);
  488. if (!$limit) return app('json')->successful([]);
  489. $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
  490. return app('json')->successful($userSignList);
  491. }
  492. /**
  493. * 获取活动状态
  494. * @return mixed
  495. */
  496. public function activity()
  497. {
  498. $data['is_bargin'] = StoreBargain::validBargain() ? true : false;
  499. $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false;
  500. $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false;
  501. return app('json')->successful($data);
  502. }
  503. /**
  504. * 用户修改信息
  505. * @param Request $request
  506. * @return mixed
  507. */
  508. public function edit(Request $request)
  509. {
  510. list($avatar, $nickname) = UtilService::postMore([
  511. ['avatar', ''],
  512. ['nickname', ''],
  513. ], $request, true);
  514. if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
  515. return app('json')->fail('修改失败');
  516. }
  517. /**
  518. * 推广人排行
  519. * @param Request $request
  520. * @return mixed
  521. * @throws DataNotFoundException
  522. * @throws ModelNotFoundException
  523. * @throws \think\exception\DbException
  524. */
  525. public function rank(Request $request)
  526. {
  527. $data = UtilService::getMore([
  528. ['page', ''],
  529. ['limit', ''],
  530. ['type', '']
  531. ], $request);
  532. $users = User::getRankList($data);
  533. return app('json')->success($users);
  534. }
  535. /**
  536. * 佣金排行
  537. * @param Request $request
  538. * @return mixed
  539. */
  540. public function brokerage_rank(Request $request)
  541. {
  542. $data = UtilService::getMore([
  543. ['page', ''],
  544. ['limit'],
  545. ['type']
  546. ], $request);
  547. return app('json')->success([
  548. 'rank' => User::brokerageRank($data),
  549. 'position' => User::currentUserRank($data['type'], $request->user()['brokerage_price'])
  550. ]);
  551. }
  552. /**
  553. * 添加访问记录
  554. * @param Request $request
  555. * @return mixed
  556. */
  557. public function set_visit(Request $request)
  558. {
  559. $data = UtilService::postMore([
  560. ['url', ''],
  561. ['stay_time', 0]
  562. ], $request);
  563. if ($data['url'] == '') return app('json')->fail('未获取页面路径');
  564. $data['uid'] = $request->uid();
  565. $data['ip'] = $request->ip();
  566. $data['add_time'] = time();
  567. $res = UserVisit::insert($data);
  568. if ($res) {
  569. return app('json')->success('添加访问记录成功');
  570. } else {
  571. return app('json')->fail('添加访问记录失败');
  572. }
  573. }
  574. /**
  575. * 静默绑定推广人
  576. * @param Request $request
  577. * @return mixed
  578. * @throws DataNotFoundException
  579. * @throws DbException
  580. * @throws ModelNotFoundException
  581. */
  582. public function spread(Request $request)
  583. {
  584. $puid = $request->post('puid/d', 0);
  585. return app('json')->success(User::setSpread($puid, $request->uid()));
  586. }
  587. /**
  588. * 添加收款方式
  589. * @param Request $request
  590. * @return void
  591. */
  592. public function pay(Request $request)
  593. {
  594. $data = UtilService::postMore([
  595. ['payment'],
  596. ['image'],
  597. ['bank'],
  598. ['name'],
  599. ['type'],
  600. ['phone'],
  601. ['bank_name']
  602. ], $request);
  603. if (!$data['type']) return app('json')->fail('数据传入错误');
  604. $data['uid'] =$request->uid();
  605. $model = new UserPay();
  606. $pay = $model->where([['uid', '=', $request->uid()], ['type', '=', $data['type']]])->find();
  607. $res = Validate::rule([
  608. 'phone' => 'mobile'
  609. ]);
  610. $res->message([
  611. 'phone.mobile' => '请填写正确手机格式'
  612. ]);
  613. if (!$res->check($data)){
  614. return app('json')->fail($res->getError());
  615. }
  616. if (!empty($pay)){
  617. if ($data['type'] == 1 ){
  618. // 微信收款方式
  619. if (!$data['payment']) return app('json')->fail('微信账号不能为空');
  620. if (!$data['image']) return app('json')->fail('二维码不能为空');
  621. if (!$data['name']) return app('json')->fail('姓名不能为空');
  622. $pay['payment'] = $data['payment'];
  623. $pay['image'] = $data['image'];
  624. $pay['name'] = $data['name'];
  625. $pay['phone'] = $data['phone'];
  626. }elseif ($data['type'] == 2){
  627. // 支付宝收款方式
  628. if (!$data['payment']) return app('json')->fail('支付宝账号不能为空');
  629. if (!$data['name']) return app('json')->fail('姓名不能为空');
  630. $pay['payment'] = $data['payment'];
  631. $pay['name'] = $data['name'];
  632. $pay['phone'] = $data['phone'];
  633. }elseif ($data['type'] == 3){
  634. // 银行卡收款方式
  635. if (!$data['payment']) return app('json')->fail('银行卡号不能为空');
  636. if (!$data['name']) return app('json')->fail('姓名不能为空');
  637. if (!$data['bank']) return app('json')->fail('开户行不能为空');
  638. if (!$data['bank_name']) return app('json')->fail('开户支行不能为空');
  639. if (!$data['phone']) return app('json')->fail('请填写手机号');
  640. $pay['payment'] = $data['payment'];
  641. $pay['bank'] = $data['bank'];
  642. $pay['bank_name'] = $data['bank_name'];
  643. $pay['phone'] = $data['phone'];
  644. $pay['name'] = $data['name'];
  645. }
  646. $res = $pay->save();
  647. if ($res) return app('json')->successful('修改成功');
  648. return app('json')->fail('修改失败');
  649. }else{
  650. if ($data['type'] == 1 ){
  651. // 微信收款方式
  652. if (!$data['payment']) return app('json')->fail('微信账号不能为空');
  653. if (!$data['image']) return app('json')->fail('二维码不能为空');
  654. if (!$data['name']) return app('json')->fail('姓名不能为空');
  655. if (!$data['phone']) return app('json')->fail('请填写手机号');
  656. }elseif ($data['type'] == 2){
  657. // 支付宝收款方式
  658. if (!$data['payment']) return app('json')->fail('支付宝账号不能为空');
  659. if (!$data['name']) return app('json')->fail('姓名不能为空');
  660. if (!$data['phone']) return app('json')->fail('请填写手机号');
  661. }elseif ($data['type'] == 3){
  662. // 银行卡收款方式
  663. if (!$data['payment']) return app('json')->fail('银行卡号不能为空');
  664. if (!$data['name']) return app('json')->fail('姓名不能为空');
  665. if (!$data['bank']) return app('json')->fail('开户行不能为空');
  666. if (!$data['bank_name']) return app('json')->fail('开户支行不能为空');
  667. if (!$data['phone']) return app('json')->fail('请填写手机号');
  668. }
  669. $res = $model->save($data);
  670. if ($res) return app('json')->successful('添加成功');
  671. return app('json')->fail('添加失败');
  672. }
  673. }
  674. /**
  675. * 收款方式详情
  676. * @param Request $request
  677. * @return mixed
  678. * @throws \think\db\exception\DataNotFoundException
  679. * @throws \think\db\exception\DbException
  680. * @throws \think\db\exception\ModelNotFoundException
  681. */
  682. public function pay_list(Request $request)
  683. {
  684. $model = new UserPay();
  685. $list = $model->where('uid', $request->uid())->select();
  686. $list = empty($list)? []: $list->toArray();
  687. $data['wx'] = [];
  688. $data['zfb'] = [];
  689. $data['bank'] = [];
  690. foreach ($list as $k => $v){
  691. if ($v['type'] == 1){
  692. $data['wx'] = $v;
  693. }elseif ($v['type'] == 2){
  694. $data['zfb'] = $v;
  695. }elseif ($v['type'] == 3){
  696. $data['bank'] = $v;
  697. }
  698. }
  699. return app('json')->successful($data);
  700. }
  701. /**
  702. * 定时分红
  703. * @return void
  704. */
  705. public function bonus()
  706. {
  707. // if (date('d', time()) == 1){
  708. try {
  709. Db::startTrans();
  710. User::bonus();
  711. User::creation();
  712. Db::commit();
  713. } catch (\Exception $e) {
  714. Db::rollback();
  715. }
  716. // }
  717. }
  718. }