UserController.php 29 KB

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