修改缓存方式
This commit is contained in:
@@ -6,9 +6,9 @@ namespace app\api\controller;
|
||||
|
||||
use app\common\library\game\ZiHuaDictionary;
|
||||
use app\common\model\BetOrder;
|
||||
use app\common\model\GameConfig;
|
||||
use app\common\model\GameRecord;
|
||||
use app\common\model\UserWalletRecord;
|
||||
use app\common\service\GameHotDataRedis;
|
||||
use app\common\service\UserPushService;
|
||||
use support\think\Db;
|
||||
use Webman\Http\Request;
|
||||
@@ -25,15 +25,15 @@ class Game extends MobileBase
|
||||
return $response;
|
||||
}
|
||||
|
||||
$period = GameRecord::order('id', 'desc')->find();
|
||||
$periodRow = GameHotDataRedis::gameRecordLatest();
|
||||
$now = time();
|
||||
$startAt = $period ? $this->intValue($period->period_start_at) : $now;
|
||||
$startAt = $periodRow ? $this->intValue($periodRow['period_start_at'] ?? 0) : $now;
|
||||
$lockAt = $startAt + 20;
|
||||
$openAt = $startAt + 22;
|
||||
$countdown = $period ? max(0, ($startAt + 30) - $now) : 0;
|
||||
$countdown = $periodRow ? max(0, ($startAt + 30) - $now) : 0;
|
||||
|
||||
$dictionaryConfig = GameConfig::where('config_key', ZiHuaDictionary::CONFIG_KEY)->find();
|
||||
$dictionaryItems = ZiHuaDictionary::parseFromConfigValue($dictionaryConfig?->config_value ?? null);
|
||||
$dictionaryConfig = GameHotDataRedis::gameConfigRow(ZiHuaDictionary::CONFIG_KEY) ?? [];
|
||||
$dictionaryItems = ZiHuaDictionary::parseFromConfigValue($dictionaryConfig['config_value'] ?? null);
|
||||
$items = [];
|
||||
foreach ($dictionaryItems as $row) {
|
||||
$items[] = [
|
||||
@@ -48,8 +48,8 @@ class Game extends MobileBase
|
||||
return $this->mobileSuccess([
|
||||
'server_time' => $now,
|
||||
'period' => [
|
||||
'period_no' => $period->period_no ?? '',
|
||||
'status' => $this->mapPeriodStatus($period->status ?? null),
|
||||
'period_no' => (string) ($periodRow['period_no'] ?? ''),
|
||||
'status' => $this->mapPeriodStatus($periodRow['status'] ?? null),
|
||||
'countdown' => $countdown,
|
||||
'lock_at' => $lockAt,
|
||||
'open_at' => $openAt,
|
||||
@@ -73,8 +73,8 @@ class Game extends MobileBase
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
$dictionaryConfig = GameConfig::where('config_key', ZiHuaDictionary::CONFIG_KEY)->find();
|
||||
$dictionaryItems = ZiHuaDictionary::parseFromConfigValue($dictionaryConfig?->config_value ?? null);
|
||||
$dictionaryConfig = GameHotDataRedis::gameConfigRow(ZiHuaDictionary::CONFIG_KEY) ?? [];
|
||||
$dictionaryItems = ZiHuaDictionary::parseFromConfigValue($dictionaryConfig['config_value'] ?? null);
|
||||
$items = [];
|
||||
foreach ($dictionaryItems as $row) {
|
||||
$items[] = [
|
||||
@@ -85,7 +85,7 @@ class Game extends MobileBase
|
||||
];
|
||||
}
|
||||
return $this->mobileSuccess([
|
||||
'version' => (string) ($dictionaryConfig->update_time ?? '1'),
|
||||
'version' => (string) ($dictionaryConfig['update_time'] ?? '1'),
|
||||
'items' => $items,
|
||||
]);
|
||||
}
|
||||
@@ -118,19 +118,19 @@ class Game extends MobileBase
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
$period = GameRecord::order('id', 'desc')->find();
|
||||
if (!$period) {
|
||||
$periodRow = GameHotDataRedis::gameRecordLatest();
|
||||
if (!$periodRow) {
|
||||
return $this->mobileError(2002, 'Game period does not exist');
|
||||
}
|
||||
$now = time();
|
||||
$startAt = $this->intValue($period->period_start_at);
|
||||
$startAt = $this->intValue($periodRow['period_start_at'] ?? 0);
|
||||
return $this->mobileSuccess([
|
||||
'period_id' => $period->id,
|
||||
'period_no' => $period->period_no,
|
||||
'status' => $this->mapPeriodStatus($period->status),
|
||||
'period_id' => $periodRow['id'],
|
||||
'period_no' => $periodRow['period_no'],
|
||||
'status' => $this->mapPeriodStatus($periodRow['status'] ?? null),
|
||||
'countdown' => max(0, ($startAt + 30) - $now),
|
||||
'bet_close_in' => max(0, ($startAt + 20) - $now),
|
||||
'result_number' => $period->result_number,
|
||||
'result_number' => $periodRow['result_number'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -218,6 +218,10 @@ class Game extends MobileBase
|
||||
'update_time' => time(),
|
||||
]);
|
||||
Db::commit();
|
||||
$uid = filter_var($user->id, FILTER_VALIDATE_INT);
|
||||
if ($uid !== false) {
|
||||
GameHotDataRedis::userForget($uid);
|
||||
}
|
||||
UserPushService::publish((int) $user->id, UserPushService::EVT_BET_ACCEPTED, [
|
||||
'order_no' => $orderNo,
|
||||
'period_no' => (string) $period->period_no,
|
||||
@@ -355,7 +359,11 @@ class Game extends MobileBase
|
||||
|
||||
private function getConfigValue(string $key, string $default): string
|
||||
{
|
||||
$value = GameConfig::where('config_key', $key)->value('config_value');
|
||||
$row = GameHotDataRedis::gameConfigRow($key);
|
||||
if ($row === null) {
|
||||
return $default;
|
||||
}
|
||||
$value = $row['config_value'] ?? null;
|
||||
if ($value === null || $value === '') {
|
||||
return $default;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user