UserController.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. <<<<<<< HEAD
  2. <?php
  3. namespace app\api\controller\user;
  4. use app\http\validates\user\AddressValidate;
  5. use app\models\system\SystemCity;
  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. /**
  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. $uids = User::where('spread_uid', $request->uid())->column('uid');
  61. $info['pay_price'] = StoreOrder::where('uid', 'in', $uids)
  62. ->where('paid', 1)
  63. ->where('is_participate', 0)
  64. ->sum('pay_price');
  65. return app('json')->success($info);
  66. }
  67. /**
  68. * 用户资金统计
  69. * @param Request $request
  70. * @return mixed
  71. * @throws \think\Exception
  72. * @throws DataNotFoundException
  73. * @throws ModelNotFoundException
  74. * @throws \think\exception\DbException
  75. */
  76. public function balance(Request $request)
  77. {
  78. $uid = $request->uid();
  79. $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money'];//当前总资金
  80. $user['recharge'] = UserBill::getRecharge($uid);//累计充值
  81. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid);//累计消费
  82. return app('json')->successful($user);
  83. }
  84. /**
  85. * 个人中心
  86. * @param Request $request
  87. * @return mixed
  88. */
  89. public function user(Request $request)
  90. {
  91. $user = $request->user();
  92. $user = $user->toArray();
  93. $user['couponCount'] = StoreCouponUser::getUserValidCouponCount($user['uid']);
  94. $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
  95. $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']);
  96. $user['notice'] = UserNotice::getNotice($user['uid']);
  97. $user['brokerage'] = UserBill::getBrokerage($user['uid']);//获取总佣金
  98. $user['recharge'] = UserBill::getRecharge($user['uid']);//累计充值
  99. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']);//累计消费
  100. $user['extractTotalPrice'] = UserExtract::userExtractTotalPrice($user['uid']);//累计提现
  101. $user['extractPrice'] = $user['brokerage_price'];//可提现
  102. $user['statu'] = (int)sys_config('store_brokerage_statu');
  103. $broken_time = intval(sys_config('extract_time'));
  104. $search_time = time() - 86400 * $broken_time;
  105. if (!$user['is_promoter'] && $user['statu'] == 2) {
  106. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price');
  107. $status = is_brokerage_statu($price);
  108. if ($status) {
  109. User::where('uid', $user['uid'])->update(['is_promoter' => 1]);
  110. $user['is_promoter'] = 1;
  111. } else {
  112. $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
  113. $user['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
  114. }
  115. }
  116. //可提现佣金
  117. //返佣 +
  118. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  119. ->where('add_time', '>', $search_time)
  120. ->where('pm', 1)
  121. ->sum('number');
  122. //退款退的佣金 -
  123. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  124. ->where('add_time', '>', $search_time)
  125. ->where('pm', 0)
  126. ->sum('number');
  127. $user['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  128. if ($user['broken_commission'] < 0)
  129. $user['broken_commission'] = 0;
  130. $user['commissionCount'] = bcsub($user['brokerage_price'], $user['broken_commission'], 2);
  131. if ($user['commissionCount'] < 0)
  132. $user['commissionCount'] = 0;
  133. if (!sys_config('vip_open'))
  134. $user['vip'] = false;
  135. else {
  136. $vipId = UserLevel::getUserLevel($user['uid']);
  137. $user['vip'] = $vipId !== false ? true : false;
  138. if ($user['vip']) {
  139. $user['vip_id'] = $vipId;
  140. $user['vip_icon'] = UserLevel::getUserLevelInfo($vipId, 'icon');
  141. $user['vip_name'] = UserLevel::getUserLevelInfo($vipId, 'name');
  142. }
  143. }
  144. $user['yesterDay'] = UserBill::yesterdayCommissionSum($user['uid']);
  145. $user['recharge_switch'] = (int)sys_config('recharge_switch');//充值开关
  146. $user['adminid'] = (boolean)\app\models\store\StoreService::orderServiceStatus($user['uid']);
  147. if ($user['phone'] && $user['user_type'] != 'h5') {
  148. $user['switchUserInfo'][] = $request->user();
  149. if ($h5UserInfo = User::where('account', $user['phone'])->where('user_type', 'h5')->find()) {
  150. $user['switchUserInfo'][] = $h5UserInfo;
  151. }
  152. } else if ($user['phone'] && $user['user_type'] == 'h5') {
  153. if ($wechatUserInfo = User::where('phone', $user['phone'])->where('user_type', '<>', 'h5')->find()) {
  154. $user['switchUserInfo'][] = $wechatUserInfo;
  155. }
  156. $user['switchUserInfo'][] = $request->user();
  157. } else if (!$user['phone']) {
  158. $user['switchUserInfo'][] = $request->user();
  159. }
  160. return app('json')->successful($user);
  161. }
  162. /**
  163. * 地址 获取单个
  164. * @param Request $request
  165. * @param $id
  166. * @return mixed
  167. * @throws DataNotFoundException
  168. * @throws ModelNotFoundException
  169. * @throws \think\exception\DbException
  170. */
  171. public function address(Request $request, $id)
  172. {
  173. $addressInfo = [];
  174. if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
  175. $addressInfo = UserAddress::find($id)->toArray();
  176. }
  177. return app('json')->successful($addressInfo);
  178. }
  179. /**
  180. * 地址列表
  181. * @param Request $request
  182. * @param $page
  183. * @param $limit
  184. * @return mixed
  185. */
  186. public function address_list(Request $request)
  187. {
  188. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true);
  189. $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default');
  190. return app('json')->successful($list);
  191. }
  192. /**
  193. * 设置默认地址
  194. *
  195. * @param Request $request
  196. * @return mixed
  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. */
  229. public function address_edit(Request $request)
  230. {
  231. $addressInfo = UtilService::postMore([
  232. ['address', []],
  233. ['is_default', false],
  234. ['real_name', ''],
  235. ['post_code', ''],
  236. ['phone', ''],
  237. ['detail', ''],
  238. ['id', 0],
  239. ['type', 0]
  240. ], $request);
  241. if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!');
  242. if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!');
  243. if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!');
  244. if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) {
  245. return app('json')->fail('收货地址格式错误!请重新选择!');
  246. } else if ($addressInfo['type'] == 1) {
  247. $city = $addressInfo['address']['city'];
  248. $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id');
  249. if ($cityId) {
  250. $addressInfo['address']['city_id'] = $cityId;
  251. } else {
  252. if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) {
  253. return app('json')->fail('收货地址格式错误!修改后请重新导入!');
  254. }
  255. $addressInfo['address']['city_id'] = $cityId;
  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. */
  297. public function address_del(Request $request)
  298. {
  299. list($id) = UtilService::postMore([['id', 0]], $request, true);
  300. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  301. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  302. return app('json')->fail('地址不存在!');
  303. if (UserAddress::edit(['is_del' => '1'], $id, 'id'))
  304. return app('json')->successful();
  305. else
  306. return app('json')->fail('删除地址失败!');
  307. }
  308. /**
  309. * 获取收藏产品
  310. *
  311. * @param Request $request
  312. * @return mixed
  313. */
  314. public function collect_user(Request $request)
  315. {
  316. list($page, $limit) = UtilService::getMore([
  317. ['page', 0],
  318. ['limit', 0]
  319. ], $request, true);
  320. if (!(int)$limit) return app('json')->successful([]);
  321. $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit);
  322. return app('json')->successful($productRelationList);
  323. }
  324. /**
  325. * 添加收藏
  326. * @param Request $request
  327. * @param $id
  328. * @param $category
  329. * @return mixed
  330. */
  331. public function collect_add(Request $request)
  332. {
  333. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  334. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  335. $res = StoreProductRelation::productRelation($id, $request->uid(), 'collect', $category);
  336. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  337. else return app('json')->successful();
  338. }
  339. /**
  340. * 取消收藏
  341. *
  342. * @param Request $request
  343. * @return mixed
  344. */
  345. public function collect_del(Request $request)
  346. {
  347. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  348. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  349. $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category);
  350. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  351. else return app('json')->successful();
  352. }
  353. /**
  354. * 批量收藏
  355. * @param Request $request
  356. * @return mixed
  357. */
  358. public function collect_all(Request $request)
  359. {
  360. $collectInfo = UtilService::postMore([
  361. ['id', []],
  362. ['category', 'product'],
  363. ], $request);
  364. if (!count($collectInfo['id'])) return app('json')->fail('参数错误');
  365. $productIdS = $collectInfo['id'];
  366. $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['category']);
  367. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  368. else return app('json')->successful('收藏成功');
  369. }
  370. /**
  371. * 添加点赞
  372. *
  373. * @param Request $request
  374. * @return mixed
  375. */
  376. // public function like_add(Request $request)
  377. // {
  378. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  379. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  380. // $res = StoreProductRelation::productRelation($id,$request->uid(),'like',$category);
  381. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  382. // else return app('json')->successful();
  383. // }
  384. /**
  385. * 取消点赞
  386. *
  387. * @param Request $request
  388. * @return mixed
  389. */
  390. // public function like_del(Request $request)
  391. // {
  392. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  393. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  394. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  395. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  396. // else return app('json')->successful();
  397. // }
  398. /**
  399. * 签到 配置
  400. * @return mixed
  401. * @throws DataNotFoundException
  402. * @throws ModelNotFoundException
  403. * @throws \think\exception\DbException
  404. */
  405. public function sign_config()
  406. {
  407. $signConfig = sys_data('sign_day_num') ?? [];
  408. return app('json')->successful($signConfig);
  409. }
  410. /**
  411. * 签到 列表
  412. * @param Request $request
  413. * @param $page
  414. * @param $limit
  415. * @return mixed
  416. */
  417. public function sign_list(Request $request)
  418. {
  419. list($page, $limit) = UtilService::getMore([
  420. ['page', 0],
  421. ['limit', 0]
  422. ], $request, true);
  423. if (!$limit) return app('json')->successful([]);
  424. $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit);
  425. if ($signList) $signList = $signList->toArray();
  426. return app('json')->successful($signList);
  427. }
  428. /**
  429. * 签到
  430. * @param Request $request
  431. * @return mixed
  432. */
  433. public function sign_integral(Request $request)
  434. {
  435. $signed = UserSign::getIsSign($request->uid());
  436. if ($signed) return app('json')->fail('已签到');
  437. if (false !== ($integral = UserSign::sign($request->uid())))
  438. return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]);
  439. return app('json')->fail(UserSign::getErrorInfo('签到失败'));
  440. }
  441. /**
  442. * 签到用户信息
  443. * @param Request $request
  444. * @return mixed
  445. */
  446. public function sign_user(Request $request)
  447. {
  448. list($sign, $integral, $all) = UtilService::postMore([
  449. ['sign', 0],
  450. ['integral', 0],
  451. ['all', 0],
  452. ], $request, true);
  453. $user = $request->user();
  454. //是否统计签到
  455. if ($sign || $all) {
  456. $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']);
  457. $user['is_day_sgin'] = UserSign::getIsSign($user['uid']);
  458. $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday');
  459. if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) {
  460. $user['sign_num'] = 0;
  461. }
  462. }
  463. //是否统计积分使用情况
  464. if ($integral || $all) {
  465. $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain');
  466. $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
  467. $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
  468. }
  469. unset($user['pwd']);
  470. if (!$user['is_promoter']) {
  471. $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == 2 ? true : false;
  472. }
  473. 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());
  474. }
  475. /**
  476. * 签到列表(年月)
  477. *
  478. * @param Request $request
  479. * @return mixed
  480. */
  481. public function sign_month(Request $request)
  482. {
  483. list($page, $limit) = UtilService::getMore([
  484. ['page', 0],
  485. ['limit', 0]
  486. ], $request, true);
  487. if (!$limit) return app('json')->successful([]);
  488. $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
  489. return app('json')->successful($userSignList);
  490. }
  491. /**
  492. * 获取活动状态
  493. * @return mixed
  494. */
  495. public function activity()
  496. {
  497. $data['is_bargin'] = StoreBargain::validBargain() ? true : false;
  498. $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false;
  499. $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false;
  500. return app('json')->successful($data);
  501. }
  502. /**
  503. * 用户修改信息
  504. * @param Request $request
  505. * @return mixed
  506. */
  507. public function edit(Request $request)
  508. {
  509. list($avatar, $nickname) = UtilService::postMore([
  510. ['avatar', ''],
  511. ['nickname', ''],
  512. ], $request, true);
  513. if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
  514. return app('json')->fail('修改失败');
  515. }
  516. /**
  517. * 推广人排行
  518. * @param Request $request
  519. * @return mixed
  520. * @throws DataNotFoundException
  521. * @throws ModelNotFoundException
  522. * @throws \think\exception\DbException
  523. */
  524. public function rank(Request $request)
  525. {
  526. $data = UtilService::getMore([
  527. ['page', ''],
  528. ['limit', ''],
  529. ['type', '']
  530. ], $request);
  531. $users = User::getRankList($data);
  532. return app('json')->success($users);
  533. }
  534. /**
  535. * 佣金排行
  536. * @param Request $request
  537. * @return mixed
  538. */
  539. public function brokerage_rank(Request $request)
  540. {
  541. $data = UtilService::getMore([
  542. ['page', ''],
  543. ['limit'],
  544. ['type']
  545. ], $request);
  546. return app('json')->success([
  547. 'rank' => User::brokerageRank($data),
  548. 'position' => User::currentUserRank($data['type'], $request->user()['brokerage_price'])
  549. ]);
  550. }
  551. /**
  552. * 添加访问记录
  553. * @param Request $request
  554. * @return mixed
  555. */
  556. public function set_visit(Request $request)
  557. {
  558. $data = UtilService::postMore([
  559. ['url', ''],
  560. ['stay_time', 0]
  561. ], $request);
  562. if ($data['url'] == '') return app('json')->fail('未获取页面路径');
  563. $data['uid'] = $request->uid();
  564. $data['ip'] = $request->ip();
  565. $data['add_time'] = time();
  566. $res = UserVisit::insert($data);
  567. if ($res) {
  568. return app('json')->success('添加访问记录成功');
  569. } else {
  570. return app('json')->fail('添加访问记录失败');
  571. }
  572. }
  573. /**
  574. * 静默绑定推广人
  575. * @param Request $request
  576. * @return mixed
  577. * @throws DataNotFoundException
  578. * @throws DbException
  579. * @throws ModelNotFoundException
  580. */
  581. public function spread(Request $request)
  582. {
  583. $puid = $request->post('puid/d', 0);
  584. return app('json')->success(User::setSpread($puid, $request->uid()));
  585. }
  586. =======
  587. <?php
  588. namespace app\api\controller\user;
  589. use app\http\validates\user\AddressValidate;
  590. use app\models\system\SystemCity;
  591. use app\models\user\UserVisit;
  592. use think\db\exception\DataNotFoundException;
  593. use think\db\exception\DbException;
  594. use think\db\exception\ModelNotFoundException;
  595. use think\exception\ValidateException;
  596. use app\Request;
  597. use app\models\user\UserLevel;
  598. use app\models\user\UserSign;
  599. use app\models\store\StoreBargain;
  600. use app\models\store\StoreCombination;
  601. use app\models\store\StoreCouponUser;
  602. use app\models\store\StoreOrder;
  603. use app\models\store\StoreProductRelation;
  604. use app\models\store\StoreSeckill;
  605. use app\models\user\User;
  606. use app\models\user\UserAddress;
  607. use app\models\user\UserBill;
  608. use app\models\user\UserExtract;
  609. use app\models\user\UserNotice;
  610. use crmeb\services\GroupDataService;
  611. use crmeb\services\UtilService;
  612. /**
  613. * 用户类
  614. * Class UserController
  615. * @package app\api\controller\store
  616. */
  617. class UserController
  618. {
  619. /**
  620. * 获取用户信息
  621. * @param Request $request
  622. * @return mixed
  623. */
  624. public function userInfo(Request $request)
  625. {
  626. $info = $request->user()->toArray();
  627. $broken_time = intval(sys_config('extract_time'));
  628. $search_time = time() - 86400 * $broken_time;
  629. //返佣 +
  630. $brokerage_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  631. ->where('add_time', '>', $search_time)
  632. ->where('pm', 1)
  633. ->sum('number');
  634. //退款退的佣金 -
  635. $refund_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  636. ->where('add_time', '>', $search_time)
  637. ->where('pm', 0)
  638. ->sum('number');
  639. $info['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  640. if ($info['broken_commission'] < 0)
  641. $info['broken_commission'] = 0;
  642. $info['commissionCount'] = bcsub($info['brokerage_price'], $info['broken_commission'], 2);
  643. if ($info['commissionCount'] < 0)
  644. $info['commissionCount'] = 0;
  645. $uids = User::where('spread_uid', $request->uid())->column('uid');
  646. $info['pay_price'] = StoreOrder::where('uid', 'in', $uids)
  647. ->where('paid', 1)
  648. ->where('is_participate', 0)
  649. ->sum('pay_price');
  650. return app('json')->success($info);
  651. }
  652. /**
  653. * 用户资金统计
  654. * @param Request $request
  655. * @return mixed
  656. * @throws \think\Exception
  657. * @throws DataNotFoundException
  658. * @throws ModelNotFoundException
  659. * @throws \think\exception\DbException
  660. */
  661. public function balance(Request $request)
  662. {
  663. $uid = $request->uid();
  664. $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money'];//当前总资金
  665. $user['recharge'] = UserBill::getRecharge($uid);//累计充值
  666. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid);//累计消费
  667. return app('json')->successful($user);
  668. }
  669. /**
  670. * 个人中心
  671. * @param Request $request
  672. * @return mixed
  673. */
  674. public function user(Request $request)
  675. {
  676. $user = $request->user();
  677. $user = $user->toArray();
  678. $user['couponCount'] = StoreCouponUser::getUserValidCouponCount($user['uid']);
  679. $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
  680. $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']);
  681. $user['notice'] = UserNotice::getNotice($user['uid']);
  682. $user['brokerage'] = UserBill::getBrokerage($user['uid']);//获取总佣金
  683. $user['recharge'] = UserBill::getRecharge($user['uid']);//累计充值
  684. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']);//累计消费
  685. $user['extractTotalPrice'] = UserExtract::userExtractTotalPrice($user['uid']);//累计提现
  686. $user['extractPrice'] = $user['brokerage_price'];//可提现
  687. $user['statu'] = (int)sys_config('store_brokerage_statu');
  688. $broken_time = intval(sys_config('extract_time'));
  689. $search_time = time() - 86400 * $broken_time;
  690. if (!$user['is_promoter'] && $user['statu'] == 2) {
  691. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price');
  692. $status = is_brokerage_statu($price);
  693. if ($status) {
  694. User::where('uid', $user['uid'])->update(['is_promoter' => 1]);
  695. $user['is_promoter'] = 1;
  696. } else {
  697. $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
  698. $user['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
  699. }
  700. }
  701. //可提现佣金
  702. //返佣 +
  703. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  704. ->where('add_time', '>', $search_time)
  705. ->where('pm', 1)
  706. ->sum('number');
  707. //退款退的佣金 -
  708. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  709. ->where('add_time', '>', $search_time)
  710. ->where('pm', 0)
  711. ->sum('number');
  712. $user['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  713. if ($user['broken_commission'] < 0)
  714. $user['broken_commission'] = 0;
  715. $user['commissionCount'] = bcsub($user['brokerage_price'], $user['broken_commission'], 2);
  716. if ($user['commissionCount'] < 0)
  717. $user['commissionCount'] = 0;
  718. if (!sys_config('vip_open'))
  719. $user['vip'] = false;
  720. else {
  721. $vipId = UserLevel::getUserLevel($user['uid']);
  722. $user['vip'] = $vipId !== false ? true : false;
  723. if ($user['vip']) {
  724. $user['vip_id'] = $vipId;
  725. $user['vip_icon'] = UserLevel::getUserLevelInfo($vipId, 'icon');
  726. $user['vip_name'] = UserLevel::getUserLevelInfo($vipId, 'name');
  727. }
  728. }
  729. $user['yesterDay'] = UserBill::yesterdayCommissionSum($user['uid']);
  730. $user['recharge_switch'] = (int)sys_config('recharge_switch');//充值开关
  731. $user['adminid'] = (boolean)\app\models\store\StoreService::orderServiceStatus($user['uid']);
  732. if ($user['phone'] && $user['user_type'] != 'h5') {
  733. $user['switchUserInfo'][] = $request->user();
  734. if ($h5UserInfo = User::where('account', $user['phone'])->where('user_type', 'h5')->find()) {
  735. $user['switchUserInfo'][] = $h5UserInfo;
  736. }
  737. } else if ($user['phone'] && $user['user_type'] == 'h5') {
  738. if ($wechatUserInfo = User::where('phone', $user['phone'])->where('user_type', '<>', 'h5')->find()) {
  739. $user['switchUserInfo'][] = $wechatUserInfo;
  740. }
  741. $user['switchUserInfo'][] = $request->user();
  742. } else if (!$user['phone']) {
  743. $user['switchUserInfo'][] = $request->user();
  744. }
  745. return app('json')->successful($user);
  746. }
  747. /**
  748. * 地址 获取单个
  749. * @param Request $request
  750. * @param $id
  751. * @return mixed
  752. * @throws DataNotFoundException
  753. * @throws ModelNotFoundException
  754. * @throws \think\exception\DbException
  755. */
  756. public function address(Request $request, $id)
  757. {
  758. $addressInfo = [];
  759. if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
  760. $addressInfo = UserAddress::find($id)->toArray();
  761. }
  762. return app('json')->successful($addressInfo);
  763. }
  764. /**
  765. * 地址列表
  766. * @param Request $request
  767. * @param $page
  768. * @param $limit
  769. * @return mixed
  770. */
  771. public function address_list(Request $request)
  772. {
  773. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true);
  774. $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default');
  775. return app('json')->successful($list);
  776. }
  777. /**
  778. * 设置默认地址
  779. *
  780. * @param Request $request
  781. * @return mixed
  782. */
  783. public function address_default_set(Request $request)
  784. {
  785. list($id) = UtilService::getMore([['id', 0]], $request, true);
  786. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  787. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  788. return app('json')->fail('地址不存在!');
  789. $res = UserAddress::setDefaultAddress($id, $request->uid());
  790. if (!$res)
  791. return app('json')->fail('地址不存在!');
  792. else
  793. return app('json')->successful();
  794. }
  795. /**
  796. * 获取默认地址
  797. * @param Request $request
  798. * @return mixed
  799. */
  800. public function address_default(Request $request)
  801. {
  802. $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default');
  803. if ($defaultAddress) {
  804. $defaultAddress = $defaultAddress->toArray();
  805. return app('json')->successful('ok', $defaultAddress);
  806. }
  807. return app('json')->successful('empty', []);
  808. }
  809. /**
  810. * 修改 添加地址
  811. * @param Request $request
  812. * @return mixed
  813. */
  814. public function address_edit(Request $request)
  815. {
  816. $addressInfo = UtilService::postMore([
  817. ['address', []],
  818. ['is_default', false],
  819. ['real_name', ''],
  820. ['post_code', ''],
  821. ['phone', ''],
  822. ['detail', ''],
  823. ['id', 0],
  824. ['type', 0]
  825. ], $request);
  826. if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!');
  827. if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!');
  828. if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!');
  829. if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) {
  830. return app('json')->fail('收货地址格式错误!请重新选择!');
  831. } else if ($addressInfo['type'] == 1) {
  832. $city = $addressInfo['address']['city'];
  833. $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id');
  834. if ($cityId) {
  835. $addressInfo['address']['city_id'] = $cityId;
  836. } else {
  837. if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) {
  838. return app('json')->fail('收货地址格式错误!修改后请重新导入!');
  839. }
  840. $addressInfo['address']['city_id'] = $cityId;
  841. }
  842. }
  843. $addressInfo['province'] = $addressInfo['address']['province'];
  844. $addressInfo['city'] = $addressInfo['address']['city'];
  845. $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
  846. $addressInfo['district'] = $addressInfo['address']['district'];
  847. $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
  848. $addressInfo['uid'] = $request->uid();
  849. unset($addressInfo['address'], $addressInfo['type']);
  850. try {
  851. validate(AddressValidate::class)->check($addressInfo);
  852. } catch (ValidateException $e) {
  853. return app('json')->fail($e->getError());
  854. }
  855. if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
  856. $id = $addressInfo['id'];
  857. unset($addressInfo['id']);
  858. if (UserAddress::edit($addressInfo, $id, 'id')) {
  859. if ($addressInfo['is_default'])
  860. UserAddress::setDefaultAddress($id, $request->uid());
  861. return app('json')->successful();
  862. } else
  863. return app('json')->fail('编辑收货地址失败!');
  864. } else {
  865. $addressInfo['add_time'] = time();
  866. if ($address = UserAddress::create($addressInfo)) {
  867. if ($addressInfo['is_default']) {
  868. UserAddress::setDefaultAddress($address->id, $request->uid());
  869. }
  870. return app('json')->successful(['id' => $address->id]);
  871. } else {
  872. return app('json')->fail('添加收货地址失败!');
  873. }
  874. }
  875. }
  876. /**
  877. * 删除地址
  878. *
  879. * @param Request $request
  880. * @return mixed
  881. */
  882. public function address_del(Request $request)
  883. {
  884. list($id) = UtilService::postMore([['id', 0]], $request, true);
  885. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  886. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  887. return app('json')->fail('地址不存在!');
  888. if (UserAddress::edit(['is_del' => '1'], $id, 'id'))
  889. return app('json')->successful();
  890. else
  891. return app('json')->fail('删除地址失败!');
  892. }
  893. /**
  894. * 获取收藏产品
  895. *
  896. * @param Request $request
  897. * @return mixed
  898. */
  899. public function collect_user(Request $request)
  900. {
  901. list($page, $limit) = UtilService::getMore([
  902. ['page', 0],
  903. ['limit', 0]
  904. ], $request, true);
  905. if (!(int)$limit) return app('json')->successful([]);
  906. $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit);
  907. return app('json')->successful($productRelationList);
  908. }
  909. /**
  910. * 添加收藏
  911. * @param Request $request
  912. * @param $id
  913. * @param $category
  914. * @return mixed
  915. */
  916. public function collect_add(Request $request)
  917. {
  918. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  919. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  920. $res = StoreProductRelation::productRelation($id, $request->uid(), 'collect', $category);
  921. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  922. else return app('json')->successful();
  923. }
  924. /**
  925. * 取消收藏
  926. *
  927. * @param Request $request
  928. * @return mixed
  929. */
  930. public function collect_del(Request $request)
  931. {
  932. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  933. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  934. $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category);
  935. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  936. else return app('json')->successful();
  937. }
  938. /**
  939. * 批量收藏
  940. * @param Request $request
  941. * @return mixed
  942. */
  943. public function collect_all(Request $request)
  944. {
  945. $collectInfo = UtilService::postMore([
  946. ['id', []],
  947. ['category', 'product'],
  948. ], $request);
  949. if (!count($collectInfo['id'])) return app('json')->fail('参数错误');
  950. $productIdS = $collectInfo['id'];
  951. $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['category']);
  952. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  953. else return app('json')->successful('收藏成功');
  954. }
  955. /**
  956. * 添加点赞
  957. *
  958. * @param Request $request
  959. * @return mixed
  960. */
  961. // public function like_add(Request $request)
  962. // {
  963. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  964. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  965. // $res = StoreProductRelation::productRelation($id,$request->uid(),'like',$category);
  966. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  967. // else return app('json')->successful();
  968. // }
  969. /**
  970. * 取消点赞
  971. *
  972. * @param Request $request
  973. * @return mixed
  974. */
  975. // public function like_del(Request $request)
  976. // {
  977. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  978. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  979. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  980. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  981. // else return app('json')->successful();
  982. // }
  983. /**
  984. * 签到 配置
  985. * @return mixed
  986. * @throws DataNotFoundException
  987. * @throws ModelNotFoundException
  988. * @throws \think\exception\DbException
  989. */
  990. public function sign_config()
  991. {
  992. $signConfig = sys_data('sign_day_num') ?? [];
  993. return app('json')->successful($signConfig);
  994. }
  995. /**
  996. * 签到 列表
  997. * @param Request $request
  998. * @param $page
  999. * @param $limit
  1000. * @return mixed
  1001. */
  1002. public function sign_list(Request $request)
  1003. {
  1004. list($page, $limit) = UtilService::getMore([
  1005. ['page', 0],
  1006. ['limit', 0]
  1007. ], $request, true);
  1008. if (!$limit) return app('json')->successful([]);
  1009. $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit);
  1010. if ($signList) $signList = $signList->toArray();
  1011. return app('json')->successful($signList);
  1012. }
  1013. /**
  1014. * 签到
  1015. * @param Request $request
  1016. * @return mixed
  1017. */
  1018. public function sign_integral(Request $request)
  1019. {
  1020. $signed = UserSign::getIsSign($request->uid());
  1021. if ($signed) return app('json')->fail('已签到');
  1022. if (false !== ($integral = UserSign::sign($request->uid())))
  1023. return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]);
  1024. return app('json')->fail(UserSign::getErrorInfo('签到失败'));
  1025. }
  1026. /**
  1027. * 签到用户信息
  1028. * @param Request $request
  1029. * @return mixed
  1030. */
  1031. public function sign_user(Request $request)
  1032. {
  1033. list($sign, $integral, $all) = UtilService::postMore([
  1034. ['sign', 0],
  1035. ['integral', 0],
  1036. ['all', 0],
  1037. ], $request, true);
  1038. $user = $request->user();
  1039. //是否统计签到
  1040. if ($sign || $all) {
  1041. $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']);
  1042. $user['is_day_sgin'] = UserSign::getIsSign($user['uid']);
  1043. $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday');
  1044. if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) {
  1045. $user['sign_num'] = 0;
  1046. }
  1047. }
  1048. //是否统计积分使用情况
  1049. if ($integral || $all) {
  1050. $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain');
  1051. $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
  1052. $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
  1053. }
  1054. unset($user['pwd']);
  1055. if (!$user['is_promoter']) {
  1056. $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == 2 ? true : false;
  1057. }
  1058. 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());
  1059. }
  1060. /**
  1061. * 签到列表(年月)
  1062. *
  1063. * @param Request $request
  1064. * @return mixed
  1065. */
  1066. public function sign_month(Request $request)
  1067. {
  1068. list($page, $limit) = UtilService::getMore([
  1069. ['page', 0],
  1070. ['limit', 0]
  1071. ], $request, true);
  1072. if (!$limit) return app('json')->successful([]);
  1073. $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
  1074. return app('json')->successful($userSignList);
  1075. }
  1076. /**
  1077. * 获取活动状态
  1078. * @return mixed
  1079. */
  1080. public function activity()
  1081. {
  1082. $data['is_bargin'] = StoreBargain::validBargain() ? true : false;
  1083. $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false;
  1084. $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false;
  1085. return app('json')->successful($data);
  1086. }
  1087. /**
  1088. * 用户修改信息
  1089. * @param Request $request
  1090. * @return mixed
  1091. */
  1092. public function edit(Request $request)
  1093. {
  1094. list($avatar, $nickname) = UtilService::postMore([
  1095. ['avatar', ''],
  1096. ['nickname', ''],
  1097. ], $request, true);
  1098. if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
  1099. return app('json')->fail('修改失败');
  1100. }
  1101. /**
  1102. * 推广人排行
  1103. * @param Request $request
  1104. * @return mixed
  1105. * @throws DataNotFoundException
  1106. * @throws ModelNotFoundException
  1107. * @throws \think\exception\DbException
  1108. */
  1109. public function rank(Request $request)
  1110. {
  1111. $data = UtilService::getMore([
  1112. ['page', ''],
  1113. ['limit', ''],
  1114. ['type', '']
  1115. ], $request);
  1116. $users = User::getRankList($data);
  1117. return app('json')->success($users);
  1118. }
  1119. /**
  1120. * 佣金排行
  1121. * @param Request $request
  1122. * @return mixed
  1123. */
  1124. public function brokerage_rank(Request $request)
  1125. {
  1126. $data = UtilService::getMore([
  1127. ['page', ''],
  1128. ['limit'],
  1129. ['type']
  1130. ], $request);
  1131. return app('json')->success([
  1132. 'rank' => User::brokerageRank($data),
  1133. 'position' => User::currentUserRank($data['type'], $request->user()['brokerage_price'])
  1134. ]);
  1135. }
  1136. /**
  1137. * 添加访问记录
  1138. * @param Request $request
  1139. * @return mixed
  1140. */
  1141. public function set_visit(Request $request)
  1142. {
  1143. $data = UtilService::postMore([
  1144. ['url', ''],
  1145. ['stay_time', 0]
  1146. ], $request);
  1147. if ($data['url'] == '') return app('json')->fail('未获取页面路径');
  1148. $data['uid'] = $request->uid();
  1149. $data['ip'] = $request->ip();
  1150. $data['add_time'] = time();
  1151. $res = UserVisit::insert($data);
  1152. if ($res) {
  1153. return app('json')->success('添加访问记录成功');
  1154. } else {
  1155. return app('json')->fail('添加访问记录失败');
  1156. }
  1157. }
  1158. /**
  1159. * 静默绑定推广人
  1160. * @param Request $request
  1161. * @return mixed
  1162. * @throws DataNotFoundException
  1163. * @throws DbException
  1164. * @throws ModelNotFoundException
  1165. */
  1166. public function spread(Request $request)
  1167. {
  1168. $puid = $request->post('puid/d', 0);
  1169. return app('json')->success(User::setSpread($puid, $request->uid()));
  1170. }
  1171. >>>>>>> 386b37d33e5ba817cba00df29efaefbd692e4dd1
  1172. }