UserController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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;
  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. /**
  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', '', $request->mer_id()));
  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. return app('json')->success($info);
  61. }
  62. /**
  63. * 用户资金统计
  64. * @param Request $request
  65. * @return mixed
  66. * @throws Exception
  67. * @throws DataNotFoundException
  68. * @throws ModelNotFoundException
  69. * @throws DbException
  70. */
  71. public function balance(Request $request)
  72. {
  73. $uid = $request->uid();
  74. $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money'];//当前总资金
  75. $user['recharge'] = UserBill::getRecharge($uid);//累计充值
  76. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid);//累计消费
  77. return app('json')->successful($user);
  78. }
  79. /**
  80. * 个人中心
  81. * @param Request $request
  82. * @return mixed
  83. * @throws DataNotFoundException
  84. * @throws DbException
  85. * @throws ModelNotFoundException
  86. */
  87. public function user(Request $request)
  88. {
  89. $user = $request->user()->toArray();
  90. $user['couponCount'] = StoreCouponUser::getUserValidCouponCount($user['uid']);
  91. $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
  92. $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid'], $request->mer_id());
  93. $user['notice'] = UserNotice::getNotice($user['uid']);
  94. // $user['brokerage'] = UserBill::getBrokerage($user['uid']);//获取总佣金
  95. $user['recharge'] = UserBill::getRecharge($user['uid']);//累计充值
  96. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']);//累计消费
  97. $user['extractTotalPrice'] = UserExtract::userExtractTotalPrice($user['uid']);//累计提现
  98. $user['extractPrice'] = $user['brokerage_price'];//可提现
  99. $user['statu'] = (int)sys_config('store_brokerage_statu', '', $request->mer_id());
  100. $broken_time = intval(sys_config('extract_time', '', $request->mer_id()));
  101. $search_time = time() - 86400 * $broken_time;
  102. if (!$user['is_promoter'] && $user['statu'] == 2) {
  103. $price = StoreOrder::merSet($request->mer_id())->where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price');
  104. $status = is_brokerage_statu($price, $request->mer_id());
  105. if ($status) {
  106. User::where('uid', $user['uid'])->update(['is_promoter' => 1]);
  107. $user['is_promoter'] = 1;
  108. } else {
  109. $storeBrokeragePrice = sys_config('store_brokerage_price', 0, $request->mer_id());
  110. $user['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
  111. }
  112. }
  113. //可提现佣金
  114. //返佣 +
  115. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  116. ->where('add_time', '>', $search_time)
  117. ->where('pm', 1)
  118. ->sum('number');
  119. //退款退的佣金 -
  120. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  121. ->where('add_time', '>', $search_time)
  122. ->where('pm', 0)
  123. ->sum('number');
  124. $user['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  125. if ($user['broken_commission'] < 0)
  126. $user['broken_commission'] = 0;
  127. $user['commissionCount'] = bcsub($user['brokerage_price'], $user['broken_commission'], 2);
  128. if ($user['commissionCount'] < 0)
  129. $user['commissionCount'] = 0;
  130. if (!sys_config('vip_open'))
  131. $user['vip'] = false;
  132. else {
  133. $vipId = UserLevel::getUserLevel($user['uid']);
  134. $user['vip'] = $vipId !== false ? true : false;
  135. if ($user['vip']) {
  136. $user['vip_id'] = $vipId;
  137. $user['vip_icon'] = UserLevel::getUserLevelInfo($vipId, 'icon');
  138. $user['vip_name'] = UserLevel::getUserLevelInfo($vipId, 'name');
  139. }
  140. }
  141. $user['yesterDay'] = UserBill::yesterdayCommissionSum($user['uid']);
  142. $user['recharge_switch'] = (int)sys_config('recharge_switch', '', $request->mer_id());//充值开关
  143. $user['adminid'] = (boolean)\app\models\store\StoreService::orderServiceStatus($user['uid']);
  144. if ($user['phone'] && $user['user_type'] != 'h5') {
  145. $user['switchUserInfo'][] = $request->user();
  146. if ($h5UserInfo = User::merSet($request->mer_id())->where('account', $user['phone'])->where('user_type', 'h5')->find()) {
  147. $user['switchUserInfo'][] = $h5UserInfo;
  148. }
  149. } else if ($user['phone'] && $user['user_type'] == 'h5') {
  150. if ($wechatUserInfo = User::merSet($request->mer_id())->where('phone', $user['phone'])->where('user_type', '<>', 'h5')->find()) {
  151. $user['switchUserInfo'][] = $wechatUserInfo;
  152. }
  153. $user['switchUserInfo'][] = $request->user();
  154. } else if (!$user['phone']) {
  155. $user['switchUserInfo'][] = $request->user();
  156. }
  157. $user['broken_day'] = (int)sys_config('extract_time', '', $request->mer_id());//佣金冻结时间
  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 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. * @throws \Exception
  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. * @throws \Exception
  197. */
  198. public function address_default_set(Request $request)
  199. {
  200. list($id) = UtilService::getMore([['id', 0]], $request, true);
  201. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  202. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  203. return app('json')->fail('地址不存在!');
  204. $res = UserAddress::setDefaultAddress($id, $request->uid());
  205. if (!$res)
  206. return app('json')->fail('地址不存在!');
  207. else
  208. return app('json')->successful();
  209. }
  210. /**
  211. * 获取默认地址
  212. * @param Request $request
  213. * @return mixed
  214. */
  215. public function address_default(Request $request)
  216. {
  217. $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default');
  218. if ($defaultAddress) {
  219. $defaultAddress = $defaultAddress->toArray();
  220. return app('json')->successful('ok', $defaultAddress);
  221. }
  222. return app('json')->successful('empty', []);
  223. }
  224. /**
  225. * 修改 添加地址
  226. * @param Request $request
  227. * @return mixed
  228. * @throws \Exception
  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', 'd'], 0],
  240. [['type', 'd'], 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. }
  257. }
  258. $addressInfo['province'] = $addressInfo['address']['province'];
  259. $addressInfo['city'] = $addressInfo['address']['city'];
  260. $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
  261. $addressInfo['district'] = $addressInfo['address']['district'];
  262. $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
  263. $addressInfo['uid'] = $request->uid();
  264. unset($addressInfo['address'], $addressInfo['type']);
  265. try {
  266. validate(AddressValidate::class)->check($addressInfo);
  267. } catch (ValidateException $e) {
  268. return app('json')->fail($e->getError());
  269. }
  270. if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
  271. $id = $addressInfo['id'];
  272. unset($addressInfo['id']);
  273. if (UserAddress::edit($addressInfo, $id, 'id')) {
  274. if ($addressInfo['is_default'])
  275. UserAddress::setDefaultAddress($id, $request->uid());
  276. return app('json')->successful();
  277. } else
  278. return app('json')->fail('编辑收货地址失败!');
  279. } else {
  280. $addressInfo['add_time'] = time();
  281. if ($address = UserAddress::create($addressInfo)) {
  282. if ($addressInfo['is_default']) {
  283. UserAddress::setDefaultAddress($address->id, $request->uid());
  284. }
  285. return app('json')->successful(['id' => $address->id]);
  286. } else {
  287. return app('json')->fail('添加收货地址失败!');
  288. }
  289. }
  290. }
  291. /**
  292. * 删除地址
  293. *
  294. * @param Request $request
  295. * @return mixed
  296. * @throws \Exception
  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. * @throws \Exception
  315. */
  316. public function collect_user(Request $request)
  317. {
  318. list($page, $limit) = UtilService::getMore([
  319. ['page', 0],
  320. ['limit', 0]
  321. ], $request, true);
  322. if (!(int)$limit) return app('json')->successful([]);
  323. $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit, $request->mer_id());
  324. return app('json')->successful($productRelationList);
  325. }
  326. /**
  327. * 添加收藏
  328. * @param Request $request
  329. * @param $id
  330. * @param $category
  331. * @return mixed
  332. * @throws \Exception
  333. */
  334. public function collect_add(Request $request)
  335. {
  336. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  337. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  338. $res = StoreProductRelation::productRelation($id, $request->uid(), 'collect', $category);
  339. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  340. else return app('json')->successful();
  341. }
  342. /**
  343. * 取消收藏
  344. *
  345. * @param Request $request
  346. * @return mixed
  347. * @throws \Exception
  348. */
  349. public function collect_del(Request $request)
  350. {
  351. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  352. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  353. $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category);
  354. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  355. else return app('json')->successful();
  356. }
  357. /**
  358. * 批量收藏
  359. * @param Request $request
  360. * @return mixed
  361. * @throws \Exception
  362. */
  363. public function collect_all(Request $request)
  364. {
  365. $collectInfo = UtilService::postMore([
  366. ['id', []],
  367. ['category', 'product'],
  368. ], $request);
  369. if (!count($collectInfo['id'])) return app('json')->fail('参数错误');
  370. $productIdS = $collectInfo['id'];
  371. $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['category']);
  372. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  373. else return app('json')->successful('收藏成功');
  374. }
  375. /**
  376. * 添加点赞
  377. *
  378. * @param Request $request
  379. * @return mixed
  380. */
  381. // public function like_add(Request $request)
  382. // {
  383. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  384. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  385. // $res = StoreProductRelation::productRelation($id,$request->uid(),'like',$category);
  386. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  387. // else return app('json')->successful();
  388. // }
  389. /**
  390. * 取消点赞
  391. *
  392. * @param Request $request
  393. * @return mixed
  394. */
  395. // public function like_del(Request $request)
  396. // {
  397. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  398. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  399. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  400. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  401. // else return app('json')->successful();
  402. // }
  403. /**
  404. * 签到 配置
  405. * @return mixed
  406. * @throws DataNotFoundException
  407. * @throws ModelNotFoundException
  408. * @throws \think\exception\DbException
  409. */
  410. public function sign_config(Request $request)
  411. {
  412. $signConfig = sys_data('sign_day_num', 0, $request->mer_id()) ?? [];
  413. return app('json')->successful($signConfig);
  414. }
  415. /**
  416. * 签到 列表
  417. * @param Request $request
  418. * @param $page
  419. * @param $limit
  420. * @return mixed
  421. * @throws \Exception
  422. */
  423. public function sign_list(Request $request)
  424. {
  425. list($page, $limit) = UtilService::getMore([
  426. ['page', 0],
  427. ['limit', 0]
  428. ], $request, true);
  429. if (!$limit) return app('json')->successful([]);
  430. $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit);
  431. if ($signList) $signList = $signList->toArray();
  432. return app('json')->successful($signList);
  433. }
  434. /**
  435. * 签到
  436. * @param Request $request
  437. * @return mixed
  438. */
  439. public function sign_integral(Request $request)
  440. {
  441. $signed = UserSign::getIsSign($request->uid());
  442. if ($signed) return app('json')->fail('已签到');
  443. if (false !== ($integral = UserSign::sign($request->uid(), $request->mer_id())))
  444. return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]);
  445. return app('json')->fail(UserSign::getErrorInfo('签到失败'));
  446. }
  447. /**
  448. * 签到用户信息
  449. * @param Request $request
  450. * @return mixed
  451. * @throws \Exception
  452. */
  453. public function sign_user(Request $request)
  454. {
  455. list($sign, $integral, $all) = UtilService::postMore([
  456. ['sign', 0],
  457. ['integral', 0],
  458. ['all', 0],
  459. ], $request, true);
  460. $user = $request->user();
  461. //是否统计签到
  462. if ($sign || $all) {
  463. $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']);
  464. $user['is_day_sgin'] = UserSign::getIsSign($user['uid']);
  465. $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday');
  466. if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) {
  467. $user['sign_num'] = 0;
  468. }
  469. }
  470. //是否统计积分使用情况
  471. if ($integral || $all) {
  472. $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain');
  473. $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
  474. $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
  475. }
  476. unset($user['pwd']);
  477. if (!$user['is_promoter']) {
  478. $user['is_promoter'] = (int)sys_config('store_brokerage_statu', '', $request->mer_id()) == 2 ? true : false;
  479. }
  480. 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());
  481. }
  482. /**
  483. * 签到列表(年月)
  484. *
  485. * @param Request $request
  486. * @return mixed
  487. */
  488. public function sign_month(Request $request)
  489. {
  490. list($page, $limit) = UtilService::getMore([
  491. ['page', 0],
  492. ['limit', 0]
  493. ], $request, true);
  494. if (!$limit) return app('json')->successful([]);
  495. $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
  496. return app('json')->successful($userSignList);
  497. }
  498. /**
  499. * 获取活动状态
  500. * @return mixed
  501. */
  502. public function activity(Request $request)
  503. {
  504. $mer_id = $request->mer_id();
  505. $data['is_bargin'] = StoreBargain::validBargain(0, $mer_id) ? true : false;
  506. $data['is_pink'] = StoreCombination::getPinkIsOpen($mer_id) ? true : false;
  507. $data['is_seckill'] = StoreSeckill::getSeckillCount($mer_id) ? true : false;
  508. return app('json')->successful($data);
  509. }
  510. /**
  511. * 用户修改信息
  512. * @param Request $request
  513. * @return mixed
  514. * @throws \Exception
  515. */
  516. public function edit(Request $request)
  517. {
  518. list($avatar, $nickname) = UtilService::postMore([
  519. ['avatar', ''],
  520. ['nickname', ''],
  521. ], $request, true);
  522. if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
  523. return app('json')->fail('修改失败');
  524. }
  525. /**
  526. * 推广人排行
  527. * @param Request $request
  528. * @return mixed
  529. * @throws \Exception
  530. */
  531. public function rank(Request $request)
  532. {
  533. $data = UtilService::getMore([
  534. ['page', ''],
  535. ['limit', ''],
  536. ['type', '']
  537. ], $request);
  538. $users = User::getRankList($data, $request->mer_id());
  539. return app('json')->success($users);
  540. }
  541. /**
  542. * 佣金排行
  543. * @param Request $request
  544. * @return mixed
  545. * @throws \Exception
  546. */
  547. public function brokerage_rank(Request $request)
  548. {
  549. $data = UtilService::getMore([
  550. ['page', ''],
  551. ['limit'],
  552. ['type']
  553. ], $request);
  554. $users = User::brokerageRank($data, $request->mer_id());
  555. foreach ($users as $key => $item) {
  556. if ($item['brokerage_price'] == '0.00' || $item['brokerage_price'] == 0 || !$item['brokerage_price']) {
  557. unset($users[$key]);
  558. }
  559. }
  560. $position_tmp = User::brokerageRank(['type' => $data['type'], 'page' => 0, 'limit' => 99999], $request->mer_id());
  561. $position_tmp_one = array_column($position_tmp, 'uid');
  562. $position_tmp_two = array_column($position_tmp, 'brokerage_price', 'uid');
  563. if (!in_array($request->uid(), $position_tmp_one)) {
  564. $position = 0;
  565. } else {
  566. if ($position_tmp_two[$request->uid()] == 0.00) {
  567. $position = 0;
  568. } else {
  569. $position = array_search($request->uid(), $position_tmp_one) + 1;
  570. }
  571. }
  572. return app('json')->success([
  573. 'rank' => $users,
  574. 'position' => $position
  575. ]);
  576. }
  577. /**
  578. * 添加访问记录
  579. * @param Request $request
  580. * @return mixed
  581. * @throws \Exception
  582. */
  583. public function set_visit(Request $request)
  584. {
  585. $data = UtilService::postMore([
  586. ['url', ''],
  587. ['stay_time', 0]
  588. ], $request);
  589. if ($data['url'] == '') return app('json')->fail('未获取页面路径');
  590. $data['uid'] = $request->uid();
  591. $data['ip'] = $request->ip();
  592. $data['add_time'] = time();
  593. $res = UserVisit::insert($data);
  594. if ($res) {
  595. return app('json')->success('添加访问记录成功');
  596. } else {
  597. return app('json')->fail('添加访问记录失败');
  598. }
  599. }
  600. /**
  601. * 静默绑定推广人
  602. * @param Request $request
  603. * @return mixed
  604. */
  605. public function spread(Request $request)
  606. {
  607. $puid = $request->post('puid/d', 0);
  608. if ($puid) {
  609. $userInfo = $request->user();
  610. $spreadUid = User::where('uid', $puid)->value('spread_uid');
  611. if (!$userInfo['spread_uid'] && $puid != $request->uid() && $spreadUid != $userInfo['uid']) {
  612. User::where('uid', $request->uid())->update(['spread_uid' => $puid, 'spread_time' => time()]);
  613. }
  614. }
  615. return app('json')->success();
  616. }
  617. }