1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060 |
- <?php
- namespace app\api\controller\user;
- use app\api\controller\trade\CashTradeController;
- use app\http\validates\user\AddressValidate;
- use app\models\system\SystemCity;
- use app\models\trade\CashTradeOrder;
- use app\models\user\UserBanks;
- use app\models\user\UserMoney;
- use app\models\user\UserVisit;
- use crmeb\services\CacheService;
- use crmeb\services\ZtPayService;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\Exception;
- use think\exception\ValidateException;
- use app\Request;
- use app\models\user\UserLevel;
- use app\models\user\UserSign;
- use app\models\store\StoreBargain;
- use app\models\store\StoreCombination;
- use app\models\store\StoreCouponUser;
- use app\models\store\StoreOrder;
- use app\models\store\StoreProductRelation;
- use app\models\store\StoreSeckill;
- use app\models\user\User;
- use app\models\user\UserAddress;
- use app\models\user\UserBill;
- use app\models\user\UserExtract;
- use app\models\user\UserNotice;
- use crmeb\services\GroupDataService;
- use crmeb\services\UtilService;
- class UserController
- {
-
- public function userInfo(Request $request)
- {
- $info = $request->user()->toArray();
- $info['statu'] = (int)sys_config('store_brokerage_statu');
- if (!$info['is_promoter'] && $info['statu'] == 2) {
- $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $info['uid']])->sum('pay_price');
- $status = is_brokerage_statu($price);
- if ($status) {
- User::where('uid', $info['uid'])->update(['is_promoter' => 1]);
- $info['is_promoter'] = 1;
- } else {
- $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
- $info['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
- }
- }
- $broken_time = intval(sys_config('extract_time'));
- $search_time = time() - 86400 * $broken_time;
-
- $brokerage_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
- ->where('add_time', '>', $search_time)
- ->where('pm', 1)
- ->sum('number');
-
- $refund_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
- ->where('add_time', '>', $search_time)
- ->where('pm', 0)
- ->sum('number');
- $info['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
- if ($info['broken_commission'] < 0)
- $info['broken_commission'] = 0;
- $info['commissionCount'] = bcsub($info['brokerage_price'], $info['broken_commission'], 2);
- if ($info['commissionCount'] < 0)
- $info['commissionCount'] = 0;
- return app('json')->success($info);
- }
-
- public function otherUserInfo(Request $request)
- {
- $uid = $request->get('uid', 0);
- $invite_code = $request->get('invite_code', '');
- if (!$uid && !$invite_code) return app('json')->success('ok', []);
- $model = new User();
- if ($uid) $model = $model->where('uid', $uid);
- if ($invite_code) $model = $model->where('invite_code', $invite_code);
- $info = $model->field('uid,nickname,phone,email,avatar')->find();
- return app('json')->success('ok', $info ? $info->toArray() : []);
- }
-
- public function balance(Request $request)
- {
- $uid = $request->uid();
- $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money'];
- $user['recharge'] = UserBill::getRecharge($uid);
- $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid);
- return app('json')->successful($user);
- }
-
- public function user(Request $request)
- {
- $user = $request->user();
- $user = $user->toArray();
- $info = $user;
- $info['statu'] = (int)sys_config('store_brokerage_statu');
- if (!$info['is_promoter'] && $info['statu'] == 2) {
- $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $info['uid']])->sum('pay_price');
- $status = is_brokerage_statu($price);
- if ($status) {
- User::where('uid', $info['uid'])->update(['is_promoter' => 1]);
- $info['is_promoter'] = 1;
- } else {
- $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
- $info['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
- }
- }
- $user = $info;
- $user['couponCount'] = StoreCouponUser::getUserValidCouponCount($user['uid']);
- $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
- $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']);
- $user['notice'] = UserNotice::getNotice($user['uid']);
- $user['recharge'] = UserBill::getRecharge($user['uid']);
- $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']);
- $user['extractTotalPrice'] = UserExtract::userExtractTotalPrice($user['uid']);
- $user['extractPrice'] = $user['brokerage_price'];
- $user['statu'] = (int)sys_config('store_brokerage_statu');
- $broken_time = intval(sys_config('extract_time'));
- $search_time = time() - 86400 * $broken_time;
- if (!$user['is_promoter'] && $user['statu'] == 2) {
- $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price');
- $status = is_brokerage_statu($price);
- if ($status) {
- User::where('uid', $user['uid'])->update(['is_promoter' => 1]);
- $user['is_promoter'] = 1;
- } else {
- $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
- $user['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
- }
- }
-
-
- $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
- ->where('add_time', '>', $search_time)
- ->where('pm', 1)
- ->sum('number');
-
- $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
- ->where('add_time', '>', $search_time)
- ->where('pm', 0)
- ->sum('number');
- $user['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
- if ($user['broken_commission'] < 0)
- $user['broken_commission'] = 0;
- $user['commissionCount'] = bcsub($user['brokerage_price'], $user['broken_commission'], 2);
- if ($user['commissionCount'] < 0)
- $user['commissionCount'] = 0;
- if (!sys_config('vip_open'))
- $user['vip'] = false;
- else {
- $vipId = UserLevel::getUserLevel($user['uid']);
- $user['vip'] = $vipId !== false ? true : false;
- if ($user['vip']) {
- $user['vip_id'] = $vipId;
- $user['vip_icon'] = UserLevel::getUserLevelInfo($vipId, 'icon');
- $user['vip_name'] = UserLevel::getUserLevelInfo($vipId, 'name');
- }
- }
- $user['yesterDay'] = UserBill::yesterdayCommissionSum($user['uid']);
- $user['recharge_switch'] = (int)sys_config('recharge_switch');
- $user['adminid'] = (boolean)\app\models\store\StoreService::orderServiceStatus($user['uid']);
- if ($user['phone'] && $user['user_type'] != 'h5') {
- $user['switchUserInfo'][] = $request->user();
- if ($h5UserInfo = User::where('account', $user['phone'])->where('user_type', 'h5')->find()) {
- $user['switchUserInfo'][] = $h5UserInfo;
- }
- } else if ($user['phone'] && $user['user_type'] == 'h5') {
- if ($wechatUserInfo = User::where('phone', $user['phone'])->where('user_type', '<>', 'h5')->find()) {
- $user['switchUserInfo'][] = $wechatUserInfo;
- }
- $user['switchUserInfo'][] = $request->user();
- } else if (!$user['phone']) {
- $user['switchUserInfo'][] = $request->user();
- }
- return app('json')->successful($user);
- }
-
- public function address(Request $request, $id)
- {
- $addressInfo = [];
- if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
- $addressInfo = UserAddress::find($id)->toArray();
- }
- return app('json')->successful($addressInfo);
- }
-
- public function address_list(Request $request)
- {
- list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true);
- $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default');
- return app('json')->successful($list);
- }
-
- public function address_default_set(Request $request)
- {
- list($id) = UtilService::getMore([['id', 0]], $request, true);
- if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
- if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
- return app('json')->fail('地址不存在!');
- $res = UserAddress::setDefaultAddress($id, $request->uid());
- if (!$res)
- return app('json')->fail('地址不存在!');
- else
- return app('json')->successful();
- }
-
- public function address_default(Request $request)
- {
- $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default');
- if ($defaultAddress) {
- $defaultAddress = $defaultAddress->toArray();
- return app('json')->successful('ok', $defaultAddress);
- }
- return app('json')->successful('empty', []);
- }
-
- public function address_edit(Request $request)
- {
- $addressInfo = UtilService::postMore([
- ['address', []],
- ['is_default', false],
- ['real_name', ''],
- ['post_code', ''],
- ['phone', ''],
- ['detail', ''],
- ['id', 0],
- ['type', 0]
- ], $request);
- if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!');
- if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!');
- if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!');
- if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) {
- return app('json')->fail('收货地址格式错误!请重新选择!');
- } else if ($addressInfo['type'] == 1 && !$addressInfo['id']) {
- $city = $addressInfo['address']['city'];
- $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id');
- if ($cityId) {
- $addressInfo['address']['city_id'] = $cityId;
- } else {
- if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) {
- return app('json')->fail('收货地址格式错误!修改后请重新导入!');
- }
- }
- }
- $addressInfo['province'] = $addressInfo['address']['province'];
- $addressInfo['city'] = $addressInfo['address']['city'];
- $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
- $addressInfo['district'] = $addressInfo['address']['district'];
- $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
- $addressInfo['uid'] = $request->uid();
- unset($addressInfo['address'], $addressInfo['type']);
- try {
- validate(AddressValidate::class)->check($addressInfo);
- } catch (ValidateException $e) {
- return app('json')->fail($e->getError());
- }
- if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
- $id = $addressInfo['id'];
- unset($addressInfo['id']);
- if (UserAddress::edit($addressInfo, $id, 'id')) {
- if ($addressInfo['is_default'])
- UserAddress::setDefaultAddress($id, $request->uid());
- return app('json')->successful();
- } else
- return app('json')->fail('编辑收货地址失败!');
- } else {
- $addressInfo['add_time'] = time();
- if ($address = UserAddress::create($addressInfo)) {
- if ($addressInfo['is_default']) {
- UserAddress::setDefaultAddress($address->id, $request->uid());
- }
- return app('json')->successful(['id' => $address->id]);
- } else {
- return app('json')->fail('添加收货地址失败!');
- }
- }
- }
-
- public function address_del(Request $request)
- {
- list($id) = UtilService::postMore([['id', 0]], $request, true);
- if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
- if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
- return app('json')->fail('地址不存在!');
- if (UserAddress::edit(['is_del' => '1'], $id, 'id'))
- return app('json')->successful();
- else
- return app('json')->fail('删除地址失败!');
- }
-
- public function collect_user(Request $request)
- {
- list($page, $limit) = UtilService::getMore([
- ['page', 0],
- ['limit', 0]
- ], $request, true);
- if (!(int)$limit) return app('json')->successful([]);
- $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit);
- return app('json')->successful($productRelationList);
- }
-
- public function collect_add(Request $request)
- {
- list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
- if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
- $res = StoreProductRelation::productRelation($id, $request->uid(), 'collect', $category);
- if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
- else return app('json')->successful();
- }
-
- public function collect_del(Request $request)
- {
- list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
- if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
- $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category);
- if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
- else return app('json')->successful();
- }
-
- public function collect_all(Request $request)
- {
- $collectInfo = UtilService::postMore([
- ['id', []],
- ['category', 'product'],
- ], $request);
- if (!count($collectInfo['id'])) return app('json')->fail('参数错误');
- $productIdS = $collectInfo['id'];
- $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['category']);
- if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
- else return app('json')->successful('收藏成功');
- }
-
-
-
- public function sign_config()
- {
- $signConfig = sys_data('sign_day_num') ?? [];
- return app('json')->successful($signConfig);
- }
-
- public function sign_list(Request $request)
- {
- list($page, $limit) = UtilService::getMore([
- ['page', 0],
- ['limit', 0]
- ], $request, true);
- if (!$limit) return app('json')->successful([]);
- $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit);
- if ($signList) $signList = $signList->toArray();
- return app('json')->successful($signList);
- }
-
- public function sign_integral(Request $request)
- {
- $signed = UserSign::getIsSign($request->uid());
- if ($signed) return app('json')->fail('已签到');
- if (false !== ($integral = UserSign::sign($request->uid())))
- return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]);
- return app('json')->fail(UserSign::getErrorInfo('签到失败'));
- }
-
- public function sign_user(Request $request)
- {
- list($sign, $integral, $all) = UtilService::postMore([
- ['sign', 0],
- ['integral', 0],
- ['all', 0],
- ], $request, true);
- $user = $request->user();
-
- if ($sign || $all) {
- $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']);
- $user['is_day_sgin'] = UserSign::getIsSign($user['uid']);
- $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday');
- if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) {
- $user['sign_num'] = 0;
- }
- }
-
- if ($integral || $all) {
- $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain');
- $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
- $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
- }
- unset($user['pwd']);
- if (!$user['is_promoter']) {
- $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == 2 ? true : false;
- }
- 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());
- }
-
- public function sign_month(Request $request)
- {
- list($page, $limit) = UtilService::getMore([
- ['page', 0],
- ['limit', 0]
- ], $request, true);
- if (!$limit) return app('json')->successful([]);
- $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
- return app('json')->successful($userSignList);
- }
-
- public function activity()
- {
- $data['is_bargin'] = StoreBargain::validBargain() ? true : false;
- $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false;
- $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false;
- return app('json')->successful($data);
- }
-
- public function edit(Request $request)
- {
- list($avatar, $nickname) = UtilService::postMore([
- ['avatar', ''],
- ['nickname', ''],
- ], $request, true);
- if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
- return app('json')->fail('修改失败');
- }
-
- public function rank(Request $request)
- {
- $data = UtilService::getMore([
- ['page', ''],
- ['limit', ''],
- ['type', '']
- ], $request);
- $users = User::getRankList($data);
- return app('json')->success($users);
- }
-
- public function brokerage_rank(Request $request)
- {
- $data = UtilService::getMore([
- ['page', ''],
- ['limit'],
- ['type']
- ], $request);
- return app('json')->success([
- 'rank' => User::brokerageRank($data),
- 'position' => User::currentUserRank($data['type'], $request->user()['brokerage_price'])
- ]);
- }
-
- public function set_visit(Request $request)
- {
- $data = UtilService::postMore([
- ['url', ''],
- ['stay_time', 0]
- ], $request);
- if ($data['url'] == '') return app('json')->fail('未获取页面路径');
- $data['uid'] = $request->uid();
- $data['ip'] = $request->ip();
- $data['add_time'] = time();
- $res = UserVisit::insert($data);
- if ($res) {
- return app('json')->success('添加访问记录成功');
- } else {
- return app('json')->fail('添加访问记录失败');
- }
- }
-
- public function set_main_account(Request $request)
- {
- if ($request->user()['main_uid'] != 0 && $request->user()['main_uid'] != $request->uid()) {
- return app('json')->fail('本账号已绑定主账号');
- }
- $user = User::where('account', $request->param('account'))->find();
- if ($user) {
- if ($user->pwd !== md5($request->param('password')))
- return app('json')->fail('目标账号或密码错误');
- } else {
- return app('json')->fail('目标账号或密码错误');
- }
- if (!$user['status'])
- return app('json')->fail('目标账号已被禁止,请联系管理员');
- if (!mobile_check($user['account'])) {
- return app('json')->fail('主账号必须为手机注册');
- }
- if ($user['main_uid'] != $user['uid'] && $user['main_uid'] != 0) {
- return app('json')->fail('目标账号已绑定作为其他账号的子账号');
- }
- if (User::where('main_uid', $request->uid())->count()) {
- return app('json')->fail('账号是主账号,不可绑定其他主账号');
- }
- if (User::where('main_uid', $user['uid'])->where('uid', '<>', $user['uid'])->count() >= sys_config('max_sub_account', 0)) {
- return app('json')->fail('目标账号子账号已达上限');
- }
- if ($user)
- $res = User::where('uid', $request->uid())->update(['main_uid' => $user['uid']]);
- if ($res) {
- return app('json')->success('绑定成功');
- } else
- return app('json')->fail('绑定失败');
- }
-
- public function spread(Request $request)
- {
- $puid = $request->post('puid/d', 0);
- return app('json')->success(User::setSpread($puid, $request->uid()));
- }
- public function realNameCheck(Request $request)
- {
- $user = $request->user();
- if ($user['real_check'] == 1) return app('json')->fail('账号或主账号已实名认证');
- list($idcard, $realname, $idcard_front, $idcard_hold, $idcard_back) = UtilService::postMore([['id_card', ''], ['real_name', ''], ['idcard_front', ''], ['idcard_hold', ''], ['idcard_back', '']], $request, true);
- $email_update = [];
- if ($user['email'] == '') {
- list($email, $captcha) = UtilService::postMore([['email', ''], ['captcha', '']], $request, true);
- if ($email) {
- if (User::be(['email' => $email])) {
- return app('json')->fail('邮箱已被绑定');
- }
- if (!$captcha) {
- return app('json')->fail('请输入验证码');
- }
- $verifyCode = CacheService::get('code_' . $email);
- if (!$verifyCode)
- return app('json')->fail('请先获取验证码');
- $verifyCode = substr($verifyCode, 0, 6);
- if ($verifyCode != $captcha)
- return app('json')->fail('验证码错误');
- $email_update['email'] = $email;
- } else return app('json')->fail('请绑定邮箱');
- }
- $update = array_merge([
- 'real_name' => $realname,
- 'card_id' => $idcard,
- 'real_check' => 0,
- 'idcard_front' => $idcard_front,
- 'idcard_hold' => $idcard_hold,
- 'idcard_back' => $idcard_back
- ], $email_update);
- try {
- $res = User::where('uid', $user['main_uid'] ?: $user['uid'])->update($update);
- if ($res) {
- return app('json')->success('已提交认证');
- } else {
- return app('json')->fail('提交失败');
- }
- } catch (Exception $e) {
- return app('json')->fail($e->getMessage());
- }
- }
-
- public function myWallet(Request $request)
- {
- $uid = $request->uid();
- $money_type = sys_data('money_type');
- $back = [];
- $like_rmb = 0;
- foreach ($money_type as $v) {
- $back[$v['code']] = $v;
- $back[$v['code']]['price'] = $back[$v['code']]['price'] > 0 ? $back[$v['code']]['price'] : CashTradeOrder::averagePrice($v['code']);
- $back[$v['code']]['money'] = UserMoney::initialUserMoney($uid, $v['code']);
- if (explode('_', $v['code'])[0] == "USDT") {
- $usdt_price = $back[$v['code']]['price'];
- }
- }
- $info = CacheService::redisHandler()->get('all_money');
- if (!$info) {
- (new CashTradeController())->all_money_redis();
- $info = CacheService::redisHandler()->get('all_money');
- }
- foreach ($back as $k => $v) {
- foreach ($info as $vv) {
- if ($vv['code'] == $v['code']) {
- $back[$k]['usdt'] = bcmul($back[$k]['money']['money'], $vv['usdt'], 2);
- $back[$k]['price'] = $vv['price'];
- $back[$k]['up'] = $vv['up'];
- $back[$k]['rmb'] = bcmul($back[$k]['money']['money'], $back[$k]['price'], 2);
- $like_rmb += $back[$k]['rmb'];
- }
- }
- }
- $like_usdt = 0;
- if (isset($usdt_price) && $usdt_price > 0) $like_usdt = bcdiv($like_rmb, $usdt_price, 8);
- return app('json')->success('ok', compact('back', 'like_rmb', 'like_usdt'));
- }
-
- public function setAddress($id, Request $request)
- {
- $key = $request->param('key', '');
- $money_type = UserMoney::get($id);
- if ($money_type['uid'] != $request->uid()) {
- return app('json')->fail('参数错误');
- }
- if (!$money_type || !$key) {
- return app('json')->fail('参数错误');
- }
- $money_type->address = $key;
- $res = $money_type->save();
- if ($res) {
- return app('json')->success('修改成功');
- } else {
- return app('json')->success('修改失败');
- }
- }
-
- public function createAddress($id, Request $request)
- {
- $money_type = UserMoney::get($id);
- if ($money_type['uid'] != $request->uid()) {
- return app('json')->fail('参数错误');
- }
- if (!$money_type) {
- return app('json')->fail('参数错误');
- }
- $res = ZtPayService::instance()->get_address($money_type['money_type']);
- if ($res['code'] != 0) {
- return app('json')->fail($res['message']);
- }
- $res = UserMoney::where('id', $id)->update(['address' => $res['data']['address']]);
- if ($res) {
- return app('json')->success('生成成功');
- } else {
- return app('json')->success('生成失败');
- }
- }
- public function myAccount(Request $request)
- {
- $user = $request->user();
- $uid = $user['uid'];
- if ($user['main_uid'] == 0) {
- $list = User::where('main_uid', $uid)->whereOr('uid', $uid)->select()->toArray();
- } else {
- $list = User::where('main_uid|uid', $user['main_uid'])->select()->toArray();
- }
- return app('json')->success('ok', $list);
- }
- public function myGroup(Request $request)
- {
- $user = $request->user();
- $uid = $user['uid'];
- $page = $request->get('page', 1);
- $limit = $request->get('limit', 10);
- $recommend_count = User::where('spread_uid', $uid)->count();
- $recommend_list = User::where('spread_uid', $uid)->page((int)$page, (int)$limit)->select()->each(function ($item) {
- $item['group_num'] = count(User::getAllLowUid($item['uid'], true));
- });
- $all_area = $user['achievement'];
- $small_area = bcsub(bcsub($user['achievement'], User::getBigAreaAchievement($uid), 8), $user['vote_num'], 8);
- $recommend_count_buy = User::where('spread_uid', $uid)->where('vote_num', '>', 0)->count();
- $group_count = count(User::getAllLowUid($uid, true));
- $group_count_buy = count(User::getAllLowUid($uid, $user['vote_num'] > 0, true));
- return app('json')->success('ok', compact('recommend_count', 'recommend_count_buy', 'group_count', 'group_count_buy', 'small_area', 'all_area', 'recommend_list'));
- }
- public function moneyLog($money_type, Request $request)
- {
- $user = $request->user();
- $uid = $user['uid'];
- $page = $request->get('page', 1);
- $limit = $request->get('limit', 10);
- $count = UserBill::where('uid', $uid)->where('category', $money_type)->count();
- $list = UserBill::where('uid', $uid)->where('category', $money_type)->page((int)$page, (int)$limit)->select()->each(function ($item) {
- $item['add_time'] = time_format($item['add_time']);
- });
- return app('json')->success('ok', compact('count', 'list'));
- }
- public function setMoneyAccount($type, Request $request)
- {
- list($real_name, $bank_code, $bank_address, $wechat_account, $alipay_account, $alipay_code, $wechat_code) = UtilService::postMore([
- ['real_name', '', '', '', ['not_empty_check'], ['请输入真实姓名']],
- ['bank_code', '', '', '', [function ($item) use ($type) {
- if ($type == 'bank') return not_empty_check($item);
- else return true;
- }], ['请输入银行卡号']],
- ['bank_address', '', '', '', [function ($item) use ($type) {
- if ($type == 'bank') return not_empty_check($item);
- else return true;
- }], ['请输入开户银行']],
- ['wechat_account', '', '', '', [function ($item) use ($type) {
- if ($type == 'wechat') return not_empty_check($item);
- else return true;
- }], ['请输入微信号']],
- ['alipay_account', '', '', '', [function ($item) use ($type) {
- if ($type == 'alipay') return not_empty_check($item);
- else return true;
- }], ['请输入支付宝帐号']],
- ['alipay_code', '', '', '', [function ($item) use ($type) {
- if ($type == 'alipay') return not_empty_check($item);
- else return true;
- }], ['请上传支付宝收款码']],
- ['wechat_code', '', '', '', [function ($item) use ($type) {
- if ($type == 'wechat') return not_empty_check($item);
- else return true;
- }], ['请上传微信收款码']],
- ], $request, true);
- switch ($type) {
- case 'bank':
- $bank_name = $real_name;
- $res = User::where('uid', $request->uid())->update(compact('bank_name', 'bank_code', 'bank_address'));
- break;
- case 'alipay':
- $alipay_name = $real_name;
- $res = User::where('uid', $request->uid())->update(compact('alipay_name', 'alipay_code', 'alipay_account'));
- break;
- case 'wechat':
- $wechat_name = $real_name;
- $res = User::where('uid', $request->uid())->update(compact('wechat_name', 'wechat_code', 'wechat_account'));
- break;
- default:
- $res = false;
- break;
- }
- if ($res) return app('json')->success('设置成功');
- else return app('json')->fail('设置失败');
- }
- public function banks(Request $request)
- {
- list($page, $limit, $type) = UtilService::getMore([['page', 0], ['limit', 20], ['type', 3]], $request, true);
- $list = UserBanks::getUserValidAddressList($request->uid(), $type, $page, $limit);
- return app('json')->successful($list);
- }
- public function bank($id, Request $request)
- {
- $addressInfo = [];
- if ($id && is_numeric($id) && UserBanks::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
- $addressInfo = UserBanks::find($id)->toArray();
- }
- return app('json')->successful($addressInfo);
- }
-
- public function bank_edit(Request $request)
- {
- $addressInfo = UtilService::postMore([
- ['code', '', '', '', ['not_empty_check'], ['请输入完整参数']],
- ['name', '', '', '', ['not_empty_check'], ['请输入完整参数']],
- ['account', '', '', '', ['not_empty_check'], ['请输入完整参数']],
- ['id', 0],
- ['type', 0, '', '', ['not_empty_check'], ['请选择类型']]
- ], $request);
- if ($addressInfo['id'] && UserBanks::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
- $id = $addressInfo['id'];
- unset($addressInfo['id']);
- if (UserBanks::edit($addressInfo, $id, 'id')) {
- return app('json')->successful();
- } else
- return app('json')->fail('编辑收款地址失败!');
- } else {
- $addressInfo['add_time'] = time();
- $addressInfo['uid'] = $request->uid();
- if ($address = UserBanks::create($addressInfo)) {
- return app('json')->successful();
- } else {
- return app('json')->fail('添加收款地址失败!');
- }
- }
- }
-
- public function bank_del(Request $request)
- {
- list($id) = UtilService::postMore([['id', 0]], $request, true);
- if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
- if (!UserBanks::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
- return app('json')->fail('地址不存在!');
- if (UserBanks::edit(['is_del' => '1'], $id, 'id'))
- return app('json')->successful();
- else
- return app('json')->fail('删除地址失败!');
- }
- }
|