Просмотр исходного кода

支付筛选从按照渠道配置比例改成按照支付方式配置比例

Tree 7 часов назад
Родитель
Сommit
1c992a610c

+ 45 - 6
app/Http/Controllers/Admin/RechargeController.php

@@ -910,6 +910,10 @@ class RechargeController extends Controller
         $validator = Validator::make($request->all(), [
             'config.*.sort' => 'required|int',
             'config.*.status' => 'required|in:1,-1',
+            'config.*.weight.1' => 'nullable|int|min:0|max:100000',
+            'config.*.weight.2' => 'nullable|int|min:0|max:100000',
+            'config.*.weight.4' => 'nullable|int|min:0|max:100000',
+            'config.*.weight.8' => 'nullable|int|min:0|max:100000',
         ]);
         if ($validator->fails()) {
             return apiReturnFail($validator->errors()->first());
@@ -922,13 +926,48 @@ class RechargeController extends Controller
             return apiReturnFail('权重值分配不正确');
         }
         foreach ($config as $id => $v) {
-            $v['admin_id'] = session('admin')['id'];
-            $v['updated_at'] = date('Y-m-d H:i:s');
-            if ($v['status'] == -1) {
-                $v['sort'] = 0;
+            $weightInput = $v['weight'] ?? null;
+            // 防御性处理:避免后续误把 weight 数组直接参与 update
+            unset($v['weight']);
+            $remarksRaw = DB::table('agent.dbo.admin_configs')->where('id', $id)->value('remarks');
+            $remarks = [];
+            if (!empty($remarksRaw)) {
+                $decoded = \GuzzleHttp\json_decode($remarksRaw, true);
+                if (is_array($decoded)) {
+                    $remarks = $decoded;
+                }
+            }
+            if (is_array($weightInput)) {
+                $existingWeights = $remarks['weight'] ?? ($remarks['weights'] ?? []);
+                if (!is_array($existingWeights)) {
+                    $existingWeights = [];
+                }
+                $methodWeights = $existingWeights;
+                foreach ([1, 2, 4, 8] as $methodKey) {
+                    if (array_key_exists($methodKey, $weightInput)) {
+                        $weightKey = 'type_' . $methodKey;
+                        if ($weightInput[$methodKey] === '' || $weightInput[$methodKey] === null) {
+                            $methodWeights[$weightKey] = 0;
+                        } else {
+                            $methodWeights[$weightKey] = (int)$weightInput[$methodKey];
+                        }
+                    }
+                }
+                $remarks['weight'] = $methodWeights;
+            }
+
+            $updateData = [
+                'sort' => (int)$v['sort'],
+                'status' => (int)$v['status'],
+                'admin_id' => session('admin')['id'],
+                'updated_at' => date('Y-m-d H:i:s'),
+                'remarks' => \GuzzleHttp\json_encode($remarks, JSON_UNESCAPED_UNICODE),
+            ];
+            if ((int)$v['status'] === -1) {
+                $updateData['sort'] = 0;
             }
-            DB::table('agent.dbo.admin_configs')->where('id', $id)->update($v);
-            if ($v['status'] == -1) {
+            DB::table('agent.dbo.admin_configs')->where('id', $id)->update($updateData);
+            if ((int)$v['status'] === -1) {
                 DB::table('QPPlatformDB.dbo.ChannelOpenRecharge')->where('ConfigID', $id)
                     ->update([
                         'sort' => 0,

+ 5 - 0
app/Http/Controllers/Game/PaymentEntryController.php

@@ -6,6 +6,7 @@ namespace App\Http\Controllers\Game;
 
 use App\Facade\TableName;
 use App\Http\Controllers\Api\BroQrController;
+use App\Notification\TelegramBot;
 use App\Services\PayMentService;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
@@ -77,6 +78,10 @@ class PaymentEntryController {
             $payServiceString = 'CoinPay';
         }else{
             $payServiceString = PayMentService::getServiceByPayMethod($query, $payAmt,$pay_method);
+            if (empty($payServiceString)) {
+                TelegramBot::getDefault()->sendProgramNotify("PayType ERROR Error PHP Code");
+                return apiReturnFail(['web.payment.paytype_error','PayType ERROR']);
+            }
         }
 
 

+ 40 - 12
app/Services/PayMentService.php

@@ -127,19 +127,27 @@ class PayMentService
         }
         $matrix = [];
         foreach ($services as $v) {
-            for ($i = 0; $i < $v->sort; $i++) {
-//                if(Redis::exists("PayErro_".$v->config_key)) continue;
-                if(!empty($v->remarks)&&$v->remarks!=null){
-                    $remarks=json_decode($v->remarks,true);
-                    // 按支付类型校验金额是否在允许范围内:不满足则跳过该渠道
-                    if(isset($remarks['limit'])){
-                        $typeKey='type_'.$pay_method;
-                        $limitConfig=$remarks['limit'][$typeKey]??null;
-                        if($limitConfig!==null && !self::isAmountInLimit($payAmt,$limitConfig)){
-                            continue;
-                        }
-                    }
+            $remarks = [];
+            if (!empty($v->remarks)) {
+                $decoded = json_decode($v->remarks, true);
+                if (is_array($decoded)) {
+                    $remarks = $decoded;
+                }
+            }
+            // 按支付类型校验金额是否在允许范围内:不满足则跳过该渠道
+            if (isset($remarks['limit'])) {
+                $typeKey = 'type_' . $pay_method;
+                $limitConfig = $remarks['limit'][$typeKey] ?? null;
+                if ($limitConfig !== null && !self::isAmountInLimit($payAmt, $limitConfig)) {
+                    continue;
                 }
+            }
+            // 新逻辑:优先按支付方式独立权重分配渠道;未配置时回退旧 sort 逻辑
+            $weight = self::resolveMethodWeight($remarks, $pay_method, (int)$v->sort);
+            if ($weight <= 0) {
+                continue;
+            }
+            for ($i = 0; $i < $weight; $i++) {
                 $matrix[] = $v->config_key;
             }
         }
@@ -154,6 +162,26 @@ class PayMentService
         return $res;
     }
 
+    /**
+     * 解析指定支付方式的渠道权重(从 remarks 读取),未配置时回退默认权重
+     * remarks 支持:
+     * {"weight":{"type_1":30,"type_2":20,"type_4":10,"type_8":40}}
+     * {"weights":{"type_1":30,"type_2":20}}
+     * @param array $remarks
+     * @param int $payMethod
+     * @param int $defaultWeight
+     * @return int
+     */
+    public static function resolveMethodWeight(array $remarks, $payMethod, $defaultWeight = 0)
+    {
+        $typeKey = 'type_' . (int)$payMethod;
+        $weightConfig = $remarks['weight'] ?? ($remarks['weights'] ?? null);
+        if (is_array($weightConfig) && array_key_exists($typeKey, $weightConfig)) {
+            return max(0, (int)$weightConfig[$typeKey]);
+        }
+        return max(0, (int)$defaultWeight);
+    }
+
     /**
      * 判断支付金额是否在 limit 配置的取值范围内
      * @param float $payAmt 支付金额

+ 106 - 21
resources/views/admin/recharge/config.blade.php

@@ -23,29 +23,86 @@
                     <div class="card">
                         <div class="card-body">
                             <h4 class="card-title">{{ __('auto.查看渠道') }}</h4>
+                            <div class="mb-2">
+                                <button type="button" class="btn btn-sm btn-outline-secondary" id="toggle-closed-btn">
+                                    显示已关闭渠道
+                                </button>
+                            </div>
 
-                                <form action="" method="post" class="form-inline form-ajax">
+                                <form action="" method="post" class="form-ajax">
                                     {!! csrf_field() !!}
-                                    @foreach($list as $k => $v)
-                                        <div style="margin: 5px 0; width: 100%;">
-                                            <div class="form-group">
-                                                <label for="">{{ __('auto.权重') }}:</label>
-                                                <input class="form-control" type="text"
-                                                       name="config[{{$v->id}}][sort]" value="{{$v->sort}}">
-                                                <label for="">{{ __('auto.渠道名称') }}:</label>
-                                                <input class="form-control" type="text" disabled value="{{ $v->name }}">
-                                                <label for="">{{ __('auto.当前状态') }}:</label>
-                                                @component('components.select', [
-                                                    'name' => "config[{$v->id}][status]",
-                                                    'class' => $v->status == 1 ? 'btn-primary' : 'btn-danger',
-                                                    'options' => [1 => __('auto.开启'), -1 => __('auto.关闭')],
-                                                    'default' => $v->status])
-                                                @endcomponent
-                                            </div>
-
-                                        </div>
-                                    @endforeach
-                                    <div>
+                                    <div class="table-responsive">
+                                        <table class="table table-bordered table-striped">
+                                            <thead>
+                                            <tr>
+                                                <th style="min-width: 80px;">ID</th>
+                                                <th style="min-width: 180px;">{{ __('auto.渠道名称') }}</th>
+                                                <th style="min-width: 120px;">Cash(1)</th>
+                                                <th style="min-width: 120px;">PayPal(2)</th>
+                                                <th style="min-width: 120px;">Apple(4)</th>
+                                                <th style="min-width: 120px;">Google(8)</th>
+                                                <th style="min-width: 150px;">{{ __('auto.当前状态') }}</th>
+                                            </tr>
+                                            </thead>
+                                            <tbody>
+                                            @foreach($list as $k => $v)
+                                                @php
+                                                    $remarks = [];
+                                                    if (!empty($v->remarks)) {
+                                                        $decoded = \GuzzleHttp\json_decode($v->remarks, true);
+                                                        if (is_array($decoded)) {
+                                                            $remarks = $decoded;
+                                                        }
+                                                    }
+                                                    $weights = $remarks['weight'] ?? ($remarks['weights'] ?? []);
+                                                    $payTypes = (int)($v->pay_types ?? 0);
+                                                @endphp
+                                                <tr data-status="{{ (int)$v->status }}">
+                                                    <td>{{ $v->id }}</td>
+                                                    <td>{{ $v->name }}</td>
+                                                    <input type="hidden" name="config[{{$v->id}}][sort]" value="{{$v->sort}}">
+                                                    <td>
+                                                        <input class="form-control form-control-sm" type="number" min="0"
+                                                               name="config[{{$v->id}}][weight][1]"
+                                                               value="{{ $weights['type_1'] ?? '' }}"
+                                                               placeholder="{{ (($payTypes & 1) === 1) ? '0' : 'N/A' }}"
+                                                               {{ (($payTypes & 1) === 1) ? '' : 'disabled' }}>
+                                                    </td>
+                                                    <td>
+                                                        <input class="form-control form-control-sm" type="number" min="0"
+                                                               name="config[{{$v->id}}][weight][2]"
+                                                               value="{{ $weights['type_2'] ?? '' }}"
+                                                               placeholder="{{ (($payTypes & 2) === 2) ? '0' : 'N/A' }}"
+                                                               {{ (($payTypes & 2) === 2) ? '' : 'disabled' }}>
+                                                    </td>
+                                                    <td>
+                                                        <input class="form-control form-control-sm" type="number" min="0"
+                                                               name="config[{{$v->id}}][weight][4]"
+                                                               value="{{ $weights['type_4'] ?? '' }}"
+                                                               placeholder="{{ (($payTypes & 4) === 4) ? '0' : 'N/A' }}"
+                                                               {{ (($payTypes & 4) === 4) ? '' : 'disabled' }}>
+                                                    </td>
+                                                    <td>
+                                                        <input class="form-control form-control-sm" type="number" min="0"
+                                                               name="config[{{$v->id}}][weight][8]"
+                                                               value="{{ $weights['type_8'] ?? '' }}"
+                                                               placeholder="{{ (($payTypes & 8) === 8) ? '0' : 'N/A' }}"
+                                                               {{ (($payTypes & 8) === 8) ? '' : 'disabled' }}>
+                                                    </td>
+                                                    <td>
+                                                        @component('components.select', [
+                                                            'name' => "config[{$v->id}][status]",
+                                                            'class' => $v->status == 1 ? 'btn-primary' : 'btn-danger',
+                                                            'options' => [1 => __('auto.开启'), -1 => __('auto.关闭')],
+                                                            'default' => $v->status])
+                                                        @endcomponent
+                                                    </td>
+                                                </tr>
+                                            @endforeach
+                                            </tbody>
+                                        </table>
+                                    </div>
+                                    <div class="mt-3">
                                         <button class="btn btn-sm btn-primary">{{ __('auto.提交') }}</button>
                                     </div>
                                 </form>
@@ -55,4 +112,32 @@
             </div>
         </div>
     </div>
+    <script>
+        (function () {
+            var showClosed = false;
+            var btn = document.getElementById('toggle-closed-btn');
+            if (!btn) return;
+
+            function renderRows() {
+                var rows = document.querySelectorAll('tr[data-status]');
+                for (var i = 0; i < rows.length; i++) {
+                    var row = rows[i];
+                    var status = parseInt(row.getAttribute('data-status') || '0', 10);
+                    if (!showClosed && status === -1) {
+                        row.style.display = 'none';
+                    } else {
+                        row.style.display = '';
+                    }
+                }
+                btn.textContent = showClosed ? '隐藏已关闭渠道' : '显示已关闭渠道';
+            }
+
+            btn.addEventListener('click', function () {
+                showClosed = !showClosed;
+                renderRows();
+            });
+
+            renderRows();
+        })();
+    </script>
 @endsection

+ 13 - 2
resources/views/admin/recharge/methods.blade.php

@@ -61,8 +61,8 @@
                                                 <button type="button" class="btn btn-sm btn-primary" onclick="switch_control({{$v->id}},'on')">{{ __('auto.开启') }}</button>
                                             @endif
                                             <button class="btn btn-sm btn-gradient-dark" onclick="updatePic({{ $v->id }})">{{ __('auto.修改图片') }}</button>
-                                            <a class="btn btn-sm btn-gradient-dark layer-dialog"
-                                               href="/admin/recharge/config/{{$v->config_key}}">{{ __('auto.查看渠道') }}</a>
+                                            <button type="button" class="btn btn-sm btn-gradient-dark"
+                                                    onclick="openConfig('{{ $v->config_key }}')">{{ __('auto.查看渠道') }}</button>
                                         </td>
                                     </tr>
                                 @endforeach
@@ -129,5 +129,16 @@
             });
         }
 
+        function openConfig(configKey) {
+            layer.open({
+                type: 2,
+                title: '{{ __('auto.查看渠道') }}',
+                shadeClose: true,
+                shade: 0.8,
+                area: ['92%', '90%'],
+                content: '/admin/recharge/config/' + configKey
+            });
+        }
+
     </script>
 @endsection