优化当前彩金池-安全线
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user