优化当前彩金池-安全线

This commit is contained in:
2026-03-17 14:22:11 +08:00
parent 216d3ac8fe
commit f6b4fb99f0
7 changed files with 136 additions and 152 deletions

View File

@@ -6,6 +6,7 @@ namespace app\api\controller;
use support\Log;
use support\Request;
use support\Response;
use support\think\Db;
use app\api\logic\GameLogic;
use app\api\logic\PlayStartLogic;
use app\api\util\ReturnCode;
@@ -162,6 +163,11 @@ class GameController extends BaseController
return $this->success([], $msg);
}
$lockName = 'play_start_' . $userId;
$lockResult = Db::query('SELECT GET_LOCK(?, 30) as l', [$lockName]);
if (empty($lockResult) || (int) ($lockResult[0]['l'] ?? 0) !== 1) {
return $this->fail('请求过于频繁,请稍后再试', ReturnCode::BUSINESS_ERROR);
}
try {
$logic = new PlayStartLogic();
$data = $logic->run($userId, (int)$direction);
@@ -245,6 +251,8 @@ class GameController extends BaseController
$msg = '没有原因';
}
return $this->fail('服务超时,' . $msg);
} finally {
Db::execute('SELECT RELEASE_LOCK(?)', [$lockName]);
}
}
}