feat: redesign crypto market with synced favorites

This commit is contained in:
hajimi
2026-08-02 02:32:20 +08:00
parent b5b59d7bf1
commit cd054d4db6
9 changed files with 1078 additions and 210 deletions
+48 -1
View File
@@ -2,12 +2,59 @@
namespace app\api\controller;
use app\api\logic\CryptoLogic;
use app\api\validate\CryptoValidate;
use think\facade\Cache;
use think\facade\Log;
class CryptoController extends BaseApiController
{
public array $notNeedLogin = ['proxy'];
public array $notNeedLogin = ['proxy', 'market'];
/**
* 人民币加密行情与市场概览
*/
public function market()
{
try {
return $this->data(CryptoLogic::market());
} catch (\Throwable $e) {
Log::error('[CryptoMarket] controller failed: ' . $e->getMessage());
return $this->fail('行情加载失败,请稍后重试');
}
}
/**
* 当前账号的加密自选列表
*/
public function favorites()
{
return $this->data(['symbols' => CryptoLogic::favorites($this->userId)]);
}
/**
* 加入加密自选
*/
public function addFavorite()
{
$params = (new CryptoValidate())->post()->goCheck('favorite');
if (!CryptoLogic::addFavorite($this->userId, (string) $params['symbol'])) {
return $this->fail(CryptoLogic::getError());
}
return $this->success('已加入自选');
}
/**
* 取消加密自选
*/
public function cancelFavorite()
{
$params = (new CryptoValidate())->post()->goCheck('favorite');
if (!CryptoLogic::cancelFavorite($this->userId, (string) $params['symbol'])) {
return $this->fail(CryptoLogic::getError());
}
return $this->success('已取消自选');
}
/**
* Binance API 代理(解决客户端直连被墙问题)