lip 49 minuuttia sitten
vanhempi
sitoutus
0354183131
2 muutettua tiedostoa jossa 13 lisäystä ja 2 poistoa
  1. 2 2
      app/Http/Controllers/admin/RechargeChannel.php
  2. 11 0
      app/Models/RechargeChannel.php

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

@@ -14,7 +14,7 @@ class RechargeChannel extends Controller
     //获取充值方式
     public function getChannel()
     {
-        $channel = RechargeChannelModel::where('status', 1)->select(['type','name'])->get()->toArray();
+        $channel = RechargeChannelModel::getChannel();
         return $this->success(['total' => count($channel), 'data' => $channel]);
     }
 
@@ -33,7 +33,7 @@ class RechargeChannel extends Controller
                 ->forPage($page, $limit)
                 ->get();
             foreach($list as &$item) {
-                $item->rechargeChannel = RechargeChannelModel::whereIn('type', $item['type'])->get();
+                $item->rechargeChannel = RechargeChannelModel::getChannel($item['type']);
             }
         } catch (Exception $e) {
             return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());

+ 11 - 0
app/Models/RechargeChannel.php

@@ -14,6 +14,17 @@ class RechargeChannel extends BaseModel
         return $value ? explode(',', $value) : null; 
     }
 
+    public static function getChannel($type = [])
+    {
+        $query = self::where('status', 1);
+        if ($type) {
+            $query = $query->whereIn('type', $type);
+        }
+        $channel = $query->select(['type','name'])->get()->toArray();
+        $channel = array_column($channel, null, 'type');
+        return $channel;
+    }
+
     //获取充值通道
     public static function product($from = '')
     {