UserController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\http\validates\user\AddressValidate;
  4. use app\models\member\MemberCheck;
  5. use app\models\member\MemberGrade;
  6. use app\models\system\SystemCity;
  7. use app\models\user\UserVisit;
  8. use crmeb\repositories\OrderRepository;
  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 && !$addressInfo['id']) {
  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. }
  253. }
  254. $addressInfo['province'] = $addressInfo['address']['province'];
  255. $addressInfo['city'] = $addressInfo['address']['city'];
  256. $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
  257. $addressInfo['district'] = $addressInfo['address']['district'];
  258. $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
  259. $addressInfo['uid'] = $request->uid();
  260. unset($addressInfo['address'], $addressInfo['type']);
  261. try {
  262. validate(AddressValidate::class)->check($addressInfo);
  263. } catch (ValidateException $e) {
  264. return app('json')->fail($e->getError());
  265. }
  266. if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
  267. $id = $addressInfo['id'];
  268. unset($addressInfo['id']);
  269. if (UserAddress::edit($addressInfo, $id, 'id')) {
  270. if ($addressInfo['is_default'])
  271. UserAddress::setDefaultAddress($id, $request->uid());
  272. return app('json')->successful();
  273. } else
  274. return app('json')->fail('编辑收货地址失败!');
  275. } else {
  276. $addressInfo['add_time'] = time();
  277. if ($address = UserAddress::create($addressInfo)) {
  278. if ($addressInfo['is_default']) {
  279. UserAddress::setDefaultAddress($address->id, $request->uid());
  280. }
  281. return app('json')->successful(['id' => $address->id]);
  282. } else {
  283. return app('json')->fail('添加收货地址失败!');
  284. }
  285. }
  286. }
  287. /**
  288. * 删除地址
  289. *
  290. * @param Request $request
  291. * @return mixed
  292. */
  293. public function address_del(Request $request)
  294. {
  295. list($id) = UtilService::postMore([['id', 0]], $request, true);
  296. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  297. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  298. return app('json')->fail('地址不存在!');
  299. if (UserAddress::edit(['is_del' => '1'], $id, 'id'))
  300. return app('json')->successful();
  301. else
  302. return app('json')->fail('删除地址失败!');
  303. }
  304. /**
  305. * 获取收藏产品
  306. *
  307. * @param Request $request
  308. * @return mixed
  309. */
  310. public function collect_user(Request $request)
  311. {
  312. list($page, $limit) = UtilService::getMore([
  313. ['page', 0],
  314. ['limit', 0]
  315. ], $request, true);
  316. if (!(int)$limit) return app('json')->successful([]);
  317. $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit);
  318. return app('json')->successful($productRelationList);
  319. }
  320. /**
  321. * 添加收藏
  322. * @param Request $request
  323. * @param $id
  324. * @param $category
  325. * @return mixed
  326. */
  327. public function collect_add(Request $request)
  328. {
  329. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  330. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  331. $res = StoreProductRelation::productRelation($id, $request->uid(), 'collect', $category);
  332. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  333. else return app('json')->successful();
  334. }
  335. /**
  336. * 取消收藏
  337. *
  338. * @param Request $request
  339. * @return mixed
  340. */
  341. public function collect_del(Request $request)
  342. {
  343. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  344. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  345. $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category);
  346. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  347. else return app('json')->successful();
  348. }
  349. /**
  350. * 批量收藏
  351. * @param Request $request
  352. * @return mixed
  353. */
  354. public function collect_all(Request $request)
  355. {
  356. $collectInfo = UtilService::postMore([
  357. ['id', []],
  358. ['category', 'product'],
  359. ], $request);
  360. if (!count($collectInfo['id'])) return app('json')->fail('参数错误');
  361. $productIdS = $collectInfo['id'];
  362. $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['category']);
  363. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  364. else return app('json')->successful('收藏成功');
  365. }
  366. /**
  367. * 添加点赞
  368. *
  369. * @param Request $request
  370. * @return mixed
  371. */
  372. // public function like_add(Request $request)
  373. // {
  374. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  375. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  376. // $res = StoreProductRelation::productRelation($id,$request->uid(),'like',$category);
  377. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  378. // else return app('json')->successful();
  379. // }
  380. /**
  381. * 取消点赞
  382. *
  383. * @param Request $request
  384. * @return mixed
  385. */
  386. // public function like_del(Request $request)
  387. // {
  388. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  389. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  390. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  391. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  392. // else return app('json')->successful();
  393. // }
  394. /**
  395. * 签到 配置
  396. * @return mixed
  397. * @throws DataNotFoundException
  398. * @throws ModelNotFoundException
  399. * @throws \think\exception\DbException
  400. */
  401. public function sign_config()
  402. {
  403. $signConfig = sys_data('sign_day_num') ?? [];
  404. return app('json')->successful($signConfig);
  405. }
  406. /**
  407. * 签到 列表
  408. * @param Request $request
  409. * @param $page
  410. * @param $limit
  411. * @return mixed
  412. */
  413. public function sign_list(Request $request)
  414. {
  415. list($page, $limit) = UtilService::getMore([
  416. ['page', 0],
  417. ['limit', 0]
  418. ], $request, true);
  419. if (!$limit) return app('json')->successful([]);
  420. $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit);
  421. if ($signList) $signList = $signList->toArray();
  422. return app('json')->successful($signList);
  423. }
  424. /**
  425. * 签到
  426. * @param Request $request
  427. * @return mixed
  428. */
  429. public function sign_integral(Request $request)
  430. {
  431. $signed = UserSign::getIsSign($request->uid());
  432. if ($signed) return app('json')->fail('已签到');
  433. if (false !== ($integral = UserSign::sign($request->uid())))
  434. return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]);
  435. return app('json')->fail(UserSign::getErrorInfo('签到失败'));
  436. }
  437. /**
  438. * 签到用户信息
  439. * @param Request $request
  440. * @return mixed
  441. */
  442. public function sign_user(Request $request)
  443. {
  444. list($sign, $integral, $all) = UtilService::postMore([
  445. ['sign', 0],
  446. ['integral', 0],
  447. ['all', 0],
  448. ], $request, true);
  449. $user = $request->user();
  450. //是否统计签到
  451. if ($sign || $all) {
  452. $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']);
  453. $user['is_day_sgin'] = UserSign::getIsSign($user['uid']);
  454. $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday');
  455. if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) {
  456. $user['sign_num'] = 0;
  457. }
  458. }
  459. //是否统计积分使用情况
  460. if ($integral || $all) {
  461. $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain');
  462. $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
  463. $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
  464. }
  465. unset($user['pwd']);
  466. if (!$user['is_promoter']) {
  467. $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == 2 ? true : false;
  468. }
  469. 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());
  470. }
  471. /**
  472. * 签到列表(年月)
  473. *
  474. * @param Request $request
  475. * @return mixed
  476. */
  477. public function sign_month(Request $request)
  478. {
  479. list($page, $limit) = UtilService::getMore([
  480. ['page', 0],
  481. ['limit', 0]
  482. ], $request, true);
  483. if (!$limit) return app('json')->successful([]);
  484. $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
  485. return app('json')->successful($userSignList);
  486. }
  487. /**
  488. * 获取活动状态
  489. * @return mixed
  490. */
  491. public function activity()
  492. {
  493. $data['is_bargin'] = StoreBargain::validBargain() ? true : false;
  494. $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false;
  495. $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false;
  496. return app('json')->successful($data);
  497. }
  498. /**
  499. * 用户修改信息
  500. * @param Request $request
  501. * @return mixed
  502. */
  503. public function edit(Request $request)
  504. {
  505. list($avatar, $nickname) = UtilService::postMore([
  506. ['avatar', ''],
  507. ['nickname', ''],
  508. ], $request, true);
  509. if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
  510. return app('json')->fail('修改失败');
  511. }
  512. /**
  513. * 推广人排行
  514. * @param Request $request
  515. * @return mixed
  516. * @throws DataNotFoundException
  517. * @throws ModelNotFoundException
  518. * @throws \think\exception\DbException
  519. */
  520. public function rank(Request $request)
  521. {
  522. $data = UtilService::getMore([
  523. ['page', ''],
  524. ['limit', ''],
  525. ['type', '']
  526. ], $request);
  527. $users = User::getRankList($data);
  528. return app('json')->success($users);
  529. }
  530. /**
  531. * 佣金排行
  532. * @param Request $request
  533. * @return mixed
  534. */
  535. public function brokerage_rank(Request $request)
  536. {
  537. $data = UtilService::getMore([
  538. ['page', ''],
  539. ['limit'],
  540. ['type']
  541. ], $request);
  542. return app('json')->success([
  543. 'rank' => User::brokerageRank($data),
  544. 'position' => User::currentUserRank($data['type'], $request->user()['brokerage_price'])
  545. ]);
  546. }
  547. /**
  548. * 添加访问记录
  549. * @param Request $request
  550. * @return mixed
  551. */
  552. public function set_visit(Request $request)
  553. {
  554. $data = UtilService::postMore([
  555. ['url', ''],
  556. ['stay_time', 0]
  557. ], $request);
  558. if ($data['url'] == '') return app('json')->fail('未获取页面路径');
  559. $data['uid'] = $request->uid();
  560. $data['ip'] = $request->ip();
  561. $data['add_time'] = time();
  562. $res = UserVisit::insert($data);
  563. if ($res) {
  564. return app('json')->success('添加访问记录成功');
  565. } else {
  566. return app('json')->fail('添加访问记录失败');
  567. }
  568. }
  569. /**
  570. * 静默绑定推广人
  571. * @param Request $request
  572. * @return mixed
  573. * @throws DataNotFoundException
  574. * @throws DbException
  575. * @throws ModelNotFoundException
  576. */
  577. public function spread(Request $request)
  578. {
  579. $puid = $request->post('puid/d', 0);
  580. return app('json')->success(User::setSpread($puid, $request->uid()));
  581. }
  582. public function getMemberConfig($type, Request $request)
  583. {
  584. $member = MemberGrade::where(['type' => $type])->order('grade asc')->select();
  585. return app('json')->success('ok', $member ? $member->toArray() : []);
  586. }
  587. public function applyMemberCheck(Request $request)
  588. {
  589. $uid = $request->uid();
  590. $param = UtilService::postMore([
  591. ['type', ''],
  592. ['name', ''],
  593. ['id', ''],
  594. ['phone', ''],
  595. ['location', ''],
  596. ['address', ''],
  597. ['occupation', ''],
  598. ['careerYears', ''],
  599. ['sponsor', ''],
  600. ['img', ''],
  601. ['grade', ''],
  602. ['pay_type', 'weixin'],
  603. ['from', 'weixin'],
  604. ], $request);
  605. $payType = $param['pay_type'];
  606. $from = $param['from'];
  607. $order = MemberCheck::createOrder($param, $uid, $payType, $from);
  608. if ($order === false) return app('json')->fail(MemberCheck::getErrorInfo('订单生成失败'));
  609. $orderId = $order['order_id'];
  610. $info = ['order_id' => $orderId];
  611. if ($orderId) {
  612. switch ($payType) {
  613. case "weixin":
  614. $orderInfo = MemberCheck::where('order_id', $orderId)->find();
  615. if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
  616. $orderInfo = $orderInfo->toArray();
  617. if ($orderInfo['paid']) return app('json')->fail('订单已支付!');
  618. //支付金额为0
  619. if (bcsub((float)$orderInfo['pay_money'], 0, 2) <= 0) {
  620. //创建订单jspay支付
  621. $payPriceStatus = MemberCheck::jsPayPrice($orderId, $uid);
  622. if ($payPriceStatus)//0元支付成功
  623. return app('json')->status('success', '微信支付成功');
  624. else
  625. return app('json')->status('pay_error', MemberCheck::getErrorInfo());
  626. } else {
  627. try {
  628. if ($from == 'routine') {
  629. $jsConfig = OrderRepository::jsMemberPay($orderId); //创建订单jspay
  630. } else if ($from == 'weixinh5') {
  631. $jsConfig = OrderRepository::h5MemberPay($orderId);
  632. } else {
  633. $jsConfig = OrderRepository::wxMemberPay($orderId);
  634. }
  635. } catch (\Exception $e) {
  636. return app('json')->status('pay_error', $e->getMessage());
  637. }
  638. $info['jsConfig'] = $jsConfig;
  639. if ($from == 'weixinh5') {
  640. return app('json')->status('wechat_h5_pay', '订单创建成功', $info);
  641. } else {
  642. return app('json')->status('wechat_pay', '订单创建成功', $info);
  643. }
  644. }
  645. case 'yue':
  646. if (MemberCheck::yuePay($orderId, $request->uid()))
  647. return app('json')->status('success', '余额支付成功', $info);
  648. else {
  649. $errorinfo = MemberCheck::getErrorInfo();
  650. if (is_array($errorinfo))
  651. return app('json')->status($errorinfo['status'], $errorinfo['msg'], $info);
  652. else
  653. return app('json')->status('pay_error', $errorinfo);
  654. }
  655. break;
  656. }
  657. } else return app('json')->fail(MemberCheck::getErrorInfo('订单生成失败!'));
  658. }
  659. }