UserController.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\admin\model\user\CertType;
  4. use app\http\validates\user\AddressValidate;
  5. use app\models\member\MemberCheck;
  6. use app\models\member\MemberGrade;
  7. use app\models\system\SystemCity;
  8. use app\models\user\Cert;
  9. use app\models\user\UserTicket;
  10. use app\models\user\UserVisit;
  11. use crmeb\repositories\OrderRepository;
  12. use crmeb\services\FormBuilder;
  13. use think\db\exception\DataNotFoundException;
  14. use think\db\exception\DbException;
  15. use think\db\exception\ModelNotFoundException;
  16. use think\exception\ValidateException;
  17. use app\Request;
  18. use app\models\user\UserLevel;
  19. use app\models\user\UserSign;
  20. use app\models\store\StoreBargain;
  21. use app\models\store\StoreCombination;
  22. use app\models\store\StoreCouponUser;
  23. use app\models\store\StoreOrder;
  24. use app\models\store\StoreProductRelation;
  25. use app\models\store\StoreSeckill;
  26. use app\models\user\User;
  27. use app\models\user\UserAddress;
  28. use app\models\user\UserBill;
  29. use app\models\user\UserExtract;
  30. use app\models\user\UserNotice;
  31. use crmeb\services\GroupDataService;
  32. use crmeb\services\UtilService;
  33. use think\facade\Route;
  34. /**
  35. * 用户类
  36. * Class UserController
  37. * @package app\api\controller\store
  38. */
  39. class UserController
  40. {
  41. /**
  42. * 获取用户信息
  43. * @param Request $request
  44. * @return mixed
  45. */
  46. public function userInfo(Request $request)
  47. {
  48. $info = $request->user()->toArray();
  49. $broken_time = intval(sys_config('extract_time'));
  50. $search_time = time() - 86400 * $broken_time;
  51. //返佣 +
  52. $brokerage_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  53. ->where('add_time', '>', $search_time)
  54. ->where('pm', 1)
  55. ->sum('number');
  56. //退款退的佣金 -
  57. $refund_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  58. ->where('add_time', '>', $search_time)
  59. ->where('pm', 0)
  60. ->sum('number');
  61. $info['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  62. if ($info['broken_commission'] < 0)
  63. $info['broken_commission'] = 0;
  64. $info['commissionCount'] = bcsub($info['brokerage_price'], $info['broken_commission'], 2);
  65. if ($info['commissionCount'] < 0)
  66. $info['commissionCount'] = 0;
  67. return app('json')->success($info);
  68. }
  69. /**
  70. * 用户资金统计
  71. * @param Request $request
  72. * @return mixed
  73. * @throws \think\Exception
  74. * @throws DataNotFoundException
  75. * @throws ModelNotFoundException
  76. * @throws \think\exception\DbException
  77. */
  78. public function balance(Request $request)
  79. {
  80. $uid = $request->uid();
  81. $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money'];//当前总资金
  82. $user['recharge'] = UserBill::getRecharge($uid);//累计充值
  83. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid);//累计消费
  84. return app('json')->successful($user);
  85. }
  86. /**
  87. * 个人中心
  88. * @param Request $request
  89. * @return mixed
  90. */
  91. public function user(Request $request)
  92. {
  93. $user = $request->user();
  94. $user = $user->toArray();
  95. $user['couponCount'] = StoreCouponUser::getUserValidCouponCount($user['uid']);
  96. $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
  97. $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']);
  98. $user['notice'] = UserNotice::getNotice($user['uid']);
  99. // $user['brokerage'] = UserBill::getBrokerage($user['uid']);//获取总佣金
  100. $user['recharge'] = UserBill::getRecharge($user['uid']);//累计充值
  101. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']);//累计消费
  102. $user['extractTotalPrice'] = UserExtract::userExtractTotalPrice($user['uid']);//累计提现
  103. $user['extractPrice'] = $user['brokerage_price'];//可提现
  104. $user['statu'] = (int)sys_config('store_brokerage_statu');
  105. $broken_time = intval(sys_config('extract_time'));
  106. $search_time = time() - 86400 * $broken_time;
  107. if (!$user['is_promoter'] && $user['statu'] == 2) {
  108. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price');
  109. $status = is_brokerage_statu($price);
  110. if ($status) {
  111. User::where('uid', $user['uid'])->update(['is_promoter' => 1]);
  112. $user['is_promoter'] = 1;
  113. } else {
  114. $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
  115. $user['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
  116. }
  117. }
  118. //可提现佣金
  119. //返佣 +
  120. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  121. ->where('add_time', '>', $search_time)
  122. ->where('pm', 1)
  123. ->sum('number');
  124. //退款退的佣金 -
  125. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  126. ->where('add_time', '>', $search_time)
  127. ->where('pm', 0)
  128. ->sum('number');
  129. $user['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  130. if ($user['broken_commission'] < 0)
  131. $user['broken_commission'] = 0;
  132. $user['commissionCount'] = bcsub($user['brokerage_price'], $user['broken_commission'], 2);
  133. if ($user['commissionCount'] < 0)
  134. $user['commissionCount'] = 0;
  135. if (!sys_config('vip_open'))
  136. $user['vip'] = false;
  137. else {
  138. $vipId = UserLevel::getUserLevel($user['uid']);
  139. $user['vip'] = $vipId !== false ? true : false;
  140. if ($user['vip']) {
  141. $user['vip_id'] = $vipId;
  142. $user['vip_icon'] = UserLevel::getUserLevelInfo($vipId, 'icon');
  143. $user['vip_name'] = UserLevel::getUserLevelInfo($vipId, 'name');
  144. }
  145. }
  146. $user['yesterDay'] = UserBill::yesterdayCommissionSum($user['uid']);
  147. $user['recharge_switch'] = (int)sys_config('recharge_switch');//充值开关
  148. $user['adminid'] = (boolean)\app\models\store\StoreService::orderServiceStatus($user['uid']);
  149. if ($user['phone'] && $user['user_type'] != 'h5') {
  150. $user['switchUserInfo'][] = $request->user();
  151. if ($h5UserInfo = User::where('account', $user['phone'])->where('user_type', 'h5')->find()) {
  152. $user['switchUserInfo'][] = $h5UserInfo;
  153. }
  154. } else if ($user['phone'] && $user['user_type'] == 'h5') {
  155. if ($wechatUserInfo = User::where('phone', $user['phone'])->where('user_type', '<>', 'h5')->find()) {
  156. $user['switchUserInfo'][] = $wechatUserInfo;
  157. }
  158. $user['switchUserInfo'][] = $request->user();
  159. } else if (!$user['phone']) {
  160. $user['switchUserInfo'][] = $request->user();
  161. }
  162. return app('json')->successful($user);
  163. }
  164. /**
  165. * 地址 获取单个
  166. * @param Request $request
  167. * @param $id
  168. * @return mixed
  169. * @throws DataNotFoundException
  170. * @throws ModelNotFoundException
  171. * @throws \think\exception\DbException
  172. */
  173. public function address(Request $request, $id)
  174. {
  175. $addressInfo = [];
  176. if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
  177. $addressInfo = UserAddress::find($id)->toArray();
  178. }
  179. return app('json')->successful($addressInfo);
  180. }
  181. /**
  182. * 地址列表
  183. * @param Request $request
  184. * @param $page
  185. * @param $limit
  186. * @return mixed
  187. */
  188. public function address_list(Request $request)
  189. {
  190. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true);
  191. $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default');
  192. return app('json')->successful($list);
  193. }
  194. /**
  195. * 设置默认地址
  196. *
  197. * @param Request $request
  198. * @return mixed
  199. */
  200. public function address_default_set(Request $request)
  201. {
  202. list($id) = UtilService::getMore([['id', 0]], $request, true);
  203. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  204. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  205. return app('json')->fail('地址不存在!');
  206. $res = UserAddress::setDefaultAddress($id, $request->uid());
  207. if (!$res)
  208. return app('json')->fail('地址不存在!');
  209. else
  210. return app('json')->successful();
  211. }
  212. /**
  213. * 获取默认地址
  214. * @param Request $request
  215. * @return mixed
  216. */
  217. public function address_default(Request $request)
  218. {
  219. $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default');
  220. if ($defaultAddress) {
  221. $defaultAddress = $defaultAddress->toArray();
  222. return app('json')->successful('ok', $defaultAddress);
  223. }
  224. return app('json')->successful('empty', []);
  225. }
  226. /**
  227. * 修改 添加地址
  228. * @param Request $request
  229. * @return mixed
  230. */
  231. public function address_edit(Request $request)
  232. {
  233. $addressInfo = UtilService::postMore([
  234. ['address', []],
  235. ['is_default', false],
  236. ['real_name', ''],
  237. ['post_code', ''],
  238. ['phone', ''],
  239. ['detail', ''],
  240. ['id', 0],
  241. ['type', 0]
  242. ], $request);
  243. if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!');
  244. if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!');
  245. if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!');
  246. if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) {
  247. return app('json')->fail('收货地址格式错误!请重新选择!');
  248. } else if ($addressInfo['type'] == 1 && !$addressInfo['id']) {
  249. $city = $addressInfo['address']['city'];
  250. $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id');
  251. if ($cityId) {
  252. $addressInfo['address']['city_id'] = $cityId;
  253. } else {
  254. if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) {
  255. return app('json')->fail('收货地址格式错误!修改后请重新导入!');
  256. }
  257. }
  258. }
  259. $addressInfo['province'] = $addressInfo['address']['province'];
  260. $addressInfo['city'] = $addressInfo['address']['city'];
  261. $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
  262. $addressInfo['district'] = $addressInfo['address']['district'];
  263. $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
  264. $addressInfo['uid'] = $request->uid();
  265. unset($addressInfo['address'], $addressInfo['type']);
  266. try {
  267. validate(AddressValidate::class)->check($addressInfo);
  268. } catch (ValidateException $e) {
  269. return app('json')->fail($e->getError());
  270. }
  271. if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
  272. $id = $addressInfo['id'];
  273. unset($addressInfo['id']);
  274. if (UserAddress::edit($addressInfo, $id, 'id')) {
  275. if ($addressInfo['is_default'])
  276. UserAddress::setDefaultAddress($id, $request->uid());
  277. return app('json')->successful();
  278. } else
  279. return app('json')->fail('编辑收货地址失败!');
  280. } else {
  281. $addressInfo['add_time'] = time();
  282. if ($address = UserAddress::create($addressInfo)) {
  283. if ($addressInfo['is_default']) {
  284. UserAddress::setDefaultAddress($address->id, $request->uid());
  285. }
  286. return app('json')->successful(['id' => $address->id]);
  287. } else {
  288. return app('json')->fail('添加收货地址失败!');
  289. }
  290. }
  291. }
  292. /**
  293. * 删除地址
  294. *
  295. * @param Request $request
  296. * @return mixed
  297. */
  298. public function address_del(Request $request)
  299. {
  300. list($id) = UtilService::postMore([['id', 0]], $request, true);
  301. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  302. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  303. return app('json')->fail('地址不存在!');
  304. if (UserAddress::edit(['is_del' => '1'], $id, 'id'))
  305. return app('json')->successful();
  306. else
  307. return app('json')->fail('删除地址失败!');
  308. }
  309. /**
  310. * 获取收藏产品
  311. *
  312. * @param Request $request
  313. * @return mixed
  314. */
  315. public function collect_user(Request $request)
  316. {
  317. list($page, $limit) = UtilService::getMore([
  318. ['page', 0],
  319. ['limit', 0]
  320. ], $request, true);
  321. if (!(int)$limit) return app('json')->successful([]);
  322. $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit);
  323. return app('json')->successful($productRelationList);
  324. }
  325. /**
  326. * 添加收藏
  327. * @param Request $request
  328. * @param $id
  329. * @param $category
  330. * @return mixed
  331. */
  332. public function collect_add(Request $request)
  333. {
  334. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  335. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  336. $res = StoreProductRelation::productRelation($id, $request->uid(), 'collect', $category);
  337. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  338. else return app('json')->successful();
  339. }
  340. /**
  341. * 取消收藏
  342. *
  343. * @param Request $request
  344. * @return mixed
  345. */
  346. public function collect_del(Request $request)
  347. {
  348. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  349. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  350. $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category);
  351. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  352. else return app('json')->successful();
  353. }
  354. /**
  355. * 批量收藏
  356. * @param Request $request
  357. * @return mixed
  358. */
  359. public function collect_all(Request $request)
  360. {
  361. $collectInfo = UtilService::postMore([
  362. ['id', []],
  363. ['category', 'product'],
  364. ], $request);
  365. if (!count($collectInfo['id'])) return app('json')->fail('参数错误');
  366. $productIdS = $collectInfo['id'];
  367. $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['category']);
  368. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  369. else return app('json')->successful('收藏成功');
  370. }
  371. /**
  372. * 添加点赞
  373. *
  374. * @param Request $request
  375. * @return mixed
  376. */
  377. // public function like_add(Request $request)
  378. // {
  379. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  380. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  381. // $res = StoreProductRelation::productRelation($id,$request->uid(),'like',$category);
  382. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  383. // else return app('json')->successful();
  384. // }
  385. /**
  386. * 取消点赞
  387. *
  388. * @param Request $request
  389. * @return mixed
  390. */
  391. // public function like_del(Request $request)
  392. // {
  393. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  394. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  395. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  396. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  397. // else return app('json')->successful();
  398. // }
  399. /**
  400. * 签到 配置
  401. * @return mixed
  402. * @throws DataNotFoundException
  403. * @throws ModelNotFoundException
  404. * @throws \think\exception\DbException
  405. */
  406. public function sign_config()
  407. {
  408. $signConfig = sys_data('sign_day_num') ?? [];
  409. return app('json')->successful($signConfig);
  410. }
  411. /**
  412. * 签到 列表
  413. * @param Request $request
  414. * @param $page
  415. * @param $limit
  416. * @return mixed
  417. */
  418. public function sign_list(Request $request)
  419. {
  420. list($page, $limit) = UtilService::getMore([
  421. ['page', 0],
  422. ['limit', 0]
  423. ], $request, true);
  424. if (!$limit) return app('json')->successful([]);
  425. $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit);
  426. if ($signList) $signList = $signList->toArray();
  427. return app('json')->successful($signList);
  428. }
  429. /**
  430. * 签到
  431. * @param Request $request
  432. * @return mixed
  433. */
  434. public function sign_integral(Request $request)
  435. {
  436. $signed = UserSign::getIsSign($request->uid());
  437. if ($signed) return app('json')->fail('已签到');
  438. if (false !== ($integral = UserSign::sign($request->uid())))
  439. return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]);
  440. return app('json')->fail(UserSign::getErrorInfo('签到失败'));
  441. }
  442. /**
  443. * 签到用户信息
  444. * @param Request $request
  445. * @return mixed
  446. */
  447. public function sign_user(Request $request)
  448. {
  449. list($sign, $integral, $all) = UtilService::postMore([
  450. ['sign', 0],
  451. ['integral', 0],
  452. ['all', 0],
  453. ], $request, true);
  454. $user = $request->user();
  455. //是否统计签到
  456. if ($sign || $all) {
  457. $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']);
  458. $user['is_day_sgin'] = UserSign::getIsSign($user['uid']);
  459. $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday');
  460. if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) {
  461. $user['sign_num'] = 0;
  462. }
  463. }
  464. //是否统计积分使用情况
  465. if ($integral || $all) {
  466. $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain');
  467. $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
  468. $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
  469. }
  470. unset($user['pwd']);
  471. if (!$user['is_promoter']) {
  472. $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == 2 ? true : false;
  473. }
  474. 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());
  475. }
  476. /**
  477. * 签到列表(年月)
  478. *
  479. * @param Request $request
  480. * @return mixed
  481. */
  482. public function sign_month(Request $request)
  483. {
  484. list($page, $limit) = UtilService::getMore([
  485. ['page', 0],
  486. ['limit', 0]
  487. ], $request, true);
  488. if (!$limit) return app('json')->successful([]);
  489. $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
  490. return app('json')->successful($userSignList);
  491. }
  492. /**
  493. * 获取活动状态
  494. * @return mixed
  495. */
  496. public function activity()
  497. {
  498. $data['is_bargin'] = StoreBargain::validBargain() ? true : false;
  499. $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false;
  500. $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false;
  501. return app('json')->successful($data);
  502. }
  503. /**
  504. * 用户修改信息
  505. * @param Request $request
  506. * @return mixed
  507. */
  508. public function edit(Request $request)
  509. {
  510. list($avatar, $nickname) = UtilService::postMore([
  511. ['avatar', ''],
  512. ['nickname', ''],
  513. ], $request, true);
  514. if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
  515. return app('json')->fail('修改失败');
  516. }
  517. /**
  518. * 推广人排行
  519. * @param Request $request
  520. * @return mixed
  521. * @throws DataNotFoundException
  522. * @throws ModelNotFoundException
  523. * @throws \think\exception\DbException
  524. */
  525. public function rank(Request $request)
  526. {
  527. $data = UtilService::getMore([
  528. ['page', ''],
  529. ['limit', ''],
  530. ['type', '']
  531. ], $request);
  532. $users = User::getRankList($data);
  533. return app('json')->success($users);
  534. }
  535. /**
  536. * 佣金排行
  537. * @param Request $request
  538. * @return mixed
  539. */
  540. public function brokerage_rank(Request $request)
  541. {
  542. $data = UtilService::getMore([
  543. ['page', ''],
  544. ['limit'],
  545. ['type']
  546. ], $request);
  547. return app('json')->success([
  548. 'rank' => User::brokerageRank($data),
  549. 'position' => User::currentUserRank($data['type'], $request->user()['brokerage_price'])
  550. ]);
  551. }
  552. /**
  553. * 添加访问记录
  554. * @param Request $request
  555. * @return mixed
  556. */
  557. public function set_visit(Request $request)
  558. {
  559. $data = UtilService::postMore([
  560. ['url', ''],
  561. ['stay_time', 0]
  562. ], $request);
  563. if ($data['url'] == '') return app('json')->fail('未获取页面路径');
  564. $data['uid'] = $request->uid();
  565. $data['ip'] = $request->ip();
  566. $data['add_time'] = time();
  567. $res = UserVisit::insert($data);
  568. if ($res) {
  569. return app('json')->success('添加访问记录成功');
  570. } else {
  571. return app('json')->fail('添加访问记录失败');
  572. }
  573. }
  574. /**
  575. * 静默绑定推广人
  576. * @param Request $request
  577. * @return mixed
  578. * @throws DataNotFoundException
  579. * @throws DbException
  580. * @throws ModelNotFoundException
  581. */
  582. public function spread(Request $request)
  583. {
  584. $puid = $request->post('puid/d', 0);
  585. return app('json')->success(User::setSpread($puid, $request->uid()));
  586. }
  587. public function getMemberConfig($type, Request $request)
  588. {
  589. $member = MemberGrade::where(['type' => $type])->order('grade asc')->select();
  590. return app('json')->success('ok', $member ? $member->toArray() : []);
  591. }
  592. public function getMember($type, Request $request)
  593. {
  594. $name = $request->get('name', '');
  595. $idcard = $request->get('idcard', '');
  596. $info = MemberCheck::where(['status' => 1, 'paid' => 1])->where(compact('type', 'name'));
  597. if ($type == 1) $info = $info->where('idcard', $idcard);
  598. $info = $info->find();
  599. if (!$info) {
  600. return app('json')->fail('找不到会员,请检查查询项');
  601. } else {
  602. $info['grade_info'] = MemberGrade::where(['type' => $info['type'], 'grade' => $info['grade']])->find();
  603. $info['id'] = str_pad($info['check_id'], '6', '0', STR_PAD_LEFT);
  604. $info['imgs'] = explode(',', $info['imgs']);
  605. return app('json')->success('ok', ['data' => $info]);
  606. }
  607. }
  608. public function applyMemberCheck($type, Request $request)
  609. {
  610. $uid = $request->uid();
  611. $param = UtilService::postMore([
  612. ['name', ''],
  613. ['id', ''],
  614. ['phone', ''],
  615. ['location', ''],
  616. ['address', ''],
  617. ['occupation', ''],
  618. ['careerYears', ''],
  619. ['sponsor', ''],
  620. ['img', ''],
  621. ['grade', ''],
  622. ['pay_type', 'weixin'],
  623. ['from', 'weixin'],
  624. ], $request);
  625. $payType = $param['pay_type'];
  626. $from = $param['from'];
  627. $param['type'] = $type;
  628. $order = MemberCheck::createOrder($param, $uid, $payType, $from);
  629. if ($order === false) return app('json')->fail(MemberCheck::getErrorInfo('订单生成失败'));
  630. $orderId = $order['order_id'];
  631. $info = ['order_id' => $orderId];
  632. if ($orderId) {
  633. switch ($payType) {
  634. case "weixin":
  635. $orderInfo = MemberCheck::where('order_id', $orderId)->find();
  636. if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
  637. $orderInfo = $orderInfo->toArray();
  638. if ($orderInfo['paid']) return app('json')->fail('订单已支付!');
  639. //支付金额为0
  640. if (bcsub((float)$orderInfo['pay_money'], 0, 2) <= 0) {
  641. //创建订单jspay支付
  642. $payPriceStatus = MemberCheck::jsPayPrice($orderId, $uid);
  643. if ($payPriceStatus)//0元支付成功
  644. return app('json')->status('success', '微信支付成功');
  645. else
  646. return app('json')->status('pay_error', MemberCheck::getErrorInfo());
  647. } else {
  648. try {
  649. if ($from == 'routine') {
  650. $jsConfig = OrderRepository::jsMemberPay($orderId); //创建订单jspay
  651. } else if ($from == 'weixinh5') {
  652. $jsConfig = OrderRepository::h5MemberPay($orderId);
  653. } else {
  654. $jsConfig = OrderRepository::wxMemberPay($orderId);
  655. }
  656. } catch (\Exception $e) {
  657. return app('json')->status('pay_error', $e->getMessage());
  658. }
  659. $info['jsConfig'] = $jsConfig;
  660. if ($from == 'weixinh5') {
  661. return app('json')->status('wechat_h5_pay', '订单创建成功', $info);
  662. } else {
  663. return app('json')->status('wechat_pay', '订单创建成功', $info);
  664. }
  665. }
  666. case 'yue':
  667. if (MemberCheck::yuePay($orderId, $request->uid()))
  668. return app('json')->status('success', '余额支付成功', $info);
  669. else {
  670. $errorinfo = MemberCheck::getErrorInfo();
  671. if (is_array($errorinfo))
  672. return app('json')->status($errorinfo['status'], $errorinfo['msg'], $info);
  673. else
  674. return app('json')->status('pay_error', $errorinfo);
  675. }
  676. break;
  677. }
  678. } else return app('json')->fail(MemberCheck::getErrorInfo('订单生成失败!'));
  679. }
  680. public function tickets(Request $request)
  681. {
  682. list($page, $limit) = UtilService::getMore([['page', 1], ['limit', 10]], $request, true);
  683. $list = UserTicket::where('all_num > num')->where('uid', $request->uid())->order('id', 'desc')->page($page, $limit)->select();
  684. $count = UserTicket::where('all_num > num')->where('uid', $request->uid())->count();
  685. return app('json')->success('ok', compact('list', 'count'));
  686. }
  687. public function check_tickets(Request $request)
  688. {
  689. if (!$request->user()['checker']) return app('json')->fail('非核销员身份无法核销');
  690. list($code) = UtilService::postMore([['code', '']], $request, true);
  691. $ticket = UserTicket::where('ticket_code', $code)->find();
  692. if (!$ticket) return app('json')->fail('核销码无效');
  693. if ($ticket['all_num'] <= $ticket['num']) return app('json')->fail('该核销码核销次数已用完');
  694. $ticket->num++;
  695. $res = $ticket->save();
  696. if ($res)
  697. return app('json')->success('核销成功');
  698. else
  699. return app('json')->fail('核销失败');
  700. }
  701. public function jobs(Request $request)
  702. {
  703. return app('json')->success('ok', ['data' => CertType::select()]);
  704. }
  705. public function addCert(Request $request)
  706. {
  707. list($name, $gender, $idcard, $job, $photo) = UtilService::postMore([
  708. ['name', '', '', '', 'not_empty_check', '请输入姓名'],
  709. ['gender', '', '', '', 'not_empty_check', '请选择性别'],
  710. ['idcard', '', '', '', 'not_empty_check', '请输入身份证号码'],
  711. ['job', '', '', '', 'not_empty_check', '请输入职业'],
  712. ['photo', '', '', '', 'not_empty_check', '请上传照片'],
  713. ], $request, true);
  714. $res = Cert::add_cert($request->uid(), $name, $gender, $idcard, $job, $photo);
  715. if ($res) {
  716. return app('json')->success('申请成功');
  717. } else {
  718. return app('json')->fail(Cert::getErrorInfo());
  719. }
  720. }
  721. public function getCertList(Request $request)
  722. {
  723. $where = UtilService::getMore([
  724. ['status', ''],
  725. ['page', 1],
  726. ['limit', 10],
  727. ['uid', $request->uid()]
  728. ]);
  729. return app('json')->success('ok', ['list' => Cert::getList($where)]);
  730. }
  731. public function getCert(Request $request, $id = 0)
  732. {
  733. list($name) = UtilService::getMore([
  734. ['name', ''],
  735. ], $request, true);
  736. if ($id) {
  737. return app('json')->success('ok', ['info' => Cert::get($id)]);
  738. } else {
  739. return app('json')->success('ok', ['info' => Cert::search($name)]);
  740. }
  741. }
  742. }