doge преди 7 часа
родител
ревизия
142a3a79c2

+ 8 - 3
app/Constants/Util.php

@@ -48,7 +48,7 @@ class Util
     {
         if (!filter_var($url, FILTER_VALIDATE_URL)) {
             if (empty($url)) return $url;
-            $newUrl = config('app.url') . $url;
+            $newUrl = rtrim(config('app.url'), '/') . '/' . ltrim($url, '/');
             return filter_var($newUrl, FILTER_VALIDATE_URL) ? $newUrl : $url;
         }
         return $url;
@@ -56,9 +56,14 @@ class Util
 
     public static function replacePartInUrl($url)
     {
+        if (empty($url) || !is_string($url)) {
+            return $url;
+        }
+
         if (filter_var($url, FILTER_VALIDATE_URL)) {
-            $target = config('app.url');
-            return str_replace($target, '', $url);
+            $path = parse_url($url, PHP_URL_PATH) ?: '';
+            $query = parse_url($url, PHP_URL_QUERY);
+            return $query ? "{$path}?{$query}" : $path;
         }
         return $url;
     }

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

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\admin;
 
+use App\Constants\Util;
 use App\Constants\HttpStatus;
 use App\Http\Controllers\Controller;
 use Illuminate\Support\Facades\DB;
@@ -76,7 +77,7 @@ class Banner extends Controller
                 ['id' => $id],
                 [
                     'title' => $params['title'],
-                    'image' => $params['image'],
+                    'image' => Util::replacePartInUrl($params['image']),
                     'link' => $params['link'],
                     'type' => $params['type'],
                     'sort' => $params['sort'],
@@ -128,4 +129,4 @@ class Banner extends Controller
     }
 
 
-}
+}

+ 3 - 2
app/Http/Controllers/api/Wallet.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\api;
 
+use App\Constants\Util;
 use App\Services\WalletService;
 use App\Services\ConfigService;
 use App\Models\Config;
@@ -137,7 +138,7 @@ class Wallet extends BaseController
             $recharge->to_address = $params['toAddress'];
             $recharge->status = 0;
             $recharge->type = 2;
-            $recharge->image = $params['image'];
+            $recharge->image = Util::replacePartInUrl($params['image']);
             $recharge->save();
             return $this->success($recharge,'提交成功');
 
@@ -491,4 +492,4 @@ class Wallet extends BaseController
         }
     }
 
-}
+}

+ 16 - 1
app/Models/ActivityReward.php

@@ -32,6 +32,21 @@ class ActivityReward extends BaseModel
         return Util::ensureUrl($value);
     }
 
+    protected function setDetailImageAttribute($value)
+    {
+        $this->attributes['detail_image'] = Util::replacePartInUrl($value);
+    }
+
+    protected function getPcImageAttribute($value)
+    {
+        return Util::ensureUrl($value);
+    }
+
+    protected function setPcImageAttribute($value)
+    {
+        $this->attributes['pc_image'] = Util::replacePartInUrl($value);
+    }
+
     protected function getStartTimeAttribute($value): string
     {
         return date('Y-m-d', $value);
@@ -42,4 +57,4 @@ class ActivityReward extends BaseModel
         return date('Y-m-d', $value);
     }
 
-}
+}

+ 6 - 1
app/Models/ActivityUser.php

@@ -48,6 +48,11 @@ class ActivityUser extends BaseModel
         return Util::ensureUrl($value);
     }
 
+    protected function setDetailImageAttribute($value)
+    {
+        $this->attributes['detail_image'] = Util::replacePartInUrl($value);
+    }
+
     protected function getPartInTimeAttribute($value): string
     {
         return date('Y-m-d H:i:s', $value);
@@ -71,4 +76,4 @@ class ActivityUser extends BaseModel
     {
         return date('Y-m-d', $value);
     }
-}
+}

+ 6 - 1
app/Models/Banner.php

@@ -11,4 +11,9 @@ class Banner extends BaseModel
     {
         return Util::ensureUrl($value);
     }
-}
+
+    protected function setImageAttribute($value)
+    {
+        $this->attributes['image'] = Util::replacePartInUrl($value);
+    }
+}

+ 13 - 1
app/Models/Keyboard.php

@@ -2,6 +2,8 @@
 
 namespace App\Models;
 
+use App\Constants\Util;
+
 /**
  * @property $group_id
  * @property $id
@@ -17,4 +19,14 @@ class Keyboard extends BaseModel
 {
     protected $table = 'keyboard';
     protected $fillable = ['button', 'group_id', 'reply', 'id', 'buttons', 'image', 'language', 'explain'];
-}
+
+    protected function getImageAttribute($value)
+    {
+        return Util::ensureUrl($value);
+    }
+
+    protected function setImageAttribute($value)
+    {
+        $this->attributes['image'] = Util::replacePartInUrl($value);
+    }
+}

+ 5 - 0
app/Models/Recharge.php

@@ -40,4 +40,9 @@ class Recharge extends BaseModel
     {
         return Util::ensureUrl($value);
     }
+
+    protected function setImageAttribute($value)
+    {
+        $this->attributes['image'] = Util::replacePartInUrl($value);
+    }
 }

+ 14 - 1
app/Models/RoomUser.php

@@ -1,5 +1,8 @@
 <?php
 namespace App\Models;
+
+use App\Constants\Util;
+
 class RoomUser extends BaseModel
 {
     protected $table = 'room_users';
@@ -25,4 +28,14 @@ class RoomUser extends BaseModel
     {
         return floatval($value);
     }
-}
+
+    protected function getScreenshotAttribute($value)
+    {
+        return Util::ensureUrl($value);
+    }
+
+    protected function setScreenshotAttribute($value)
+    {
+        $this->attributes['screenshot'] = Util::replacePartInUrl($value);
+    }
+}

+ 2 - 0
app/Services/ActivityRewardService.php

@@ -93,6 +93,8 @@ class ActivityRewardService extends BaseService
             $params['end_time'] = strtotime($params['end_time']);
         if (isset($params['detail_image']))
             $params['detail_image'] = Util::replacePartInUrl($params['detail_image']);
+        if (isset($params['pc_image']))
+            $params['pc_image'] = Util::replacePartInUrl($params['pc_image']);
 
 
         if (!empty($params['id'])) {

+ 4 - 1
app/Services/KeyboardService.php

@@ -132,6 +132,9 @@ class KeyboardService extends BaseService
         } else {
             $params['buttons'] = json_encode([], JSON_UNESCAPED_UNICODE);
         }
+        if (isset($params['image'])) {
+            $params['image'] = Util::replacePartInUrl($params['image']);
+        }
 
         // 2. 判断是否是更新
         if (!empty($params['id'])) {
@@ -300,4 +303,4 @@ class KeyboardService extends BaseService
         }
         return null;
     }
-}
+}

+ 2 - 1
app/Services/LotteryImageService.php

@@ -2,6 +2,7 @@
 
 namespace App\Services;
 
+use App\Constants\Util;
 use App\Models\Config;
 use App\Models\Message;
 use Illuminate\Support\Facades\App;
@@ -51,7 +52,7 @@ class LotteryImageService
         }
 
         // ========= 5. 返回访问URL =========
-        return Storage::url('lottery/' . $fileName);
+        return Util::replacePartInUrl(Storage::url('lottery/' . $fileName));
     }
 
     /**