123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace app\api\controller\user;
- use app\admin\model\system\SystemConfig;
- use app\models\store\StoreOrder;
- use app\models\user\UserBill;
- use app\models\user\UserExtract;
- use app\Request;
- use crmeb\services\UtilService;
- use crmeb\services\CacheService;
- /**
- * 提现类
- * Class UserExtractController
- * @package app\api\controller\user
- */
- class UserExtractController
- {
- /**
- * 提现银行
- * @param Request $request
- * @return mixed
- */
- public function bank(Request $request)
- {
- $user = $request->user();
- $broken_time = intval(sys_config('extract_time'));
- $search_time = time() - 86400 * $broken_time;
- //可提现佣金
- //返佣 +
- $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');
- $data['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
- if ($data['broken_commission'] < 0)
- $data['broken_commission'] = 0;
- // return $data;
- $data['brokerage_price'] = $user['brokerage_price'];
- //可提现佣金
- $data['commissionCount'] = $data['brokerage_price'] - $data['broken_commission'];
- $extractBank = sys_config('user_extract_bank') ?? []; //提现银行
- $extractBank = str_replace("\r\n", "\n", $extractBank);//防止不兼容
- $data['extractBank'] = explode("\n", is_array($extractBank) ? (isset($extractBank[0]) ? $extractBank[0] : $extractBank) : $extractBank);
- $data['minPrice'] = sys_config('user_extract_min_price');//提现最低金额
- return app('json')->successful($data);
- }
- /**
- * 提现申请
- * @param Request $request
- * @return mixed
- */
- public function cash(Request $request)
- {
- $extractInfo = UtilService::postMore([
- ['type'],
- ['alipay_code', ''],
- ['extract_type', ''],
- ['money', 0],
- ['name', ''],
- ['bankname', ''],
- ['cardnum', ''],
- ['weixin', ''],
- ], $request);
- if ($extractInfo['money'] < 50) return app('json')->fail('最少提现50');
- $extract = UserExtract::where('uid', $request->uid())->where('status', '<', 0)->whereBetweenTime('add_time', strtotime('today'), strtotime('tomorrow'))->count();
- if ($extract >= 3) return app('json')->fail('今天提现错误3次,请明天再提现');
- if (cache($request->uid())) return app('json')->fail('请勿频繁点击');
- if (!preg_match('/^\\d+(\\.\\d+)?$/', $extractInfo['money'])) return app('json')->fail('提现金额输入有误');
- $user = $request->user();
- $broken_time = intval(sys_config('extract_time'));
- $search_time = time() - 86400 * $broken_time;
- //可提现佣金
- //返佣 +
- $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
- ->where('add_time', '>', $search_time)
- ->where('pm', 1)
- ->where('status', 1)
- ->sum('number');
- //退款退的佣金 -
- $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
- ->where('add_time', '>', $search_time)
- ->where('pm', 0)
- ->where('status', 1)
- ->sum('number');
- $data['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
- if ($data['broken_commission'] < 0)
- $data['broken_commission'] = 0;
- $data['brokerage_price'] = $user['brokerage_price'];
- //可提现佣金
- // $commissionCount = $data['brokerage_price'] - $data['broken_commission'];
- // if ($extractInfo['money'] > $commissionCount) return app('json')->fail('可提现佣金不足');
- if (!$extractInfo['cardnum'] == '')
- if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $extractInfo['cardnum']))
- return app('json')->fail('银行卡号输入有误');
- cache($request->uid(), 1, 5);
- if (UserExtract::userExtract($request->user(), $extractInfo))
- return app('json')->successful('申请提现成功!');
- else
- return app('json')->fail(UserExtract::getErrorInfo('提现失败'));
- }
- }
|