UserController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\admin\model\diagnosis\DiagnosisApply;
  4. use app\admin\model\diagnosis\DiagnosisOrder;
  5. use app\http\validates\user\AddressValidate;
  6. use app\models\system\SystemCity;
  7. use app\models\user\UserVisit;
  8. use crmeb\services\CacheService;
  9. use think\db\exception\DataNotFoundException;
  10. use think\db\exception\DbException;
  11. use think\db\exception\ModelNotFoundException;
  12. use think\exception\ValidateException;
  13. use app\Request;
  14. use app\models\user\UserLevel;
  15. use app\models\user\UserSign;
  16. use app\models\store\StoreBargain;
  17. use app\models\store\StoreCombination;
  18. use app\models\store\StoreCouponUser;
  19. use app\models\store\StoreOrder;
  20. use app\models\store\StoreProductRelation;
  21. use app\models\store\StoreSeckill;
  22. use app\models\user\User;
  23. use app\models\user\UserAddress;
  24. use app\models\user\UserBill;
  25. use app\models\user\UserExtract;
  26. use app\models\user\UserNotice;
  27. use crmeb\services\GroupDataService;
  28. use crmeb\services\UtilService;
  29. /**
  30. * 用户类
  31. * Class UserController
  32. * @package app\api\controller\store
  33. */
  34. class UserController
  35. {
  36. /**
  37. * 获取用户信息
  38. * @param Request $request
  39. * @return mixed
  40. */
  41. public function userInfo(Request $request)
  42. {
  43. $info = $request->user()->toArray();
  44. $broken_time = intval(sys_config('extract_time'));
  45. $search_time = time() - 86400 * $broken_time;
  46. //返佣 +
  47. $brokerage_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  48. ->where('add_time', '>', $search_time)
  49. ->where('pm', 1)
  50. ->sum('number');
  51. //退款退的佣金 -
  52. $refund_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  53. ->where('add_time', '>', $search_time)
  54. ->where('pm', 0)
  55. ->sum('number');
  56. $info['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  57. if ($info['broken_commission'] < 0)
  58. $info['broken_commission'] = 0;
  59. $info['commissionCount'] = bcsub($info['brokerage_price'], $info['broken_commission'], 2);
  60. if ($info['commissionCount'] < 0)
  61. $info['commissionCount'] = 0;
  62. return app('json')->success($info);
  63. }
  64. /**
  65. * 用户资金统计
  66. * @param Request $request
  67. * @return mixed
  68. * @throws \think\Exception
  69. * @throws DataNotFoundException
  70. * @throws ModelNotFoundException
  71. * @throws \think\exception\DbException
  72. */
  73. public function balance(Request $request)
  74. {
  75. $uid = $request->uid();
  76. $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money'];//当前总资金
  77. $user['recharge'] = UserBill::getRecharge($uid);//累计充值
  78. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid);//累计消费
  79. return app('json')->successful($user);
  80. }
  81. /**
  82. * 个人中心
  83. * @param Request $request
  84. * @return mixed
  85. */
  86. public function user(Request $request)
  87. {
  88. $user = $request->user();
  89. $user = $user->toArray();
  90. $user['couponCount'] = StoreCouponUser::getUserValidCouponCount($user['uid']);
  91. $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
  92. $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']);
  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');
  100. $broken_time = intval(sys_config('extract_time'));
  101. $search_time = time() - 86400 * $broken_time;
  102. if (!$user['is_promoter'] && $user['statu'] == 2) {
  103. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price');
  104. $status = is_brokerage_statu($price);
  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);
  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');//充值开关
  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::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::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. return app('json')->successful($user);
  158. }
  159. /**
  160. * 地址 获取单个
  161. * @param Request $request
  162. * @param $id
  163. * @return mixed
  164. * @throws DataNotFoundException
  165. * @throws ModelNotFoundException
  166. * @throws \think\exception\DbException
  167. */
  168. public function address(Request $request, $id)
  169. {
  170. $addressInfo = [];
  171. if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
  172. $addressInfo = UserAddress::find($id)->toArray();
  173. }
  174. return app('json')->successful($addressInfo);
  175. }
  176. /**
  177. * 地址列表
  178. * @param Request $request
  179. * @param $page
  180. * @param $limit
  181. * @return mixed
  182. */
  183. public function address_list(Request $request)
  184. {
  185. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true);
  186. $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default');
  187. return app('json')->successful($list);
  188. }
  189. /**
  190. * 设置默认地址
  191. *
  192. * @param Request $request
  193. * @return mixed
  194. */
  195. public function address_default_set(Request $request)
  196. {
  197. list($id) = UtilService::getMore([['id', 0]], $request, true);
  198. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  199. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  200. return app('json')->fail('地址不存在!');
  201. $res = UserAddress::setDefaultAddress($id, $request->uid());
  202. if (!$res)
  203. return app('json')->fail('地址不存在!');
  204. else
  205. return app('json')->successful();
  206. }
  207. /**
  208. * 获取默认地址
  209. * @param Request $request
  210. * @return mixed
  211. */
  212. public function address_default(Request $request)
  213. {
  214. $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default');
  215. if ($defaultAddress) {
  216. $defaultAddress = $defaultAddress->toArray();
  217. return app('json')->successful('ok', $defaultAddress);
  218. }
  219. return app('json')->successful('empty', []);
  220. }
  221. /**
  222. * 修改 添加地址
  223. * @param Request $request
  224. * @return mixed
  225. */
  226. public function address_edit(Request $request)
  227. {
  228. $addressInfo = UtilService::postMore([
  229. ['address', []],
  230. ['is_default', false],
  231. ['real_name', ''],
  232. ['post_code', ''],
  233. ['phone', ''],
  234. ['detail', ''],
  235. ['id', 0],
  236. ['type', 0]
  237. ], $request);
  238. if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!');
  239. if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!');
  240. if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!');
  241. if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) {
  242. return app('json')->fail('收货地址格式错误!请重新选择!');
  243. } else if ($addressInfo['type'] == 1) {
  244. $city = $addressInfo['address']['city'];
  245. $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id');
  246. if ($cityId) {
  247. $addressInfo['address']['city_id'] = $cityId;
  248. } else {
  249. if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) {
  250. return app('json')->fail('收货地址格式错误!修改后请重新导入!');
  251. }
  252. $addressInfo['address']['city_id'] = $cityId;
  253. }
  254. }
  255. $addressInfo['province'] = $addressInfo['address']['province'];
  256. $addressInfo['city'] = $addressInfo['address']['city'];
  257. $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
  258. $addressInfo['district'] = $addressInfo['address']['district'];
  259. $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
  260. $addressInfo['uid'] = $request->uid();
  261. unset($addressInfo['address'], $addressInfo['type']);
  262. try {
  263. validate(AddressValidate::class)->check($addressInfo);
  264. } catch (ValidateException $e) {
  265. return app('json')->fail($e->getError());
  266. }
  267. if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
  268. $id = $addressInfo['id'];
  269. unset($addressInfo['id']);
  270. if (UserAddress::edit($addressInfo, $id, 'id')) {
  271. if ($addressInfo['is_default'])
  272. UserAddress::setDefaultAddress($id, $request->uid());
  273. return app('json')->successful();
  274. } else
  275. return app('json')->fail('编辑收货地址失败!');
  276. } else {
  277. $addressInfo['add_time'] = time();
  278. if ($address = UserAddress::create($addressInfo)) {
  279. if ($addressInfo['is_default']) {
  280. UserAddress::setDefaultAddress($address->id, $request->uid());
  281. }
  282. return app('json')->successful(['id' => $address->id]);
  283. } else {
  284. return app('json')->fail('添加收货地址失败!');
  285. }
  286. }
  287. }
  288. /**
  289. * 删除地址
  290. *
  291. * @param Request $request
  292. * @return mixed
  293. */
  294. public function address_del(Request $request)
  295. {
  296. list($id) = UtilService::postMore([['id', 0]], $request, true);
  297. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  298. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  299. return app('json')->fail('地址不存在!');
  300. if (UserAddress::edit(['is_del' => '1'], $id, 'id'))
  301. return app('json')->successful();
  302. else
  303. return app('json')->fail('删除地址失败!');
  304. }
  305. /**
  306. * 获取收藏产品
  307. *
  308. * @param Request $request
  309. * @return mixed
  310. */
  311. public function collect_user(Request $request)
  312. {
  313. list($page, $limit) = UtilService::getMore([
  314. ['page', 0],
  315. ['limit', 0]
  316. ], $request, true);
  317. if (!(int)$limit) return app('json')->successful([]);
  318. $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit);
  319. return app('json')->successful($productRelationList);
  320. }
  321. /**
  322. * 添加收藏
  323. * @param Request $request
  324. * @param $id
  325. * @param $category
  326. * @return mixed
  327. */
  328. public function collect_add(Request $request)
  329. {
  330. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  331. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  332. $res = StoreProductRelation::productRelation($id, $request->uid(), 'collect', $category);
  333. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  334. else return app('json')->successful();
  335. }
  336. /**
  337. * 取消收藏
  338. *
  339. * @param Request $request
  340. * @return mixed
  341. */
  342. public function collect_del(Request $request)
  343. {
  344. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  345. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  346. $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category);
  347. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  348. else return app('json')->successful();
  349. }
  350. /**
  351. * 批量收藏
  352. * @param Request $request
  353. * @return mixed
  354. */
  355. public function collect_all(Request $request)
  356. {
  357. $collectInfo = UtilService::postMore([
  358. ['id', []],
  359. ['category', 'product'],
  360. ], $request);
  361. if (!count($collectInfo['id'])) return app('json')->fail('参数错误');
  362. $productIdS = $collectInfo['id'];
  363. $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['category']);
  364. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  365. else return app('json')->successful('收藏成功');
  366. }
  367. /**
  368. * 添加点赞
  369. *
  370. * @param Request $request
  371. * @return mixed
  372. */
  373. // public function like_add(Request $request)
  374. // {
  375. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  376. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  377. // $res = StoreProductRelation::productRelation($id,$request->uid(),'like',$category);
  378. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  379. // else return app('json')->successful();
  380. // }
  381. /**
  382. * 取消点赞
  383. *
  384. * @param Request $request
  385. * @return mixed
  386. */
  387. // public function like_del(Request $request)
  388. // {
  389. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  390. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  391. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  392. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  393. // else return app('json')->successful();
  394. // }
  395. /**
  396. * 签到 配置
  397. * @return mixed
  398. * @throws DataNotFoundException
  399. * @throws ModelNotFoundException
  400. * @throws \think\exception\DbException
  401. */
  402. public function sign_config()
  403. {
  404. $signConfig = sys_data('sign_day_num') ?? [];
  405. return app('json')->successful($signConfig);
  406. }
  407. /**
  408. * 签到 列表
  409. * @param Request $request
  410. * @param $page
  411. * @param $limit
  412. * @return mixed
  413. */
  414. public function sign_list(Request $request)
  415. {
  416. list($page, $limit) = UtilService::getMore([
  417. ['page', 0],
  418. ['limit', 0]
  419. ], $request, true);
  420. if (!$limit) return app('json')->successful([]);
  421. $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit);
  422. if ($signList) $signList = $signList->toArray();
  423. return app('json')->successful($signList);
  424. }
  425. /**
  426. * 签到
  427. * @param Request $request
  428. * @return mixed
  429. */
  430. public function sign_integral(Request $request)
  431. {
  432. $signed = UserSign::getIsSign($request->uid());
  433. if ($signed) return app('json')->fail('已签到');
  434. if (false !== ($integral = UserSign::sign($request->uid())))
  435. return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]);
  436. return app('json')->fail(UserSign::getErrorInfo('签到失败'));
  437. }
  438. /**
  439. * 签到用户信息
  440. * @param Request $request
  441. * @return mixed
  442. */
  443. public function sign_user(Request $request)
  444. {
  445. list($sign, $integral, $all) = UtilService::postMore([
  446. ['sign', 0],
  447. ['integral', 0],
  448. ['all', 0],
  449. ], $request, true);
  450. $user = $request->user();
  451. //是否统计签到
  452. if ($sign || $all) {
  453. $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']);
  454. $user['is_day_sgin'] = UserSign::getIsSign($user['uid']);
  455. $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday');
  456. if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) {
  457. $user['sign_num'] = 0;
  458. }
  459. }
  460. //是否统计积分使用情况
  461. if ($integral || $all) {
  462. $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain');
  463. $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
  464. $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
  465. }
  466. unset($user['pwd']);
  467. if (!$user['is_promoter']) {
  468. $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == 2 ? true : false;
  469. }
  470. 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());
  471. }
  472. /**
  473. * 签到列表(年月)
  474. *
  475. * @param Request $request
  476. * @return mixed
  477. */
  478. public function sign_month(Request $request)
  479. {
  480. list($page, $limit) = UtilService::getMore([
  481. ['page', 0],
  482. ['limit', 0]
  483. ], $request, true);
  484. if (!$limit) return app('json')->successful([]);
  485. $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
  486. return app('json')->successful($userSignList);
  487. }
  488. /**
  489. * 获取活动状态
  490. * @return mixed
  491. */
  492. public function activity()
  493. {
  494. $data['is_bargin'] = StoreBargain::validBargain() ? true : false;
  495. $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false;
  496. $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false;
  497. return app('json')->successful($data);
  498. }
  499. /**
  500. * 用户修改信息
  501. * @param Request $request
  502. * @return mixed
  503. */
  504. public function edit(Request $request)
  505. {
  506. list($avatar, $nickname) = UtilService::postMore([
  507. ['avatar', ''],
  508. ['nickname', ''],
  509. ], $request, true);
  510. if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
  511. return app('json')->fail('修改失败');
  512. }
  513. /**
  514. * 推广人排行
  515. * @param Request $request
  516. * @return mixed
  517. * @throws DataNotFoundException
  518. * @throws ModelNotFoundException
  519. * @throws \think\exception\DbException
  520. */
  521. public function rank(Request $request)
  522. {
  523. $data = UtilService::getMore([
  524. ['page', ''],
  525. ['limit', ''],
  526. ['type', '']
  527. ], $request);
  528. $users = User::getRankList($data);
  529. return app('json')->success($users);
  530. }
  531. /**
  532. * 佣金排行
  533. * @param Request $request
  534. * @return mixed
  535. */
  536. public function brokerage_rank(Request $request)
  537. {
  538. $data = UtilService::getMore([
  539. ['page', ''],
  540. ['limit'],
  541. ['type']
  542. ], $request);
  543. return app('json')->success([
  544. 'rank' => User::brokerageRank($data),
  545. 'position' => User::currentUserRank($data['type'], $request->user()['brokerage_price'])
  546. ]);
  547. }
  548. /**
  549. * 添加访问记录
  550. * @param Request $request
  551. * @return mixed
  552. */
  553. public function set_visit(Request $request)
  554. {
  555. $data = UtilService::postMore([
  556. ['url', ''],
  557. ['stay_time', 0]
  558. ], $request);
  559. if ($data['url'] == '') return app('json')->fail('未获取页面路径');
  560. $data['uid'] = $request->uid();
  561. $data['ip'] = $request->ip();
  562. $data['add_time'] = time();
  563. $res = UserVisit::insert($data);
  564. if ($res) {
  565. return app('json')->success('添加访问记录成功');
  566. } else {
  567. return app('json')->fail('添加访问记录失败');
  568. }
  569. }
  570. /**
  571. * 静默绑定推广人
  572. * @param Request $request
  573. * @return mixed
  574. * @throws DataNotFoundException
  575. * @throws DbException
  576. * @throws ModelNotFoundException
  577. */
  578. public function spread(Request $request)
  579. {
  580. $puid = $request->post('puid/d', 0);
  581. return app('json')->success(User::setSpread($puid, $request->uid()));
  582. }
  583. /**
  584. * 提交修改申请
  585. * @param Request $request
  586. * @return mixed
  587. * @throws DataNotFoundException
  588. * @throws DbException
  589. * @throws ModelNotFoundException
  590. */
  591. public function apply(Request $request)
  592. {
  593. $data = UtilService::postMore([
  594. ['name'],
  595. ['sex'],
  596. ['phone'],
  597. ['images', []],
  598. ['captcha']
  599. ]);
  600. // $verifyCode = CacheService::get('code_' . $data['phone']);
  601. // if (!$verifyCode)
  602. // return app('json')->fail('请先获取验证码');
  603. // $verifyCode = substr($verifyCode, 0, 6);
  604. // if ($verifyCode != $data['captcha'])
  605. // return app('json')->fail('验证码错误');
  606. if (empty($data['name'])) return app('json')->fail('请填写姓名');
  607. if (empty($data['sex'])) return app('json')->fail('请填写性别');
  608. if (empty($data['phone'])) return app('json')->fail('请填写手机号');
  609. if(!(preg_match("/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/",$data['phone'])))
  610. {
  611. return app('json')->fail('请填写正确的手机号');
  612. }
  613. if (empty($data['images'])) return app('json')->fail('请上传身份证正反面');
  614. $apply = DiagnosisApply::where('uid', $request->uid())->find();
  615. if (!$apply){
  616. $res = DiagnosisApply::create([
  617. 'name' => $data['name'],
  618. 'uid' => $request->uid(),
  619. 'sex' => $data['sex'],
  620. 'phone' => $data['phone'],
  621. 'images' => json_encode($data['images'])
  622. ]);
  623. if ($res) return app('json')->success('提交成功');
  624. return app('json')->fail('提交失败');
  625. }else{
  626. if ($apply['status'] == 0) return app('json')->success('审核中无法修改');
  627. if ($apply['status'] == -1){
  628. $apply['status'] = 0;
  629. $apply['remarks'] = '';
  630. }
  631. $apply['name'] = $data['name'];
  632. $apply['sex'] = $data['sex'];
  633. $apply['phone'] = $data['phone'];
  634. $apply['images'] = json_encode($data['images']);
  635. $res = $apply->save();
  636. if ($res) return app('json')->success('修改成功');
  637. return app('json')->fail('修改失败');
  638. }
  639. }
  640. /**
  641. * 申请记录
  642. * @param Request $request
  643. * @return mixed
  644. * @throws DataNotFoundException
  645. * @throws DbException
  646. * @throws ModelNotFoundException
  647. */
  648. public function user_apply(Request $request)
  649. {
  650. $list = DiagnosisApply::where('uid', $request->uid())->select();
  651. $list = count($list) > 0 ? $list->toArray() : [];
  652. if ($list){
  653. foreach ($list as &$item)
  654. {
  655. $item['images'] = json_decode($item['images']);
  656. }
  657. }
  658. return app('json')->successful($list);
  659. }
  660. }