[接口]新增获取用户信息接口user/info, 获取钱包余额接口

This commit is contained in:
2026-03-04 11:49:53 +08:00
parent 77a898df22
commit 6d2b74a899
3 changed files with 96 additions and 0 deletions

View File

@@ -75,6 +75,26 @@ class UserCache
return is_array($data) ? $data : [];
}
/**
* 仅从缓存读取用户平台币 coin不查库低延迟
* @return int|float|null 余额,缓存未命中返回 null缓存中 coin 可能为字符串,统一转为数值)
*/
public static function getUserCoin(int $userId): int|float|null
{
$user = self::getUser($userId);
if (empty($user) || !array_key_exists('coin', $user)) {
return null;
}
$coin = $user['coin'];
if (is_int($coin) || is_float($coin)) {
return $coin;
}
if (is_string($coin) && is_numeric($coin)) {
return str_contains($coin, '.') ? (float) $coin : (int) $coin;
}
return null;
}
/** 删除用户缓存 */
public static function deleteUser(int $userId): bool
{