UserController.php 30 KB

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