|
|
@@ -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);
|