lip 2 часов назад
Родитель
Сommit
8543bea288

+ 3 - 2
app/Http/Controllers/admin/RechargeChannel.php

@@ -39,10 +39,11 @@ class RechargeChannel extends Controller
         try {
         try {
             $params = request()->validate([
             $params = request()->validate([
                 'id' => ['nullable','integer'],
                 'id' => ['nullable','integer'],
-                'name' => ['nullable','string'],
-                'channel_ids' => ['nullable','string'],
+                'name' => ['required','string'],
+                'channel_ids' => ['required','array'],
             ]);
             ]);
             
             
+            $params['channel_ids'] = implode(',', $params['channel_ids']);
             if (empty($params['id'])) {
             if (empty($params['id'])) {
                 RechargeChannelGroup::create($params);
                 RechargeChannelGroup::create($params);
             } else {
             } else {

+ 18 - 10
app/Models/RechargeChannel.php

@@ -9,6 +9,11 @@ class RechargeChannel extends BaseModel
     protected $fillable = ['key', 'name', 'type', 'rate','min','max' ,'fixed' ,'sort'];
     protected $fillable = ['key', 'name', 'type', 'rate','min','max' ,'fixed' ,'sort'];
     protected $hidden = [];
     protected $hidden = [];
 
 
+    public function getFixedAttribute($value)
+    {
+        return $value ? explode(',', $value) : null; 
+    }
+
     //获取充值通道
     //获取充值通道
     public static function product($from = '')
     public static function product($from = '')
     {
     {
@@ -30,12 +35,12 @@ class RechargeChannel extends BaseModel
                 $where['id'] = ['in', $channel_ids];
                 $where['id'] = ['in', $channel_ids];
             }
             }
         }
         }
-        $product = self::where($where)->orderBy('sort', 'asc')->get()->toArray();
+        $product = self::where($where)->orderBy('sort', 'asc')->select(['name','type','min','max','fixed','rate'])->get()->toArray();
         
         
         $list = [];
         $list = [];
-        $config = [];
-        foreach($product as $pv) {
-            if ($config) {
+        foreach($product as $key => $pv) {
+            if (isset($list[$pv['type']]['config'])) {
+                $config = $list[$pv['type']]['config'];
                 if (empty($config['range'])) {
                 if (empty($config['range'])) {
                     $config['range'][] = $config;
                     $config['range'][] = $config;
                 }
                 }
@@ -56,13 +61,16 @@ class RechargeChannel extends BaseModel
             } else {
             } else {
                 $config = $pv;
                 $config = $pv;
             }
             }
+            
+            $list[$pv['type']] = [
+                'key' => $key,
+                'label' => lang($pv['name']),
+                'value' => $pv['type'],
+                'config' => $config ?? [],
+            ];
         }
         }
-        $list[] = [
-            'label' => lang($pv['type']),
-            'value' => $pv['type'],
-            'config' => $config ?? [],
-        ];
+        $list = array_column($list, null, 'key');
     
     
-        return $list;
+        return array_values($list);
     }
     }
 }
 }

+ 5 - 0
app/Models/RechargeChannelGroup.php

@@ -9,6 +9,11 @@ class RechargeChannelGroup extends BaseModel
     protected $fillable = ['name', 'channel_ids'];
     protected $fillable = ['name', 'channel_ids'];
     protected $hidden = [];
     protected $hidden = [];
 
 
+    public function getChannelIdsAttribute($value)
+    {
+        return $value ? explode(',', $value) : []; 
+    }
+
     public function rechargeChannel()
     public function rechargeChannel()
     {
     {
         return $this->hasMany(RechargeChannel::class, 'channel_ids', 'id');
         return $this->hasMany(RechargeChannel::class, 'channel_ids', 'id');