123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\api\v1\user;
- use app\model\user\User;
- use app\model\user\UserExtract;
- use app\Request;
- use app\services\user\UserExtractServices;
- use crmeb\services\WithdrawService;
- use think\facade\Config;
- /**
- * 提现类
- * Class UserExtractController
- * @package app\controller\api\user
- */
- class UserExtractController
- {
- protected $services = NUll;
- /**
- * UserExtractController constructor.
- * @param UserExtractServices $services
- */
- public function __construct(UserExtractServices $services)
- {
- $this->services = $services;
- }
- /**
- * 提现银行
- * @param Request $request
- * @return mixed
- */
- public function bank(Request $request)
- {
- $uid = (int)$request->uid();
- return app('json')->successful($this->services->bank($uid));
- }
- public function cash_calculator(Request $request)
- {
- $fee = sys_data('withdraw_fee');
- $user = User::where('uid', $request->uid())->find();
- if ($user['is_auth'] != 2) return app('json')->fail('请先完成实名认证');
- $uids = User::where('card_id', $user['card_id'])->column('uid');
- $money = $request->post('money');
- $user_type = $request->post('user_type', 0);
- $extract_fee = 0;
- if ($user_type == 0) {
- $sum_money = UserExtract::where('uid', 'in', $uids)
- ->whereTime('add_time', 'month')
- ->where('user_type', 0)
- ->where('extract_type', '<>', 'balance')
- ->where('status', 1)->sum('extract_price');
- $sum_fee = UserExtract::where('uid', 'in', $uids)
- ->whereTime('add_time', 'month')
- ->where('user_type', 0)
- ->where('extract_type', '<>', 'balance')
- ->where('status', 1)->sum('extract_fee');
- $money_sum = bcadd(bcadd((string)$sum_money, (string)$sum_fee, 2), (string)$money, 2);
- $max_range = 0;
- $range = [];
- foreach ($fee as $v) {
- if ($money_sum > $v['month_number']) {
- if ($max_range < $v['month_number']) {
- $range = $v;
- $max_range = $v['month_number'];
- }
- }
- }
- if ($range != []) {
- if ($range['free_type'] == 1) {
- $free = bcdiv(bcmul((string)$money_sum, (string)$range['free']), '100', 2);
- } else {
- $free = $range['free'];
- }
- $the_fee = bcdiv(bcmul(bcsub((string)$money_sum, (string)$free, 2), (string)$range['fee']), '100', 2);
- $the_fee = bcsub((string)$the_fee, (string)$range['dec'], 2);
- $extract_fee = bcsub((string)$the_fee, (string)$sum_fee, 2);
- }
- }
- return app('json')->success('ok', ['fee' => $extract_fee > 0 ? $extract_fee : 0]);
- }
- /**
- * 提现申请
- * @param Request $request
- * @return mixed
- */
- public function cash(Request $request)
- {
- $extractInfo = $request->postMore([
- ['alipay_code', ''],
- ['extract_type', 'bank'],
- ['money', 0],
- ['image', 0],
- ['name', ''],
- ['bankname', ''],
- ['cardnum', ''],
- ['weixin', ''],
- ['qrcode_url', ''],
- ['user_type', 0],
- ]);
- $extractType = Config::get('pay.extractType', []);
- if (!in_array($extractInfo['extract_type'], $extractType))
- return app('json')->fail('提现方式不存在');
- if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', (float)$extractInfo['money'])) return app('json')->fail('提现金额输入有误');
- if (!$extractInfo['cardnum'] == '')
- if (!preg_match('/^([1-9]{1})(\d{8}|\d{11}|\d{14}|\d{15}|\d{16}|\d{18})$/', $extractInfo['cardnum']))
- return app('json')->fail('银行卡号输入有误');
- if (!$extractInfo['image'])
- return app('json')->fail('请上传发票凭证');
- if ($extractInfo['extract_type'] == 'alipay') {
- if (!$extractInfo['alipay_code']) return app('json')->fail('请输入支付宝账号');
- } else if ($extractInfo['extract_type'] == 'bank') {
- if (!$extractInfo['cardnum']) return app('json')->fail('请输入银行卡账号');
- if (!$extractInfo['bankname']) return app('json')->fail('请输入开户行信息');
- // $bank_info = WithdrawService::init()::contractInfo($user['enterprise_professional_facilitator_id']);
- // if ($bank_info['is_contract']) {
- // return app('json')->fail('签约已完成');
- // }
- } else if ($extractInfo['extract_type'] == 'weixin' && sys_config('brokerage_type') == 0) {
- if (!$extractInfo['weixin']) return app('json')->fail('请输入微信账号');
- }
- $uid = (int)$request->uid();
- if ($this->services->cash($uid, $extractInfo))
- return app('json')->successful('申请提现成功!');
- else
- return app('json')->fail('提现失败');
- }
- }
|