UserController.php 29 KB

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