fix: require login for crypto favorites

This commit is contained in:
hajimi
2026-08-02 02:37:31 +08:00
parent cd054d4db6
commit 1c6ebf3e3c
2 changed files with 20 additions and 0 deletions
+11
View File
@@ -16,6 +16,9 @@ class CryptoLogic extends BaseLogic
public static function favorites(int $userId): array
{
if ($userId <= 0) {
return [];
}
$symbols = CryptoFavorite::where([
'user_id' => $userId,
'status' => YesNoEnum::YES,
@@ -26,6 +29,10 @@ class CryptoLogic extends BaseLogic
public static function addFavorite(int $userId, string $symbol): bool
{
if ($userId <= 0) {
self::setError('请先登录');
return false;
}
$symbol = strtoupper(trim($symbol));
if (!CryptoMarketService::isSupportedSymbol($symbol)) {
self::setError('暂不支持该币种');
@@ -54,6 +61,10 @@ class CryptoLogic extends BaseLogic
public static function cancelFavorite(int $userId, string $symbol): bool
{
if ($userId <= 0) {
self::setError('请先登录');
return false;
}
try {
CryptoFavorite::update(
['status' => YesNoEnum::NO],