Browse Source

no message

Tree 21 hours ago
parent
commit
5d01a8cb07

+ 4 - 2
app/Http/Controllers/Game/ActivityController.php

@@ -84,7 +84,8 @@ class ActivityController extends Controller
                 'user_id' => $user->UserID,
                 'error' => $e->getMessage(),
             ]);
-            return apiReturnFail($e->getMessage());
+            // 这里统一返回通用错误,不向前端抛出具体异常信息
+            return apiReturnFail(['web.activity.wheel_error', __('messages.web.activity.wheel_error')]);
         }
     }
 
@@ -121,7 +122,8 @@ class ActivityController extends Controller
                 'user_id' => $user->UserID,
                 'error' => $e->getMessage(),
             ]);
-            return apiReturnFail($e->getMessage());
+            // 这里统一返回通用错误,不向前端抛出具体异常信息
+            return apiReturnFail(['web.activity.wheel_error', __('messages.web.activity.wheel_error')]);
         }
     }
     public function List(Request $request)

+ 21 - 7
app/Services/ChristmasWheelService.php

@@ -237,7 +237,9 @@ class ChristmasWheelService
         $redisKey = 'christmas_wheel_spin_' . $userId;
         $lock = SetNXLock::getExclusiveLock($redisKey, 5);
         if (!$lock) {
-            throw new \RuntimeException('操作太频繁,请稍后再试');
+            return [
+                'error' => ['web.activity.wheel_too_frequent', __('messages.web.activity.wheel_too_frequent')],
+            ];
         }
 
         try {
@@ -247,15 +249,21 @@ class ChristmasWheelService
                 ->first();
 
             if (!$activity || (int)$activity->status !== 1) {
-                throw new \RuntimeException('活动未开启');
+                return [
+                    'error' => ['web.activity.wheel_not_open', __('messages.web.activity.wheel_not_open')],
+                ];
             }
 
             $now = now();
             if (!empty($activity->start_time) && $now->lt($activity->start_time)) {
-                throw new \RuntimeException('活动未开始');
+                return [
+                    'error' => ['web.activity.wheel_not_started', __('messages.web.activity.wheel_not_started')],
+                ];
             }
             if (!empty($activity->end_time) && $now->gt($activity->end_time)) {
-                throw new \RuntimeException('活动已结束');
+                return [
+                    'error' => ['web.activity.wheel_ended', __('messages.web.activity.wheel_ended')],
+                ];
             }
 
             $slots = DB::connection('write')
@@ -265,7 +273,9 @@ class ChristmasWheelService
                 ->get();
 
             if ($slots->isEmpty()) {
-                throw new \RuntimeException('转盘配置不存在');
+                return [
+                    'error' => ['web.activity.wheel_config_missing', __('messages.web.activity.wheel_config_missing')],
+                ];
             }
 
             DB::connection('write')->beginTransaction();
@@ -278,7 +288,9 @@ class ChristmasWheelService
 
             if (!$userRow || (int)$userRow->left_times <= 0) {
                 DB::connection('write')->rollBack();
-                throw new \RuntimeException($userId.'没有可用的转盘次数');
+                return [
+                    'error' => ['web.activity.wheel_no_times', __('messages.web.activity.wheel_no_times')],
+                ];
             }
 
             $totalWeight = 0;
@@ -294,7 +306,9 @@ class ChristmasWheelService
 
             if ($totalWeight <= 0) {
                 DB::connection('write')->rollBack();
-                throw new \RuntimeException('转盘权重配置错误');
+                return [
+                    'error' => ['web.activity.wheel_weight_error', __('messages.web.activity.wheel_weight_error')],
+                ];
             }
 
             $rand = mt_rand(1, $totalWeight);

+ 21 - 7
app/Services/HolidayWheelService.php

@@ -174,7 +174,9 @@ class HolidayWheelService
         $redisKey = 'holiday_wheel_spin_' . $userId;
         $lock = SetNXLock::getExclusiveLock($redisKey, 5);
         if (!$lock) {
-            throw new \RuntimeException('操作太频繁,请稍后再试');
+            return [
+                'error' => ['web.activity.wheel_too_frequent', __('messages.web.activity.wheel_too_frequent')],
+            ];
         }
 
         try {
@@ -184,15 +186,21 @@ class HolidayWheelService
                 ->first();
 
             if (!$activity || (int)$activity->status !== 1) {
-                throw new \RuntimeException('活动未开启');
+                return [
+                    'error' => ['web.activity.wheel_not_open', __('messages.web.activity.wheel_not_open')],
+                ];
             }
 
             $now = now();
             if (!empty($activity->start_time) && $now->lt($activity->start_time)) {
-                throw new \RuntimeException('活动未开始');
+                return [
+                    'error' => ['web.activity.wheel_not_started', __('messages.web.activity.wheel_not_started')],
+                ];
             }
             if (!empty($activity->end_time) && $now->gt($activity->end_time)) {
-                throw new \RuntimeException('活动已结束');
+                return [
+                    'error' => ['web.activity.wheel_ended', __('messages.web.activity.wheel_ended')],
+                ];
             }
 
             $slots = DB::connection('write')
@@ -202,7 +210,9 @@ class HolidayWheelService
                 ->get();
 
             if ($slots->isEmpty()) {
-                throw new \RuntimeException('转盘配置不存在');
+                return [
+                    'error' => ['web.activity.wheel_config_missing', __('messages.web.activity.wheel_config_missing')],
+                ];
             }
 
             DB::connection('write')->beginTransaction();
@@ -215,7 +225,9 @@ class HolidayWheelService
 
             if (!$userRow || (int)$userRow->left_times <= 0) {
                 DB::connection('write')->rollBack();
-                throw new \RuntimeException($userId.'没有可用的转盘次数');
+                return [
+                    'error' => ['web.activity.wheel_no_times', __('messages.web.activity.wheel_no_times')],
+                ];
             }
 
             $totalWeight = 0;
@@ -231,7 +243,9 @@ class HolidayWheelService
 
             if ($totalWeight <= 0) {
                 DB::connection('write')->rollBack();
-                throw new \RuntimeException('转盘权重配置错误');
+                return [
+                    'error' => ['web.activity.wheel_weight_error', __('messages.web.activity.wheel_weight_error')],
+                ];
             }
 
             $rand = mt_rand(1, $totalWeight);

+ 9 - 1
resources/lang/en/messages.php

@@ -245,7 +245,15 @@ return [
         "activity" => [
             "login_required" => "Please log in first",
             "redpack_not_available" => "There is no RedPack available",
-            "redpack_no_recharge" => "You need to deposit first!"
+            "redpack_no_recharge" => "You need to deposit first!",
+            "wheel_error" => "Spin failed, please try again later",
+            "wheel_too_frequent" => "Operation too frequent, please try again later",
+            "wheel_not_open" => "Activity is not open",
+            "wheel_not_started" => "Activity has not started",
+            "wheel_ended" => "Activity has ended",
+            "wheel_config_missing" => "Wheel configuration does not exist",
+            "wheel_no_times" => "No available spin times",
+            "wheel_weight_error" => "Wheel weight configuration error"
         ],
         "protect" => [
             "score_limit" => "Score limit reached",

+ 8 - 0
resources/lang/zh/web.php

@@ -75,6 +75,14 @@ return [
     'activity' => [
         'redpack_not_available' => '没有红包可用',
         'redpack_no_recharge' => '您需要先充值!',
+        'wheel_error' => '抽奖失败,请稍后再试',
+        'wheel_too_frequent' => '操作太频繁,请稍后再试',
+        'wheel_not_open' => '活动未开启',
+        'wheel_not_started' => '活动未开始',
+        'wheel_ended' => '活动已结束',
+        'wheel_config_missing' => '转盘配置不存在',
+        'wheel_no_times' => '没有可用的转盘次数',
+        'wheel_weight_error' => '转盘权重配置错误',
     ],
     'gift' => [
         'config_not_exists' => '礼包配置不存在',