[接口]新增获取用户信息接口user/info, 获取钱包余额接口
This commit is contained in:
20
server/app/api/cache/UserCache.php
vendored
20
server/app/api/cache/UserCache.php
vendored
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user