Ver Fonte

自动免审后台配置

Tree há 2 dias atrás
pai
commit
e8c2e23c7b

+ 70 - 18
app/Console/Commands/ExemptReview.php

@@ -10,7 +10,7 @@ use App\Models\AccountsInfo;
 use App\Models\Cpf;
 use App\Models\SystemStatusInfo;
 use App\Models\Withdrawal;
-use App\Models\WithdrawalChannelPositionConfig;
+use App\Models\WithdrawalAgentRatioConfig;
 use App\Services\CashService;
 use App\Util;
 use Illuminate\Console\Command;
@@ -57,8 +57,11 @@ class ExemptReview extends Command
         if(!$open)return;
 
         $WithdrawalModel = new Withdrawal();
-        $OrderWithDraw = DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('State', 1)
-            ->whereRaw('locking = 0')->orderBy('CreateDate', 'desc')->get();
+        $OrderWithDraw = DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')
+            ->where('State', 1)
+            ->whereRaw('locking = 0')
+            ->orderBy('CreateDate', 'desc')
+            ->get();
 
         foreach ($OrderWithDraw as $value) {
             if ($value->State != 1) {
@@ -94,10 +97,10 @@ class ExemptReview extends Command
                 $sameCountCheckIP = 100;
             }
 
-            if(($verifyRes==1||$verifyRes==9)&&$value->WithDraw!=1000){
-                Log::info('首次审核阻拦自动免审:'.$value->OrderId);
-                continue;
-            }
+//            if(($verifyRes==1||$verifyRes==9)&&$value->WithDraw!=1000){
+//                Log::info('首次审核阻拦自动免审:'.$value->OrderId);
+//                continue;
+//            }
 //            if ($AccountsInfoModel->sameWithDrawEmail($value->EmailAddress) > $sameCountCheck && ($value->WithDraw/NumConfig::NUM_VALUE)>20) {
 //                Log::info('EMAIL重复过多阻拦自动免审:'.$value->OrderId.":::".$value->EmailAddress);
 //                continue;
@@ -132,17 +135,7 @@ class ExemptReview extends Command
 //            $config = DB::table(TableName::agent().'withdrawal_position_config')->where('status', 1)->first();
             if (true) {
 
-                if($value->PixType == 2){
-                    rand(1,100)>60?$agent = 106:$agent = 100;
-//                    $agent = 100;
-                }else{
-                    if(($value->WithDraw/NumConfig::NUM_VALUE)<55){
-                        $agent = 106;
-                    }else{
-                        rand(1,100)>50?$agent = 100:$agent = 105;
-                        $agent = 105;
-                    }
-                }
+                $agent = $this->getWithdrawalAgent($value);
 //                $agent = 105;
                 $redis = Redis::connection();
                 $order_sn = $value->OrderId;
@@ -198,4 +191,63 @@ class ExemptReview extends Command
             }
         }
     }
+
+    private function getWithdrawalAgent($value)
+    {
+        $rules = WithdrawalAgentRatioConfig::getGlobal();
+        $pixType = $this->getWithdrawalAgentRuleKey($value);
+        $pixTypeRules = $rules[$pixType] ?? $rules[strval($pixType)] ?? [];
+        $agent = $this->randomAgentByRatio($pixTypeRules);
+
+        return $agent ?: $this->defaultWithdrawalAgent($value);
+    }
+
+    private function getWithdrawalAgentRuleKey($value)
+    {
+        if ((int)($value->PixType ?? 0) == 1 && ($value->WithDraw / NumConfig::NUM_VALUE) < 50) {
+            return WithdrawalAgentRatioConfig::PIX_TYPE_CASH_SMALL;
+        }
+
+        return (int)($value->PixType ?? 0);
+    }
+
+    private function randomAgentByRatio($rules)
+    {
+        if (empty($rules) || !is_array($rules)) {
+            return 0;
+        }
+
+        $total = 0;
+        foreach ($rules as $rule) {
+            $total += (int)($rule['ratio'] ?? 0);
+        }
+
+        if ($total <= 0) {
+            return 0;
+        }
+
+        $rand = random_int(1, $total);
+        $current = 0;
+        foreach ($rules as $rule) {
+            $current += (int)($rule['ratio'] ?? 0);
+            if ($rand <= $current) {
+                return (int)($rule['agent'] ?? 0);
+            }
+        }
+
+        return 0;
+    }
+
+    private function defaultWithdrawalAgent($value)
+    {
+        if ($value->PixType == 2) {
+            return 100;
+        }
+
+        if (($value->WithDraw / NumConfig::NUM_VALUE) < 55) {
+            return 106;
+        }
+
+        return 105;
+    }
 }

+ 121 - 34
app/Http/Controllers/Admin/ChannelController.php

@@ -12,9 +12,11 @@ use App\Http\logic\admin\RechargeLogic;
 use App\Jobs\ClearCache;
 use App\Models\AppSwitch;
 use App\Models\SystemStatusInfo;
+use App\Models\WithdrawalAgentRatioConfig;
 use App\Models\WithdrawalChannelPositionConfig;
 use App\Models\WithdrawalPositionConfig;
 use App\Services\GameRoomInfo;
+use App\Services\PayConfig;
 use App\Util;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
@@ -736,33 +738,20 @@ class ChannelController
                 ->where('type', 'cash')
                 ->where('status', 1)
                 ->get();
+            $this->markWithdrawalAgentFee($agent);
             return view('admin.channel.channel_withdrawal_configall', [
                 'config' => $config,
                 'agent' => $agent,
+                'ratioConfig' => WithdrawalAgentRatioConfig::getGlobal(),
+                'pixTypeOptions' => WithdrawalAgentRatioConfig::pixTypeOptions(),
             ]);
         }
 
-        $data = array_filter($request->all(), function ($item) {
-            return $item !== null && $item !== '';
-        });
-        $validator = Validator::make($data, [
-            'status' => 'required|in:1,2',
-            'agent' => 'required|integer',
-        ]);
-        if ($validator->fails()) {
-            return apiReturnFail($validator->errors()->first());
-        }
-//        $configs=WithdrawalChannelPositionConfig::query()->where('channel','<>',103)->get() ;
-        $configs=WithdrawalChannelPositionConfig::query()->get() ;
-        foreach ($configs as $config) {
-
-//            if($config->channel==103)continue;
-            $config->status = $request->input('status', 0);
-            $config->agent = $request->input('agent', 0);
-            $config->limit_manual_review_show = $request->input('limit_manual_review_show', 0);
-            $config->save();
-            //$config->update(['status'=>$request->input('status', 0),'agent'=>$request->input('agent', 0),'limit_manual_review_show'=>$request->input('limit_manual_review_show', 0)]);
+        list($ratioValid, $ratioRules) = $this->withdrawalAgentRatioRules($request);
+        if (!$ratioValid) {
+            return apiReturnFail($ratioRules);
         }
+        WithdrawalAgentRatioConfig::saveGlobal($ratioRules);
 
         return apiReturnSuc();
     }
@@ -799,31 +788,129 @@ class ChannelController
                 ->where('type', 'cash')
                 ->where('status', 1)
                 ->get();
+            $this->markWithdrawalAgentFee($agent);
             return view('admin.channel.channel_withdrawal_config', [
                 'config' => $config,
                 'agent' => $agent,
+                'ratioConfig' => WithdrawalAgentRatioConfig::getGlobal(),
+                'pixTypeOptions' => WithdrawalAgentRatioConfig::pixTypeOptions(),
             ]);
         }
 
-        $data = array_filter($request->all(), function ($item) {
-            return $item !== null && $item !== '';
-        });
-        $validator = Validator::make($data, [
-            'status' => 'required|in:1,2',
-            'agent' => 'required|integer',
-        ]);
-        if ($validator->fails()) {
-            return apiReturnFail($validator->errors()->first());
+        list($ratioValid, $ratioRules) = $this->withdrawalAgentRatioRules($request);
+        if (!$ratioValid) {
+            return apiReturnFail($ratioRules);
         }
-
-        $config->status = $request->input('status', 0);
-        $config->agent = $request->input('agent', 0);
-        $config->limit_manual_review_show = $request->input('limit_manual_review_show', 0);
-        $config->save();
+        WithdrawalAgentRatioConfig::saveGlobal($ratioRules);
 
         return apiReturnSuc();
     }
 
+    private function withdrawalAgentRatioRules(Request $request)
+    {
+        $input = $request->input('agent_ratio', []);
+        $rules = [];
+        $pixTypeNames = WithdrawalAgentRatioConfig::pixTypeOptions();
+
+        foreach ($pixTypeNames as $pixType => $pixTypeName) {
+            $total = 0;
+
+            foreach (($input[$pixType] ?? []) as $agent => $ratio) {
+                if ($ratio === null || $ratio === '') {
+                    $ratio = 0;
+                }
+
+                if (!is_numeric($ratio)) {
+                    return [false, $pixTypeName . '比例必须是数字'];
+                }
+
+                $ratio = (int)$ratio;
+                if ($ratio < 0 || $ratio > 100) {
+                    return [false, $pixTypeName . '比例必须在0-100之间'];
+                }
+
+                $total += $ratio;
+                if ($ratio > 0) {
+                    $rules[$pixType][(int)$agent] = $ratio;
+                }
+            }
+
+            if ($total != 100) {
+                return [false, $pixTypeName . '比例总和必须为100'];
+            }
+        }
+
+        return [true, $rules];
+    }
+
+    private function markWithdrawalAgentFee($agent)
+    {
+        foreach ($agent as $item) {
+            $item->withdraw_fee_texts = $this->withdrawalAgentFeeTexts($item->config_value);
+        }
+    }
+
+    private function withdrawalAgentFeeTexts($agent)
+    {
+        $configKey = $this->withdrawalPayConfigKey($agent);
+        $empty = [
+            1 => '-',
+            2 => '-',
+            WithdrawalAgentRatioConfig::PIX_TYPE_CASH_SMALL => '-',
+        ];
+
+        if (!$configKey) {
+            return $empty;
+        }
+
+        $config = (new PayConfig())->getConfig($configKey);
+        $payRates = $config['pay_rate'] ?? null;
+        if (empty($payRates) || !is_array($payRates)) {
+            return $empty;
+        }
+
+        if (is_array(reset($payRates))) {
+            return [
+                1 => isset($payRates[1]) ? $this->formatWithdrawalPayRate($payRates[1]) : '-',
+                2 => isset($payRates[2]) ? $this->formatWithdrawalPayRate($payRates[2]) : '-',
+                WithdrawalAgentRatioConfig::PIX_TYPE_CASH_SMALL => isset($payRates[1]) ? $this->formatWithdrawalPayRate($payRates[1]) : '-',
+            ];
+        }
+
+        $feeText = $this->formatWithdrawalPayRate($payRates);
+        return [
+            1 => $feeText,
+            2 => $feeText,
+            WithdrawalAgentRatioConfig::PIX_TYPE_CASH_SMALL => $feeText,
+        ];
+    }
+
+    private function withdrawalPayConfigKey($agent)
+    {
+        $map = [
+            99 => 'WiwiPayOut',
+            100 => 'WDPayOut',
+            103 => 'PagYeepPayOut',
+            105 => 'AiNewPayOut',
+            106 => 'SafePayOut',
+            107 => 'BotImPayOut',
+        ];
+
+        return $map[(int)$agent] ?? null;
+    }
+
+    private function formatWithdrawalPayRate($rate)
+    {
+        if (!is_array($rate)) {
+            return '-';
+        }
+
+        $percent = $rate[0] ?? 0;
+        $fixed = $rate[1] ?? 0;
+
+        return $percent . '%+$' . $fixed;
+    }
+
     public function quickCreateChannel(Request $request)
     {
         if ($request->isMethod('post')) {

+ 115 - 0
app/Models/WithdrawalAgentRatioConfig.php

@@ -0,0 +1,115 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Redis;
+
+class WithdrawalAgentRatioConfig
+{
+    const STATUS_NAME = 'WithdrawAgentRatioConfig';
+    const CACHE_KEY = 'withdrawal_agent_ratio_config';
+    const CACHE_TTL = 600;
+    const PIX_TYPE_CASH_SMALL = 'cash_small';
+
+    public static function pixTypeOptions()
+    {
+        return [
+            1 => 'CashApp',
+            2 => 'PayPal',
+            self::PIX_TYPE_CASH_SMALL => 'CashApp小额(<50)',
+        ];
+    }
+
+    public static function all()
+    {
+        $cache = Redis::get(self::CACHE_KEY);
+        if ($cache) {
+            $config = json_decode($cache, true);
+            if (is_array($config)) {
+                return $config;
+            }
+
+            self::clearCache();
+        }
+
+        $json = DB::table('QPAccountsDB.dbo.SystemStatusInfo')
+            ->where('StatusName', self::STATUS_NAME)
+            ->value('StatusString');
+
+        $config = json_decode($json ?: '', true);
+        $config = is_array($config) ? $config : [];
+
+        Redis::setex(self::CACHE_KEY, self::CACHE_TTL, json_encode($config));
+
+        return $config;
+    }
+
+    public static function getGlobal()
+    {
+        $config = self::all();
+
+        if (self::isRatioRules($config)) {
+            return $config;
+        }
+
+        return $config['100'] ?? $config[100] ?? [];
+    }
+
+    public static function saveGlobal(array $rules)
+    {
+        self::saveAll(self::normalizeRules($rules));
+    }
+
+    public static function clearCache()
+    {
+        Redis::del(self::CACHE_KEY);
+    }
+
+    public static function normalizeRules(array $rules)
+    {
+        $result = [];
+
+        foreach (array_keys(self::pixTypeOptions()) as $pixType) {
+            foreach (($rules[$pixType] ?? []) as $agent => $ratio) {
+                $ratio = (int)$ratio;
+                if ($ratio <= 0) {
+                    continue;
+                }
+
+                $result[$pixType][] = [
+                    'agent' => (int)$agent,
+                    'ratio' => $ratio,
+                ];
+            }
+        }
+
+        return $result;
+    }
+
+    private static function isRatioRules(array $config)
+    {
+        foreach (array_keys(self::pixTypeOptions()) as $pixType) {
+            if (isset($config[$pixType])) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    private static function saveAll(array $config)
+    {
+        DB::table('QPAccountsDB.dbo.SystemStatusInfo')->updateOrInsert(
+            ['StatusName' => self::STATUS_NAME],
+            [
+                'StatusValue' => 0,
+                'StatusString' => json_encode($config),
+                'StatusTip' => '提现免审代付比例配置',
+                'StatusDescription' => '按提现方式配置自动免审代付比例',
+            ]
+        );
+
+        self::clearCache();
+    }
+}

+ 66 - 81
resources/views/admin/channel/channel_withdrawal_config.blade.php

@@ -8,39 +8,34 @@
                     <div class="card">
                         <div class="card-body">
                             <h4 class="card-title">{{ __('auto.请填写配置信息') }}</h4>
+                            @php
+                                $ratioMap = [];
+                                foreach (($ratioConfig ?? []) as $pixType => $items) {
+                                    foreach ($items as $item) {
+                                        $ratioMap[$pixType][$item['agent']] = $item['ratio'];
+                                    }
+                                }
+                            @endphp
                             <form class="forms-sample" id="form">
-                                <div class="form-group">
-                                    <label for=""><h4>{{ __('auto.开关设置') }}</h4></label> <br>
-                                    <label> <input type="radio" name="status" id="optionsRadios2" value="1" @if ($config->status == 1)
-                                        checked
-                                            @endif> {{ __('auto.开启') }}</label>
-                                    <label> <input type="radio" name="status" id="optionsRadios2" value="2" @if ($config->status == 2)
-                                        checked
-                                            @endif> {{ __('auto.关闭') }}</label>
-                                </div>
-                                <div class="form-group">
-                                    <label for=""><h4>{{ __('auto.人工审核是否启用默认代付方') }}</h4></label>
-                                    <input type="radio" value="1" name="limit_manual_review_show"
-                                           @if ($config->limit_manual_review_show == 1)
-                                           checked
-                                        @endif> {{ __('auto.开启') }}
-                                    <input type="radio" value="0" name="limit_manual_review_show"
-                                           @if ($config->limit_manual_review_show == 0)
-                                           checked
-                                        @endif> {{ __('auto.关闭') }}
-                                </div>
-                                <div style="margin-top: 10px">
-                                    <span>{{ __('auto.请选择一个代付方') }}</span>
-                                    @foreach($agent as $val)
-                                        <div class="radio">
-                                            <label>
-                                                <input type="radio" value="{{$val->config_value}}" name="agent" @if ($config->agent == $val->config_value)
-                                                checked
-                                                    @endif>
-
-                                                {{$val->name}}
-                                            </label>
+                                <div class="form-group" style="margin-top: 20px">
+                                    <label for=""><h4>自动免审代付比例</h4></label>
+                                    <div class="alert alert-info">
+                                        CashApp、PayPal、CashApp小额(提现金额&lt;50)分别配置比例,每种提现方式下开启的比例总和必须为 100。
+                                    </div>
+                                    @foreach(($pixTypeOptions ?? [1 => 'CashApp', 2 => 'PayPal', 'cash_small' => 'CashApp小额(<50)']) as $pixType => $pixTypeName)
+                                        <h5>{{ $pixTypeName }}</h5>
+                                        <div class="row">
+                                            @foreach($agent as $val)
+                                                <div class="col-md-3" style="margin-bottom: 10px">
+                                                    <label>{{$val->name}} ({{$val->config_value}},费率:{{$val->withdraw_fee_texts[$pixType] ?? '-'}})</label>
+                                                    <input class="form-control agent-ratio" type="number" min="0" max="100"
+                                                           name="agent_ratio[{{$pixType}}][{{$val->config_value}}]"
+                                                           data-pix-type="{{$pixType}}"
+                                                           value="{{ $ratioMap[$pixType][$val->config_value] ?? 0 }}">
+                                                </div>
+                                            @endforeach
                                         </div>
+                                        <div class="ratio-total" data-pix-type="{{$pixType}}" style="margin-bottom: 10px"></div>
                                     @endforeach
                                 </div>
                                 <button type="button" onclick="commit({{ $config->channel }})"
@@ -68,59 +63,11 @@
                 return false;
             }
 
-            var data = $("#form").serializeObject();
-
-            if (! data.draw_bi_checkbox){
-                data.draw_bi = 0
-            }
-
-            if (! data.draw_gt_recharge_checkbox){
-                data.draw_gt_recharge = 0
-            }
-            if (! data.draw_total_checkbox){
-                data.draw_total = 0
-            }
-            if (! data.game_time_checkbox){
-                data.game_time = 0
-            }
-            if (! data.recharge_checkbox){
-                data.recharge_max = 0
-                data.recharge_min = 0
-            }
-            if (! data.draw_checkbox){
-                data.type = 0
-            }
-
-            let type = data.type
-
-            if (type == 1 && data.quota == '') {
-                layer.msg('{{ __('auto.固定额度不能为空') }}');
-                return false;
-            }
-            if (type == 2 && data.multiple == '') {
-                layer.msg('{{ __('auto.固定倍数不能为空') }}');
-                return false;
-            }
-
-            if (parseInt(data.recharge_min) > parseInt(data.recharge_max)) {
-                layer.msg('{{ __('auto.下限值不能大于上限') }}');
-                return false;
-            }
-
-            if (data.quota != '' && (data.quota < 0 || data.quota > 1000000)) {
-                layer.msg('{{ __('auto.固定额度区间为') }}0-1000000');
-                return false;
-            }
-
-            if (data.multiple != '' && (data.multiple < 1 || data.multiple > 100)) {
-                layer.msg('{{ __('auto.固定倍数区间为') }}1-100');
+            if (!checkAgentRatio()) {
                 return false;
             }
 
-            if (data.multiple != '' && type == 2) {
-                data.quota = data.multiple
-            }
-
+            var data = $("#form").serializeObject();
 
             myRequest("/admin/channel/withdrawal_config/"+id, "post", data, function (res) {
                 if (res.code == '200') {
@@ -137,5 +84,43 @@
         function cancel() {
             parent.location.reload();
         }
+
+        function checkAgentRatio() {
+            var pass = true;
+            var pixTypes = @json(array_keys($pixTypeOptions ?? [1 => 'CashApp', 2 => 'PayPal', 'cash_small' => 'CashApp小额(<50)']));
+            pixTypes.forEach(function (pixType) {
+                var total = 0;
+                $('.agent-ratio[data-pix-type="' + pixType + '"]').each(function () {
+                    total += parseInt($(this).val()) || 0;
+                });
+
+                if (total !== 100) {
+                    pass = false;
+                }
+            });
+
+            if (!pass) {
+                layer.msg('CashApp、PayPal、CashApp小额的比例总和都必须为100');
+            }
+
+            return pass;
+        }
+
+        $(document).ready(function () {
+            function refreshRatioTotal() {
+                var pixTypes = @json(array_keys($pixTypeOptions ?? [1 => 'CashApp', 2 => 'PayPal', 'cash_small' => 'CashApp小额(<50)']));
+                pixTypes.forEach(function (pixType) {
+                    var total = 0;
+                    $('.agent-ratio[data-pix-type="' + pixType + '"]').each(function () {
+                        total += parseInt($(this).val()) || 0;
+                    });
+
+                    $('.ratio-total[data-pix-type="' + pixType + '"]').text('当前总和:' + total + '%');
+                });
+            }
+
+            $('.agent-ratio').on('input', refreshRatioTotal);
+            refreshRatioTotal();
+        });
     </script>
 @endsection

+ 66 - 81
resources/views/admin/channel/channel_withdrawal_configall.blade.php

@@ -8,39 +8,34 @@
                     <div class="card">
                         <div class="card-body">
                             <h4 class="card-title">{{ __('auto.请填写配置信息') }}</h4>
+                            @php
+                                $ratioMap = [];
+                                foreach (($ratioConfig ?? []) as $pixType => $items) {
+                                    foreach ($items as $item) {
+                                        $ratioMap[$pixType][$item['agent']] = $item['ratio'];
+                                    }
+                                }
+                            @endphp
                             <form class="forms-sample" id="form">
-                                <div class="form-group">
-                                    <label for=""><h4>{{ __('auto.开关设置') }}</h4></label> <br>
-                                    <label> <input type="radio" name="status" id="optionsRadios2" value="1" @if ($config->status == 1)
-                                        checked
-                                            @endif> {{ __('auto.开启') }}</label>
-                                    <label> <input type="radio" name="status" id="optionsRadios2" value="2" @if ($config->status == 2)
-                                        checked
-                                            @endif> {{ __('auto.关闭') }}</label>
-                                </div>
-                                <div class="form-group">
-                                    <label for=""><h4>{{ __('auto.人工审核是否启用默认代付方') }}</h4></label>
-                                    <input type="radio" value="1" name="limit_manual_review_show"
-                                           @if ($config->limit_manual_review_show == 1)
-                                           checked
-                                        @endif> {{ __('auto.开启') }}
-                                    <input type="radio" value="0" name="limit_manual_review_show"
-                                           @if ($config->limit_manual_review_show == 0)
-                                           checked
-                                        @endif> {{ __('auto.关闭') }}
-                                </div>
-                                <div style="margin-top: 10px">
-                                    <span>{{ __('auto.请选择一个代付方') }}</span>
-                                    @foreach($agent as $val)
-                                        <div class="radio">
-                                            <label>
-                                                <input type="radio" value="{{$val->config_value}}" name="agent" @if ($config->agent == $val->config_value)
-                                                checked
-                                                    @endif>
-
-                                                {{$val->name}}
-                                            </label>
+                                <div class="form-group" style="margin-top: 20px">
+                                    <label for=""><h4>自动免审代付比例</h4></label>
+                                    <div class="alert alert-info">
+                                        CashApp、PayPal、CashApp小额(提现金额&lt;50)分别配置比例,每种提现方式下开启的比例总和必须为 100。
+                                    </div>
+                                    @foreach(($pixTypeOptions ?? [1 => 'CashApp', 2 => 'PayPal', 'cash_small' => 'CashApp小额(<50)']) as $pixType => $pixTypeName)
+                                        <h5>{{ $pixTypeName }}</h5>
+                                        <div class="row">
+                                            @foreach($agent as $val)
+                                                <div class="col-md-3" style="margin-bottom: 10px">
+                                                    <label>{{$val->name}} ({{$val->config_value}},费率:{{$val->withdraw_fee_texts[$pixType] ?? '-'}})</label>
+                                                    <input class="form-control agent-ratio" type="number" min="0" max="100"
+                                                           name="agent_ratio[{{$pixType}}][{{$val->config_value}}]"
+                                                           data-pix-type="{{$pixType}}"
+                                                           value="{{ $ratioMap[$pixType][$val->config_value] ?? 0 }}">
+                                                </div>
+                                            @endforeach
                                         </div>
+                                        <div class="ratio-total" data-pix-type="{{$pixType}}" style="margin-bottom: 10px"></div>
                                     @endforeach
                                 </div>
                                 <button type="button" onclick="commit({{ $config->channel }})"
@@ -68,59 +63,11 @@
                 return false;
             }
 
-            var data = $("#form").serializeObject();
-
-            if (! data.draw_bi_checkbox){
-                data.draw_bi = 0
-            }
-
-            if (! data.draw_gt_recharge_checkbox){
-                data.draw_gt_recharge = 0
-            }
-            if (! data.draw_total_checkbox){
-                data.draw_total = 0
-            }
-            if (! data.game_time_checkbox){
-                data.game_time = 0
-            }
-            if (! data.recharge_checkbox){
-                data.recharge_max = 0
-                data.recharge_min = 0
-            }
-            if (! data.draw_checkbox){
-                data.type = 0
-            }
-
-            let type = data.type
-
-            if (type == 1 && data.quota == '') {
-                layer.msg('{{ __('auto.固定额度不能为空') }}');
-                return false;
-            }
-            if (type == 2 && data.multiple == '') {
-                layer.msg('{{ __('auto.固定倍数不能为空') }}');
-                return false;
-            }
-
-            if (parseInt(data.recharge_min) > parseInt(data.recharge_max)) {
-                layer.msg('{{ __('auto.下限值不能大于上限') }}');
-                return false;
-            }
-
-            if (data.quota != '' && (data.quota < 0 || data.quota > 1000000)) {
-                layer.msg('{{ __('auto.固定额度区间为') }}0-1000000');
-                return false;
-            }
-
-            if (data.multiple != '' && (data.multiple < 1 || data.multiple > 100)) {
-                layer.msg('{{ __('auto.固定倍数区间为') }}1-100');
+            if (!checkAgentRatio()) {
                 return false;
             }
 
-            if (data.multiple != '' && type == 2) {
-                data.quota = data.multiple
-            }
-
+            var data = $("#form").serializeObject();
 
             myRequest("/admin/channel/withdrawal_configall", "post", data, function (res) {
                 if (res.code == '200') {
@@ -137,5 +84,43 @@
         function cancel() {
             parent.location.reload();
         }
+
+        function checkAgentRatio() {
+            var pass = true;
+            var pixTypes = @json(array_keys($pixTypeOptions ?? [1 => 'CashApp', 2 => 'PayPal', 'cash_small' => 'CashApp小额(<50)']));
+            pixTypes.forEach(function (pixType) {
+                var total = 0;
+                $('.agent-ratio[data-pix-type="' + pixType + '"]').each(function () {
+                    total += parseInt($(this).val()) || 0;
+                });
+
+                if (total !== 100) {
+                    pass = false;
+                }
+            });
+
+            if (!pass) {
+                layer.msg('CashApp、PayPal、CashApp小额的比例总和都必须为100');
+            }
+
+            return pass;
+        }
+
+        $(document).ready(function () {
+            function refreshRatioTotal() {
+                var pixTypes = @json(array_keys($pixTypeOptions ?? [1 => 'CashApp', 2 => 'PayPal', 'cash_small' => 'CashApp小额(<50)']));
+                pixTypes.forEach(function (pixType) {
+                    var total = 0;
+                    $('.agent-ratio[data-pix-type="' + pixType + '"]').each(function () {
+                        total += parseInt($(this).val()) || 0;
+                    });
+
+                    $('.ratio-total[data-pix-type="' + pixType + '"]').text('当前总和:' + total + '%');
+                });
+            }
+
+            $('.agent-ratio').on('input', refreshRatioTotal);
+            refreshRatioTotal();
+        });
     </script>
 @endsection