UserController.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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\Cert;
  8. use app\models\user\UserTicket;
  9. use app\models\user\UserVisit;
  10. use crmeb\repositories\OrderRepository;
  11. use crmeb\services\FormBuilder;
  12. use think\db\exception\DataNotFoundException;
  13. use think\db\exception\DbException;
  14. use think\db\exception\ModelNotFoundException;
  15. use think\exception\ValidateException;
  16. use app\Request;
  17. use app\models\user\UserLevel;
  18. use app\models\user\UserSign;
  19. use app\models\store\StoreBargain;
  20. use app\models\store\StoreCombination;
  21. use app\models\store\StoreCouponUser;
  22. use app\models\store\StoreOrder;
  23. use app\models\store\StoreProductRelation;
  24. use app\models\store\StoreSeckill;
  25. use app\models\user\User;
  26. use app\models\user\UserAddress;
  27. use app\models\user\UserBill;
  28. use app\models\user\UserExtract;
  29. use app\models\user\UserNotice;
  30. use crmeb\services\GroupDataService;
  31. use crmeb\services\UtilService;
  32. use think\facade\Route;
  33. /**
  34. * 用户类
  35. * Class UserController
  36. * @package app\api\controller\store
  37. */
  38. class UserController
  39. {
  40. /**
  41. * 获取用户信息
  42. * @param Request $request
  43. * @return mixed
  44. */
  45. public function userInfo(Request $request)
  46. {
  47. $info = $request->user()->toArray();
  48. $broken_time = intval(sys_config('extract_time'));
  49. $search_time = time() - 86400 * $broken_time;
  50. //返佣 +
  51. $brokerage_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  52. ->where('add_time', '>', $search_time)
  53. ->where('pm', 1)
  54. ->sum('number');
  55. //退款退的佣金 -
  56. $refund_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  57. ->where('add_time', '>', $search_time)
  58. ->where('pm', 0)
  59. ->sum('number');
  60. $info['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  61. if ($info['broken_commission'] < 0)
  62. $info['broken_commission'] = 0;
  63. $info['commissionCount'] = bcsub($info['brokerage_price'], $info['broken_commission'], 2);
  64. if ($info['commissionCount'] < 0)
  65. $info['commissionCount'] = 0;
  66. return app('json')->success($info);
  67. }
  68. /**
  69. * 用户资金统计
  70. * @param Request $request
  71. * @return mixed
  72. * @throws \think\Exception
  73. * @throws DataNotFoundException
  74. * @throws ModelNotFoundException
  75. * @throws \think\exception\DbException
  76. */
  77. public function balance(Request $request)
  78. {
  79. $uid = $request->uid();
  80. $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money'];//当前总资金
  81. $user['recharge'] = UserBill::getRecharge($uid);//累计充值
  82. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid);//累计消费
  83. return app('json')->successful($user);
  84. }
  85. /**
  86. * 个人中心
  87. * @param Request $request
  88. * @return mixed
  89. */
  90. public function user(Request $request)
  91. {
  92. $user = $request->user();
  93. $user = $user->toArray();
  94. $user['couponCount'] = StoreCouponUser::getUserValidCouponCount($user['uid']);
  95. $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
  96. $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']);
  97. $user['notice'] = UserNotice::getNotice($user['uid']);
  98. // $user['brokerage'] = UserBill::getBrokerage($user['uid']);//获取总佣金
  99. $user['recharge'] = UserBill::getRecharge($user['uid']);//累计充值
  100. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']);//累计消费
  101. $user['extractTotalPrice'] = UserExtract::userExtractTotalPrice($user['uid']);//累计提现
  102. $user['extractPrice'] = $user['brokerage_price'];//可提现
  103. $user['statu'] = (int)sys_config('store_brokerage_statu');
  104. $broken_time = intval(sys_config('extract_time'));
  105. $search_time = time() - 86400 * $broken_time;
  106. if (!$user['is_promoter'] && $user['statu'] == 2) {
  107. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price');
  108. $status = is_brokerage_statu($price);
  109. if ($status) {
  110. User::where('uid', $user['uid'])->update(['is_promoter' => 1]);
  111. $user['is_promoter'] = 1;
  112. } else {
  113. $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
  114. $user['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
  115. }
  116. }
  117. //可提现佣金
  118. //返佣 +
  119. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  120. ->where('add_time', '>', $search_time)
  121. ->where('pm', 1)
  122. ->sum('number');
  123. //退款退的佣金 -
  124. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  125. ->where('add_time', '>', $search_time)
  126. ->where('pm', 0)
  127. ->sum('number');
  128. $user['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  129. if ($user['broken_commission'] < 0)
  130. $user['broken_commission'] = 0;
  131. $user['commissionCount'] = bcsub($user['brokerage_price'], $user['broken_commission'], 2);
  132. if ($user['commissionCount'] < 0)
  133. $user['commissionCount'] = 0;
  134. if (!sys_config('vip_open'))
  135. $user['vip'] = false;
  136. else {
  137. $vipId = UserLevel::getUserLevel($user['uid']);
  138. $user['vip'] = $vipId !== false ? true : false;
  139. if ($user['vip']) {
  140. $user['vip_id'] = $vipId;
  141. $user['vip_icon'] = UserLevel::getUserLevelInfo($vipId, 'icon');
  142. $user['vip_name'] = UserLevel::getUserLevelInfo($vipId, 'name');
  143. }
  144. }
  145. $user['yesterDay'] = UserBill::yesterdayCommissionSum($user['uid']);
  146. $user['recharge_switch'] = (int)sys_config('recharge_switch');//充值开关
  147. $user['adminid'] = (boolean)\app\models\store\StoreService::orderServiceStatus($user['uid']);
  148. if ($user['phone'] && $user['user_type'] != 'h5') {
  149. $user['switchUserInfo'][] = $request->user();
  150. if ($h5UserInfo = User::where('account', $user['phone'])->where('user_type', 'h5')->find()) {
  151. $user['switchUserInfo'][] = $h5UserInfo;
  152. }
  153. } else if ($user['phone'] && $user['user_type'] == 'h5') {
  154. if ($wechatUserInfo = User::where('phone', $user['phone'])->where('user_type', '<>', 'h5')->find()) {
  155. $user['switchUserInfo'][] = $wechatUserInfo;
  156. }
  157. $user['switchUserInfo'][] = $request->user();
  158. } else if (!$user['phone']) {
  159. $user['switchUserInfo'][] = $request->user();
  160. }
  161. return app('json')->successful($user);
  162. }
  163. /**
  164. * 地址 获取单个
  165. * @param Request $request
  166. * @param $id
  167. * @return mixed
  168. * @throws DataNotFoundException
  169. * @throws ModelNotFoundException
  170. * @throws \think\exception\DbException
  171. */
  172. public function address(Request $request, $id)
  173. {
  174. $addressInfo = [];
  175. if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
  176. $addressInfo = UserAddress::find($id)->toArray();
  177. }
  178. return app('json')->successful($addressInfo);
  179. }
  180. /**
  181. * 地址列表
  182. * @param Request $request
  183. * @param $page
  184. * @param $limit
  185. * @return mixed
  186. */
  187. public function address_list(Request $request)
  188. {
  189. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true);
  190. $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default');
  191. return app('json')->successful($list);
  192. }
  193. /**
  194. * 设置默认地址
  195. *
  196. * @param Request $request
  197. * @return mixed
  198. */
  199. public function address_default_set(Request $request)
  200. {
  201. list($id) = UtilService::getMore([['id', 0]], $request, true);
  202. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  203. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  204. return app('json')->fail('地址不存在!');
  205. $res = UserAddress::setDefaultAddress($id, $request->uid());
  206. if (!$res)
  207. return app('json')->fail('地址不存在!');
  208. else
  209. return app('json')->successful();
  210. }
  211. /**
  212. * 获取默认地址
  213. * @param Request $request
  214. * @return mixed
  215. */
  216. public function address_default(Request $request)
  217. {
  218. $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default');
  219. if ($defaultAddress) {
  220. $defaultAddress = $defaultAddress->toArray();
  221. return app('json')->successful('ok', $defaultAddress);
  222. }
  223. return app('json')->successful('empty', []);
  224. }
  225. /**
  226. * 修改 添加地址
  227. * @param Request $request
  228. * @return mixed
  229. */
  230. public function address_edit(Request $request)
  231. {
  232. $addressInfo = UtilService::postMore([
  233. ['address', []],
  234. ['is_default', false],
  235. ['real_name', ''],
  236. ['post_code', ''],
  237. ['phone', ''],
  238. ['detail', ''],
  239. ['id', 0],
  240. ['type', 0]
  241. ], $request);
  242. if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!');
  243. if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!');
  244. if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!');
  245. if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) {
  246. return app('json')->fail('收货地址格式错误!请重新选择!');
  247. } else if ($addressInfo['type'] == 1 && !$addressInfo['id']) {
  248. $city = $addressInfo['address']['city'];
  249. $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id');
  250. if ($cityId) {
  251. $addressInfo['address']['city_id'] = $cityId;
  252. } else {
  253. if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) {
  254. return app('json')->fail('收货地址格式错误!修改后请重新导入!');
  255. }
  256. }
  257. }
  258. $addressInfo['province'] = $addressInfo['address']['province'];
  259. $addressInfo['city'] = $addressInfo['address']['city'];
  260. $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
  261. $addressInfo['district'] = $addressInfo['address']['district'];
  262. $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
  263. $addressInfo['uid'] = $request->uid();
  264. unset($addressInfo['address'], $addressInfo['type']);
  265. try {
  266. validate(AddressValidate::class)->check($addressInfo);
  267. } catch (ValidateException $e) {
  268. return app('json')->fail($e->getError());
  269. }
  270. if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
  271. $id = $addressInfo['id'];
  272. unset($addressInfo['id']);
  273. if (UserAddress::edit($addressInfo, $id, 'id')) {
  274. if ($addressInfo['is_default'])
  275. UserAddress::setDefaultAddress($id, $request->uid());
  276. return app('json')->successful();
  277. } else
  278. return app('json')->fail('编辑收货地址失败!');
  279. } else {
  280. $addressInfo['add_time'] = time();
  281. if ($address = UserAddress::create($addressInfo)) {
  282. if ($addressInfo['is_default']) {
  283. UserAddress::setDefaultAddress($address->id, $request->uid());
  284. }
  285. return app('json')->successful(['id' => $address->id]);
  286. } else {
  287. return app('json')->fail('添加收货地址失败!');
  288. }
  289. }
  290. }
  291. /**
  292. * 删除地址
  293. *
  294. * @param Request $request
  295. * @return mixed
  296. */
  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. public function getMemberConfig($type, Request $request)
  587. {
  588. $member = MemberGrade::where(['type' => $type])->order('grade asc')->select();
  589. return app('json')->success('ok', $member ? $member->toArray() : []);
  590. }
  591. public function getMember($type, Request $request)
  592. {
  593. $name = $request->get('name', '');
  594. $idcard = $request->get('idcard', '');
  595. $info = MemberCheck::where(['status' => 1, 'paid' => 1])->where(compact('type', 'name'));
  596. if ($type == 1) $info = $info->where('idcard', $idcard);
  597. $info = $info->find();
  598. if (!$info) {
  599. return app('json')->fail('找不到会员,请检查查询项');
  600. } else {
  601. $info['grade_info'] = MemberGrade::where(['type' => $info['type'], 'grade' => $info['grade']])->find();
  602. $info['id'] = str_pad($info['check_id'], '6', '0', STR_PAD_LEFT);
  603. $info['imgs'] = explode(',', $info['imgs']);
  604. return app('json')->success('ok', ['data' => $info]);
  605. }
  606. }
  607. public function applyMemberCheck($type, Request $request)
  608. {
  609. $uid = $request->uid();
  610. $param = UtilService::postMore([
  611. ['name', ''],
  612. ['id', ''],
  613. ['phone', ''],
  614. ['location', ''],
  615. ['address', ''],
  616. ['occupation', ''],
  617. ['careerYears', ''],
  618. ['sponsor', ''],
  619. ['img', ''],
  620. ['grade', ''],
  621. ['pay_type', 'weixin'],
  622. ['from', 'weixin'],
  623. ], $request);
  624. $payType = $param['pay_type'];
  625. $from = $param['from'];
  626. $param['type'] = $type;
  627. $order = MemberCheck::createOrder($param, $uid, $payType, $from);
  628. if ($order === false) return app('json')->fail(MemberCheck::getErrorInfo('订单生成失败'));
  629. $orderId = $order['order_id'];
  630. $info = ['order_id' => $orderId];
  631. if ($orderId) {
  632. switch ($payType) {
  633. case "weixin":
  634. $orderInfo = MemberCheck::where('order_id', $orderId)->find();
  635. if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
  636. $orderInfo = $orderInfo->toArray();
  637. if ($orderInfo['paid']) return app('json')->fail('订单已支付!');
  638. //支付金额为0
  639. if (bcsub((float)$orderInfo['pay_money'], 0, 2) <= 0) {
  640. //创建订单jspay支付
  641. $payPriceStatus = MemberCheck::jsPayPrice($orderId, $uid);
  642. if ($payPriceStatus)//0元支付成功
  643. return app('json')->status('success', '微信支付成功');
  644. else
  645. return app('json')->status('pay_error', MemberCheck::getErrorInfo());
  646. } else {
  647. try {
  648. if ($from == 'routine') {
  649. $jsConfig = OrderRepository::jsMemberPay($orderId); //创建订单jspay
  650. } else if ($from == 'weixinh5') {
  651. $jsConfig = OrderRepository::h5MemberPay($orderId);
  652. } else {
  653. $jsConfig = OrderRepository::wxMemberPay($orderId);
  654. }
  655. } catch (\Exception $e) {
  656. return app('json')->status('pay_error', $e->getMessage());
  657. }
  658. $info['jsConfig'] = $jsConfig;
  659. if ($from == 'weixinh5') {
  660. return app('json')->status('wechat_h5_pay', '订单创建成功', $info);
  661. } else {
  662. return app('json')->status('wechat_pay', '订单创建成功', $info);
  663. }
  664. }
  665. case 'yue':
  666. if (MemberCheck::yuePay($orderId, $request->uid()))
  667. return app('json')->status('success', '余额支付成功', $info);
  668. else {
  669. $errorinfo = MemberCheck::getErrorInfo();
  670. if (is_array($errorinfo))
  671. return app('json')->status($errorinfo['status'], $errorinfo['msg'], $info);
  672. else
  673. return app('json')->status('pay_error', $errorinfo);
  674. }
  675. break;
  676. }
  677. } else return app('json')->fail(MemberCheck::getErrorInfo('订单生成失败!'));
  678. }
  679. public function tickets(Request $request)
  680. {
  681. list($page, $limit) = UtilService::getMore([['page', 1], ['limit', 10]], $request, true);
  682. $list = UserTicket::where('all_num > num')->where('uid', $request->uid())->order('id', 'desc')->page($page, $limit)->select();
  683. $count = UserTicket::where('all_num > num')->where('uid', $request->uid())->count();
  684. return app('json')->success('ok', compact('list', 'count'));
  685. }
  686. public function check_tickets(Request $request)
  687. {
  688. if (!$request->user()['checker']) return app('json')->fail('非核销员身份无法核销');
  689. list($code) = UtilService::postMore([['code', '']], $request, true);
  690. $ticket = UserTicket::where('ticket_code', $code)->find();
  691. if (!$ticket) return app('json')->fail('核销码无效');
  692. if ($ticket['all_num'] <= $ticket['num']) return app('json')->fail('该核销码核销次数已用完');
  693. $ticket->num++;
  694. $res = $ticket->save();
  695. if ($res)
  696. return app('json')->success('核销成功');
  697. else
  698. return app('json')->fail('核销失败');
  699. }
  700. public function addCert(Request $request)
  701. {
  702. list($name, $gender, $idcard, $job, $photo) = UtilService::postMore([
  703. ['name', '', '', '', 'not_empty_check', '请输入姓名'],
  704. ['gender', '', '', '', 'not_empty_check', '请选择性别'],
  705. ['idcard', '', '', '', 'not_empty_check', '请输入身份证号码'],
  706. ['job', '', '', '', 'not_empty_check', '请输入职业'],
  707. ['photo', '', '', '', 'not_empty_check', '请上传照片'],
  708. ], $request, true);
  709. $res = Cert::add_cert($request->uid(), $name, $gender, $idcard, $job, $photo);
  710. if ($res) {
  711. return app('json')->success('申请成功');
  712. } else {
  713. return app('json')->fail(Cert::getErrorInfo());
  714. }
  715. }
  716. public function getCert(Request $request, $id = 0)
  717. {
  718. list($name) = UtilService::getMore([
  719. ['name', ''],
  720. ], $request, true);
  721. if ($id) {
  722. return app('json')->success('ok', ['info' => Cert::get($id)]);
  723. } else {
  724. return app('json')->success('ok', ['info' => Cert::search($name)]);
  725. }
  726. }
  727. }