fix: require login for crypto favorites
This commit is contained in:
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user