|
|
@@ -436,11 +436,14 @@ class UserExtractServices extends BaseServices
|
|
|
if (!$user) {
|
|
|
throw new ValidateException('数据不存在');
|
|
|
}
|
|
|
- if (UserExtract::where('uid', $user['uid'])
|
|
|
+ if ($user['is_auth'] != 2) return app('json')->fail('请先完成实名认证');
|
|
|
+ $uids = $userService->search()->where('card_id', $user['card_id'])->column('uid');
|
|
|
+ if (UserExtract::where('uid', 'in', $uids)
|
|
|
->whereTime('add_time', 'month')
|
|
|
->where('status', 0)->find()) {
|
|
|
- throw new ValidateException('请等待上次提现申请通过');
|
|
|
+ throw new ValidateException('请等待身份证下上次提现申请通过');
|
|
|
}
|
|
|
+
|
|
|
// if (!$user['enterprise_professional_facilitator_id']) {
|
|
|
// throw new ValidateException('签约未完成');
|
|
|
// }
|
|
|
@@ -482,23 +485,36 @@ class UserExtractServices extends BaseServices
|
|
|
$fees[$v['month_number']] = (string)$v['fee'];
|
|
|
}
|
|
|
krsort($fees, SORT_DESC);
|
|
|
- $sum_money = UserExtract::where('uid', $user['uid'])
|
|
|
+ $sum_money = UserExtract::where('uid', 'in', $uids)
|
|
|
->whereTime('add_time', 'month')
|
|
|
->where('extract_type', '<>', 'balance')
|
|
|
->where('status', 1)->sum('extract_price');
|
|
|
+ $sum_fee = UserExtract::where('uid', 'in', $uids)
|
|
|
+ ->whereTime('add_time', 'month')
|
|
|
+ ->where('extract_type', '<>', 'balance')
|
|
|
+ ->where('status', 1)->sum('extract_fee');
|
|
|
$money = $data['money'];
|
|
|
$extract_fee = 0;
|
|
|
if ($data['user_type'] == 0) {
|
|
|
- $max = PHP_INT_MAX;
|
|
|
- foreach ($fees as $k => $v) {
|
|
|
- if ($sum_money > $max) {
|
|
|
- break;
|
|
|
+ $money_sum = bcadd((string)$sum_money, (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'];
|
|
|
+ }
|
|
|
}
|
|
|
- $max = $k;
|
|
|
- if ($sum_money + $money > $k) {
|
|
|
- $extract_fee = bcadd((string)$extract_fee, bcmul((string)($sum_money + $money - ($sum_money > $k ? $sum_money : $k)), bcdiv($v, '100', 4), 2));
|
|
|
- $money = $money - ($sum_money + $money - $k);
|
|
|
+ }
|
|
|
+ if ($range != []) {
|
|
|
+ if ($range['free_type'] == 1) {
|
|
|
+ $free = bcdiv(bcmul((string)$money_sum, (string)$range['free']), '100', 2);
|
|
|
+ } else {
|
|
|
+ $free = $range;
|
|
|
}
|
|
|
+ $the_fee = bcdiv(bcmul(bcsub((string)$money_sum, (string)$free, 2), (string)$range['fee']), '100', 2);
|
|
|
+ $extract_fee = bcsub((string)$the_fee, (string)$sum_fee, 2);
|
|
|
}
|
|
|
}
|
|
|
$insertData = [
|