From 35cb021adf82b1961fbffa548f68f3868c28c9de Mon Sep 17 00:00:00 2001 From: dustoair <107600816+dustoair@users.noreply.github.com> Date: Mon, 12 Sep 2022 21:26:59 +0800 Subject: [PATCH] =?UTF-8?q?=E9=BB=84=E9=87=91=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/models.go | 14 ++++++++++++++ handle/replyText.go | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/api/models.go b/api/models.go index b1cca6f..141262d 100644 --- a/api/models.go +++ b/api/models.go @@ -22,3 +22,17 @@ func GetBinanceLatestPrice(symbol string) float64 { global.DB.Where("symbol = ?", symbol).Last(&binancePrice) return binancePrice.Price } + +type CMBGold struct { + gorm.Model + Variety string + CurPrice float64 + UpDown float64 + GoldNo string +} + +func GetCMBGoldLatestPrice(goldNo string) float64 { + var cmbGold CMBGold + global.DB.Where("gold_no = ?", goldNo).Last(&cmbGold) + return cmbGold.CurPrice +} diff --git a/handle/replyText.go b/handle/replyText.go index c342a71..ee71bf2 100644 --- a/handle/replyText.go +++ b/handle/replyText.go @@ -39,11 +39,13 @@ func cmdExec(msgContent MsgContent) (replyContent string) { case "eth", "btc", "虚拟货币": priceBTC := api.GetBinanceLatestPrice("BTCUSDT") priceETH := api.GetBinanceLatestPrice("ETHUSDT") - replyContent = fmt.Sprintf("BTC: %f \n ETH: %f", priceBTC, priceETH) + replyContent = fmt.Sprintf("BTC价格: %f \n ETH价格: %f", priceBTC, priceETH) return case "gold", "黄金": - replyContent = "黄金黄金黄金黄金黄金" + goldPrice := api.GetCMBGoldLatestPrice("AU100G") + replyContent = fmt.Sprintf("黄金价格: %f", goldPrice) + return default: cmdString = msgContent.Content }