UserController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\http\validates\user\AddressValidate;
  4. use app\models\store\StoreService;
  5. use app\models\system\Card;
  6. use app\models\system\CardInfo;
  7. use app\models\system\SystemCity;
  8. use app\models\system\SystemStore;
  9. use app\models\system\SystemStoreMember;
  10. use app\models\user\UserAli;
  11. use app\models\user\UserBank;
  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. $search_time = date("Y-m-d H:i:s",$search_time);
  47. //返佣 +
  48. $brokerage_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  49. ->where('add_time', '>', $search_time)
  50. ->where('pm', 1)
  51. ->sum('number');
  52. //退款退的佣金 -
  53. $refund_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  54. ->where('add_time', '>', $search_time)
  55. ->where('pm', 0)
  56. ->sum('number');
  57. $info['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  58. if ($info['broken_commission'] < 0)
  59. $info['broken_commission'] = 0;
  60. $info['commissionCount'] = bcsub($info['brokerage_price'], $info['broken_commission'], 2);
  61. if ($info['commissionCount'] < 0)
  62. $info['commissionCount'] = 0;
  63. $info['service'] = StoreService::orderServiceStatus($request->uid());
  64. if(empty($info['SN']))
  65. {
  66. $max = intval(User::value('max(sn)'))+1;
  67. $sn = str_pad($max,8,"0",STR_PAD_LEFT);
  68. User::edit(['SN'=>$sn],$info['uid']);
  69. $info['SN'] = $sn;
  70. }
  71. if($info['level']==1) {
  72. $info['vip'] = SystemStoreMember::where('uid', $info['uid'])->find();
  73. $info['store_name'] = SystemStore::where('id',$info['reg_store_id'])->value('name');
  74. }
  75. else
  76. {
  77. $info['vip'] = [];
  78. $info['store_name'] = [];
  79. }
  80. return app('json')->success($info);
  81. }
  82. /**
  83. * 用户资金统计
  84. * @param Request $request
  85. * @return mixed
  86. * @throws \think\Exception
  87. * @throws \think\db\exception\DataNotFoundException
  88. * @throws \think\db\exception\ModelNotFoundException
  89. * @throws \think\exception\DbException
  90. */
  91. public function balance(Request $request)
  92. {
  93. $uid = $request->uid();
  94. $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money'];//当前总资金
  95. $user['recharge'] = UserBill::getRecharge($uid);//累计充值
  96. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid);//累计消费
  97. return app('json')->successful($user);
  98. }
  99. /**
  100. * 个人中心
  101. * @param Request $request
  102. * @return mixed
  103. */
  104. public function user(Request $request)
  105. {
  106. $user = $request->user();
  107. $user = $user->toArray();
  108. $user['couponCount'] = StoreCouponUser::getUserValidCouponCount($user['uid']);
  109. $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
  110. $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']);
  111. $user['notice'] = UserNotice::getNotice($user['uid']);
  112. // $user['brokerage'] = UserBill::getBrokerage($user['uid']);//获取总佣金
  113. $user['recharge'] = UserBill::getRecharge($user['uid']);//累计充值
  114. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']);//累计消费
  115. $user['extractTotalPrice'] = UserExtract::userExtractTotalPrice($user['uid']);//累计提现
  116. $user['extractPrice'] = $user['brokerage_price'];//可提现
  117. $user['statu'] = (int)sys_config('store_brokerage_statu');
  118. $broken_time = intval(sys_config('extract_time'));
  119. $search_time = time() - 86400 * $broken_time;
  120. if (!$user['is_promoter'] && $user['statu'] == 2) {
  121. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price');
  122. $status = is_brokerage_statu($price);
  123. if ($status) {
  124. User::where('uid', $user['uid'])->update(['is_promoter' => 1]);
  125. $user['is_promoter'] = 1;
  126. } else {
  127. $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
  128. $user['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
  129. }
  130. }
  131. //可提现佣金
  132. //返佣 +
  133. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  134. ->where('add_time', '>', $search_time)
  135. ->where('pm', 1)
  136. ->sum('number');
  137. //退款退的佣金 -
  138. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  139. ->where('add_time', '>', $search_time)
  140. ->where('pm', 0)
  141. ->sum('number');
  142. $user['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  143. if ($user['broken_commission'] < 0)
  144. $user['broken_commission'] = 0;
  145. $user['commissionCount'] = bcsub($user['brokerage_price'], $user['broken_commission'], 2);
  146. if ($user['commissionCount'] < 0)
  147. $user['commissionCount'] = 0;
  148. if (!sys_config('vip_open'))
  149. $user['vip'] = false;
  150. else {
  151. $vipId = UserLevel::getUserLevel($user['uid']);
  152. $user['vip'] = $vipId !== false ? true : false;
  153. if ($user['vip']) {
  154. $user['vip_id'] = $vipId;
  155. $user['vip_icon'] = UserLevel::getUserLevelInfo($vipId, 'icon');
  156. $user['vip_name'] = UserLevel::getUserLevelInfo($vipId, 'name');
  157. }
  158. }
  159. $user['yesterDay'] = UserBill::yesterdayCommissionSum($user['uid']);
  160. $user['recharge_switch'] = (int)sys_config('recharge_switch');//充值开关
  161. $user['adminid'] = (boolean)\app\models\store\StoreService::orderServiceStatus($user['uid']);
  162. if ($user['phone'] && $user['user_type'] != 'h5') {
  163. $user['switchUserInfo'][] = $request->user();
  164. if ($h5UserInfo = User::where('account', $user['phone'])->where('user_type', 'h5')->find()) {
  165. $user['switchUserInfo'][] = $h5UserInfo;
  166. }
  167. } else if ($user['phone'] && $user['user_type'] == 'h5') {
  168. if ($wechatUserInfo = User::where('phone', $user['phone'])->where('user_type', '<>', 'h5')->find()) {
  169. $user['switchUserInfo'][] = $wechatUserInfo;
  170. }
  171. $user['switchUserInfo'][] = $request->user();
  172. } else if (!$user['phone']) {
  173. $user['switchUserInfo'][] = $request->user();
  174. }
  175. return app('json')->successful($user);
  176. }
  177. /**
  178. * 地址 获取单个
  179. * @param Request $request
  180. * @param $id
  181. * @return mixed
  182. * @throws \think\db\exception\DataNotFoundException
  183. * @throws \think\db\exception\ModelNotFoundException
  184. * @throws \think\exception\DbException
  185. */
  186. public function address(Request $request, $id)
  187. {
  188. $addressInfo = [];
  189. if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
  190. $addressInfo = UserAddress::find($id)->toArray();
  191. }
  192. return app('json')->successful($addressInfo);
  193. }
  194. /**
  195. * 地址列表
  196. * @param Request $request
  197. * @param $page
  198. * @param $limit
  199. * @return mixed
  200. */
  201. public function address_list(Request $request)
  202. {
  203. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true);
  204. $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default,longitude,latitude');
  205. return app('json')->successful($list);
  206. }
  207. /**
  208. * 设置默认地址
  209. *
  210. * @param Request $request
  211. * @return mixed
  212. */
  213. public function address_default_set(Request $request)
  214. {
  215. list($id) = UtilService::getMore([['id', 0]], $request, true);
  216. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  217. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  218. return app('json')->fail('地址不存在!');
  219. $res = UserAddress::setDefaultAddress($id, $request->uid());
  220. if (!$res)
  221. return app('json')->fail('地址不存在!');
  222. else
  223. return app('json')->successful();
  224. }
  225. /**
  226. * 获取默认地址
  227. * @param Request $request
  228. * @return mixed
  229. */
  230. public function address_default(Request $request)
  231. {
  232. $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default,longitude,latitude');
  233. if ($defaultAddress) {
  234. $defaultAddress = $defaultAddress->toArray();
  235. return app('json')->successful('ok', $defaultAddress);
  236. }
  237. return app('json')->successful('empty', []);
  238. }
  239. /**
  240. * 修改 添加地址
  241. * @param Request $request
  242. * @return mixed
  243. */
  244. public function address_edit(Request $request)
  245. {
  246. $addressInfo = UtilService::postMore([
  247. ['address', []],
  248. ['is_default', false],
  249. ['real_name', ''],
  250. ['post_code', ''],
  251. ['phone', ''],
  252. ['detail', ''],
  253. ['id', 0],
  254. ['type', 0],
  255. ['city_id',0],
  256. ['longitude',''],
  257. ['latitude',''],
  258. ], $request);
  259. if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!');
  260. if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!');
  261. if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!');
  262. if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) {
  263. return app('json')->fail('收货地址格式错误!请重新选择!');
  264. } else if ($addressInfo['type'] == 1 && !$addressInfo['id']) {
  265. $city = $addressInfo['address']['city'];
  266. $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id');
  267. if ($cityId) {
  268. $addressInfo['address']['city_id'] = $cityId;
  269. } else {
  270. if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) {
  271. return app('json')->fail('收货地址格式错误!修改后请重新导入!');
  272. }
  273. }
  274. }
  275. $addressInfo['province'] = $addressInfo['address']['province'];
  276. $addressInfo['city'] = $addressInfo['address']['city'];
  277. $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
  278. $addressInfo['district'] = $addressInfo['address']['district'];
  279. $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
  280. $addressInfo['uid'] = $request->uid();
  281. unset($addressInfo['address'], $addressInfo['type']);
  282. try {
  283. validate(AddressValidate::class)->check($addressInfo);
  284. } catch (ValidateException $e) {
  285. return app('json')->fail($e->getError());
  286. }
  287. //编辑
  288. if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
  289. $id = $addressInfo['id'];
  290. unset($addressInfo['id']);
  291. if ($addressInfo['city_id'] == 0)
  292. unset($addressInfo['city_id']);
  293. if (UserAddress::edit($addressInfo, $id, 'id')) {
  294. if ($addressInfo['is_default'])
  295. UserAddress::setDefaultAddress($id, $request->uid());
  296. return app('json')->successful();
  297. } else
  298. return app('json')->fail('编辑收货地址失败!');
  299. } else {
  300. $addressInfo['add_time'] = time();
  301. if ($address = UserAddress::create($addressInfo)) {
  302. if ($addressInfo['is_default']) {
  303. UserAddress::setDefaultAddress($address->id, $request->uid());
  304. }
  305. return app('json')->successful(['id' => $address->id]);
  306. } else {
  307. return app('json')->fail('添加收货地址失败!');
  308. }
  309. }
  310. }
  311. /**
  312. * 删除地址
  313. *
  314. * @param Request $request
  315. * @return mixed
  316. */
  317. public function address_del(Request $request)
  318. {
  319. list($id) = UtilService::postMore([['id', 0]], $request, true);
  320. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  321. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  322. return app('json')->fail('地址不存在!');
  323. if (UserAddress::edit(['is_del' => '1'], $id, 'id'))
  324. return app('json')->successful();
  325. else
  326. return app('json')->fail('删除地址失败!');
  327. }
  328. /**
  329. * 获取收藏产品
  330. *
  331. * @param Request $request
  332. * @return mixed
  333. */
  334. public function collect_user(Request $request)
  335. {
  336. list($page, $limit) = UtilService::getMore([
  337. ['page', 0],
  338. ['limit', 0]
  339. ], $request, true);
  340. if (!(int)$limit) return app('json')->successful([]);
  341. $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit);
  342. return app('json')->successful($productRelationList);
  343. }
  344. /**
  345. * 添加收藏
  346. * @param Request $request
  347. * @param $id
  348. * @param $category
  349. * @return mixed
  350. */
  351. public function collect_add(Request $request)
  352. {
  353. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  354. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  355. $res = StoreProductRelation::productRelation($id, $request->uid(), 'collect', $category);
  356. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  357. else return app('json')->successful();
  358. }
  359. /**
  360. * 取消收藏
  361. *
  362. * @param Request $request
  363. * @return mixed
  364. */
  365. public function collect_del(Request $request)
  366. {
  367. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  368. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  369. $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category);
  370. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  371. else return app('json')->successful();
  372. }
  373. /**
  374. * 批量收藏
  375. * @param Request $request
  376. * @return mixed
  377. */
  378. public function collect_all(Request $request)
  379. {
  380. $collectInfo = UtilService::postMore([
  381. ['id', []],
  382. ['category', 'product'],
  383. ], $request);
  384. if (!count($collectInfo['id'])) return app('json')->fail('参数错误');
  385. $productIdS = $collectInfo['id'];
  386. $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['category']);
  387. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  388. else return app('json')->successful('收藏成功');
  389. }
  390. /**
  391. * 添加点赞
  392. *
  393. * @param Request $request
  394. * @return mixed
  395. */
  396. // public function like_add(Request $request)
  397. // {
  398. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  399. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  400. // $res = StoreProductRelation::productRelation($id,$request->uid(),'like',$category);
  401. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  402. // else return app('json')->successful();
  403. // }
  404. /**
  405. * 取消点赞
  406. *
  407. * @param Request $request
  408. * @return mixed
  409. */
  410. // public function like_del(Request $request)
  411. // {
  412. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  413. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  414. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  415. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  416. // else return app('json')->successful();
  417. // }
  418. /**
  419. * 签到 配置
  420. * @return mixed
  421. * @throws \think\db\exception\DataNotFoundException
  422. * @throws \think\db\exception\ModelNotFoundException
  423. * @throws \think\exception\DbException
  424. */
  425. public function sign_config()
  426. {
  427. $signConfig = sys_data('sign_day_num') ?? [];
  428. return app('json')->successful($signConfig);
  429. }
  430. /**
  431. * 签到 列表
  432. * @param Request $request
  433. * @param $page
  434. * @param $limit
  435. * @return mixed
  436. */
  437. public function sign_list(Request $request)
  438. {
  439. list($page, $limit) = UtilService::getMore([
  440. ['page', 0],
  441. ['limit', 0]
  442. ], $request, true);
  443. if (!$limit) return app('json')->successful([]);
  444. $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit);
  445. if ($signList) $signList = $signList->toArray();
  446. return app('json')->successful($signList);
  447. }
  448. /**
  449. * 签到
  450. * @param Request $request
  451. * @return mixed
  452. */
  453. public function sign_integral(Request $request)
  454. {
  455. $signed = UserSign::getIsSign($request->uid());
  456. if ($signed) return app('json')->fail('已签到');
  457. if (false !== ($integral = UserSign::sign($request->uid())))
  458. return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]);
  459. return app('json')->fail(UserSign::getErrorInfo('签到失败'));
  460. }
  461. /**
  462. * 签到用户信息
  463. * @param Request $request
  464. * @return mixed
  465. */
  466. public function sign_user(Request $request)
  467. {
  468. list($sign, $integral, $all) = UtilService::postMore([
  469. ['sign', 0],
  470. ['integral', 0],
  471. ['all', 0],
  472. ], $request, true);
  473. $user = $request->user();
  474. //是否统计签到
  475. if ($sign || $all) {
  476. $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']);
  477. $user['is_day_sgin'] = UserSign::getIsSign($user['uid']);
  478. $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday');
  479. if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) {
  480. $user['sign_num'] = 0;
  481. }
  482. }
  483. //是否统计积分使用情况
  484. if ($integral || $all) {
  485. $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain');
  486. $refund_integral = (int)UserBill::where(['uid' => $user['uid'], 'category' => 'integral', 'status' => 1, 'pm' => 0])->where('type', 'in', 'sign,system_add,gain')->sum('number');
  487. if ($user['sum_integral'] > $refund_integral)
  488. $user['sum_integral'] = $user['sum_integral'] - $refund_integral;
  489. else
  490. $user['sum_integral'] = 0;
  491. $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
  492. $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
  493. }
  494. unset($user['pwd']);
  495. if (!$user['is_promoter']) {
  496. $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == 2 ? true : false;
  497. }
  498. 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());
  499. }
  500. /**
  501. * 签到列表(年月)
  502. *
  503. * @param Request $request
  504. * @return mixed
  505. */
  506. public function sign_month(Request $request)
  507. {
  508. list($page, $limit) = UtilService::getMore([
  509. ['page', 0],
  510. ['limit', 0]
  511. ], $request, true);
  512. if (!$limit) return app('json')->successful([]);
  513. $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
  514. return app('json')->successful($userSignList);
  515. }
  516. /**
  517. * 获取活动状态
  518. * @return mixed
  519. */
  520. public function activity()
  521. {
  522. $data['is_bargin'] = StoreBargain::validBargain() ? true : false;
  523. $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false;
  524. $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false;
  525. return app('json')->successful($data);
  526. }
  527. /**
  528. * 用户修改信息
  529. * @param Request $request
  530. * @return mixed
  531. */
  532. public function edit(Request $request)
  533. {
  534. list($avatar, $nickname) = UtilService::postMore([
  535. ['avatar', ''],
  536. ['nickname', ''],
  537. ], $request, true);
  538. if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
  539. return app('json')->fail('修改失败');
  540. }
  541. /**
  542. * 推广人排行
  543. * @param Request $request
  544. * @return mixed
  545. * @throws \think\db\exception\DataNotFoundException
  546. * @throws \think\db\exception\ModelNotFoundException
  547. * @throws \think\exception\DbException
  548. */
  549. public function rank(Request $request)
  550. {
  551. $data = UtilService::getMore([
  552. ['page', ''],
  553. ['limit', ''],
  554. ['type', '']
  555. ], $request);
  556. $users = User::getRankList($data);
  557. return app('json')->success($users);
  558. }
  559. /**
  560. * 佣金排行
  561. * @param Request $request
  562. * @return mixed
  563. */
  564. public function brokerage_rank(Request $request)
  565. {
  566. $data = UtilService::getMore([
  567. ['page', ''],
  568. ['limit'],
  569. ['type']
  570. ], $request);
  571. $users = User::brokerageRank($data);
  572. foreach ($users as $key => $item) {
  573. if ($item['brokerage_price'] == '0.00' || $item['brokerage_price'] == 0 || !$item['brokerage_price']) {
  574. unset($users[$key]);
  575. }
  576. }
  577. $position_tmp = User::brokerageRank(['type' => $data['type'], 'page' => 0, 'limit' => 99999]);
  578. $position_tmp_one = array_column($position_tmp, 'uid');
  579. $position_tmp_two = array_column($position_tmp, 'brokerage_price', 'uid');
  580. if (!in_array($request->uid(), $position_tmp_one)) {
  581. $position = 0;
  582. } else {
  583. if ($position_tmp_two[$request->uid()] == 0.00) {
  584. $position = 0;
  585. } else {
  586. $position = array_search($request->uid(), $position_tmp_one) + 1;
  587. }
  588. }
  589. return app('json')->success([
  590. 'rank' => $users,
  591. 'position' => $position
  592. ]);
  593. }
  594. /**
  595. * 设置银行卡
  596. * @param Request $request
  597. */
  598. public function bank_edit(Request $request)
  599. {
  600. $data = UtilService::postMore([
  601. ['fullname',''],
  602. ['bank',''],
  603. ['bankno',''],
  604. ['subbranch',''],
  605. ['default',0],
  606. ['id',0],
  607. ],$request);
  608. $data['uid'] = $request->uid();
  609. if(!$this->regtest('/^[\x{4e00}-\x{9fa5}]+$/u',$data['fullname'])) return app('json')->fail('输入完整姓名!');
  610. if(empty($data['bank'])) return app('json')->fail('选择银行');
  611. if(!$this->regtest('/^\d+$/u',$data['bankno'])) return app('json')->fail('输入银行卡!');
  612. if(intval($data['id'])==0)
  613. {
  614. unset($data['id']);
  615. UserBank::insert($data);
  616. }
  617. else
  618. {
  619. UserBank::update($data);
  620. }
  621. return app('json')->successful();
  622. }
  623. private function regtest($pattern,$value) {
  624. preg_match ( $pattern, $value, $match );
  625. if ($match) {
  626. return true;
  627. } else {
  628. return false;
  629. }
  630. }
  631. /**
  632. * 设置支付宝
  633. * @param Request $request
  634. */
  635. public function ali_edit(Request $request)
  636. {
  637. $data = UtilService::postMore([
  638. ['fullname',''],
  639. ['alino',''],
  640. ['default',0],
  641. ['id',0],
  642. ],$request);
  643. $data['uid'] = $request->uid();
  644. if(!$this->regtest('/^[\x{4e00}-\x{9fa5}]+$/u',$data['fullname'])) return app('json')->fail('输入完整姓名!');
  645. if(empty($data['alino'])) return app('json')->fail('输入支付宝账号');
  646. if(intval($data['id'])==0)
  647. {
  648. unset($data['id']);
  649. UserAli::insert($data);
  650. }
  651. else
  652. {
  653. UserAli::update($data);
  654. }
  655. return app('json')->successful();
  656. }
  657. /**
  658. * 获取银行卡信息
  659. */
  660. public function bankinfo(Request $request)
  661. {
  662. $row = Userbank::where('uid',$request->uid())->find();
  663. if($row)
  664. return app('json')->successful($row->toArray());
  665. else
  666. return app('json')->successful([]);
  667. }
  668. /**
  669. * 获取支付宝信息
  670. */
  671. public function aliinfo(Request $request)
  672. {
  673. $row = UserAli::where('uid',$request->uid())->find();
  674. if($row)
  675. return app('json')->successful($row->toArray());
  676. else
  677. return app('json')->successful([]);
  678. }
  679. /**
  680. * 兑换卡券
  681. * @param Request $request
  682. */
  683. public function verification(Request $request)
  684. {
  685. list($card_number,$card_password,$type,$is_confirm,$reg_store_id) = UtilService::postMore([
  686. ['card_number',''],
  687. ['card_password',''],
  688. ['type',0],
  689. ['is_confirm',0],
  690. ['reg_store_id',0],
  691. ],$request,true);
  692. $uid = $request->uid();
  693. if($type==1) {
  694. $user = $request->user();
  695. if ($user['reg_store_id'] > 0) {
  696. $reg_store_id = $user['reg_store_id'];
  697. }
  698. $uid = $request->uid();
  699. }
  700. $rs = CardInfo::verification($card_number,$card_password,$uid,$type,$reg_store_id,$is_confirm);
  701. if(!$rs) return app('json')->fail(CardInfo::getErrorInfo());
  702. if($is_confirm==0)
  703. {
  704. $info = CardInfo::where('card_number',$card_number)->field('card_id,card_number,create_time,amount')->find()->toArray();
  705. $info['title'] = Card::where('id',$info['card_id'])->value('title');
  706. return app('json')->successful($info);
  707. }
  708. else
  709. {
  710. return app('json')->successful('对换完成!');
  711. }
  712. }
  713. }