Kirin 1 anno fa
parent
commit
61f7247642

+ 1 - 1
app/controller/api/v1/PublicController.php

@@ -699,7 +699,7 @@ class PublicController extends BaseController
             return app('json')->fail(AliAuthService::getError());
         }
         if ($info['passed'] == 'T') {
-            User::where(['uid' => $uid])->update(['is_auth' => 2, 'f_integral' => 3000, 'off' => "", 'is_new' => 1]);
+            User::where(['uid' => $uid])->update(['is_auth' => 2, 'off' => ""]);
         } else {
             User::where(['uid' => $uid])->update(['off' => AliAuthService::getCodeError($info['subCode']), 'is_auth' => "3"]);
         }

+ 26 - 14
app/controller/api/v1/user/UserExtractController.php

@@ -10,6 +10,7 @@
 // +----------------------------------------------------------------------
 namespace app\controller\api\v1\user;
 
+use app\model\user\User;
 use app\model\user\UserExtract;
 use app\Request;
 use app\services\user\UserExtractServices;
@@ -49,29 +50,40 @@ class UserExtractController
     public function cash_calculator(Request $request)
     {
         $fee = sys_data('withdraw_fee');
-        $fees = [];
-        foreach ($fee as $v) {
-            $fees[$v['month_number']] = (string)$v['fee'];
-        }
-        krsort($fees, SORT_DESC);
-        $sum_money = UserExtract::where('uid', $request->uid())
+        $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');
+        $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 = $request->post('money');
         $user_type = $request->post('user_type', 0);
         $extract_fee = 0;
         if ($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);
             }
         }
         return app('json')->success('ok', ['fee' => $extract_fee]);

+ 27 - 11
app/services/user/UserExtractServices.php

@@ -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 = [