lip 1 hour ago
parent
commit
df460916c3

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

@@ -11,6 +11,13 @@ use App\Constants\HttpStatus;
 class RechargeChannel extends Controller
 {
 
+    //获取充值方式
+    public function getChannel()
+    {
+        $channel = RechargeChannelModel::where('status', 1)->select(['type','name'])->get()->toArray();
+        return $this->success(['total' => count($channel), 'data' => $channel]);
+    }
+
     /**
      * 充值通道组合列表
      */
@@ -26,7 +33,7 @@ class RechargeChannel extends Controller
                 ->forPage($page, $limit)
                 ->get();
             foreach($list as &$item) {
-                $item->rechargeChannel = RechargeChannelModel::whereIn('id', $item['channel_ids'])->get();
+                $item->rechargeChannel = RechargeChannelModel::whereIn('type', $item['type'])->get();
             }
         } catch (Exception $e) {
             return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
@@ -43,10 +50,10 @@ class RechargeChannel extends Controller
             $params = request()->validate([
                 'id' => ['nullable','integer'],
                 'name' => ['required','string'],
-                'channel_ids' => ['required','array'],
+                'type' => ['required','string'],
             ]);
             
-            $params['channel_ids'] = implode(',', $params['channel_ids']);
+            $params['type'] = implode(',', $params['type']);
             if (empty($params['id'])) {
                 RechargeChannelGroup::create($params);
             } else {

+ 5 - 4
app/Models/RechargeChannel.php

@@ -6,7 +6,7 @@ class RechargeChannel extends BaseModel
 {
 
     protected $table = 'recharge_channel';
-    protected $fillable = ['key', 'name', 'type', 'rate','min','max' ,'fixed' ,'sort'];
+    protected $fillable = ['id','key', 'name', 'type', 'rate','min','max' ,'fixed' ,'sort'];
     protected $hidden = [];
 
     public function getFixedAttribute($value)
@@ -27,14 +27,15 @@ class RechargeChannel extends BaseModel
 
     public static function getFormatChannel($recharge_channel_group_id = '')
     {
-        $where['status'] = 1;
+        $query = self::where(['status' => 1]);
+        
         if ($recharge_channel_group_id) {
             $channel_ids = RechargeChannelGroup::where('id', $recharge_channel_group_id)->value('channel_ids');
             if ($channel_ids) {
-                $where['id'] = ['in', $channel_ids];
+                $query = $query->whereIn('id', $channel_ids);
             }
         }
-        $product = self::where($where)->orderBy('sort', 'asc')->select(['name','type','min','max','fixed','rate'])->get()->toArray();
+        $product = $query->orderBy('sort', 'asc')->select(['id','name','type','min','max','fixed','rate'])->get()->toArray();
         
         $list = [];
         foreach($product as $key => $pv) {

+ 4 - 4
app/Models/RechargeChannelGroup.php

@@ -5,19 +5,19 @@ namespace App\Models;
 class RechargeChannelGroup extends BaseModel
 {
     protected $table = 'recharge_channel_group';
-    protected $fillable = ['name', 'channel_ids'];
+    protected $fillable = ['name', 'type'];
     protected $hidden = [];
 
     // 修改器:将逗号分隔字符串转为数组
-    public function getChannelIdsAttribute($value)
+    public function getTypeAttribute($value)
     {
         return $value ? explode(',', $value) : []; 
     }
 
     // 设置器:将数组转为逗号分隔字符串
-    public function setChannelIdsAttribute($value)
+    public function setTypeAttribute($value)
     {
-        $this->attributes['channel_ids'] = is_array($value) ? implode(',', $value) : $value;
+        $this->attributes['type'] = is_array($value) ? implode(',', $value) : $value;
     }
 
 }

+ 1 - 0
routes/admin.php

@@ -207,6 +207,7 @@ Route::middleware(['admin.jwt'])->group(function () {
             Route::post("/update", [RechargeChannel::class, 'update']);
             Route::get("/groupList", [RechargeChannel::class, 'groupList']);
             Route::post("/updateGroup", [RechargeChannel::class, 'updateGroup']);
+            Route::get("/getChannel", [RechargeChannel::class, 'getChannel']);
 
         });