perf: 优化机器人 /state 命令内容
This commit is contained in:
+30
-9
@@ -71,21 +71,39 @@ func cmdStateHandle(ctx context.Context, b *bot.Bot, u *models.Update) {
|
||||
var rows []model.TradeOrders
|
||||
model.DB.Where("created_at > ?", time.Now().Format(time.DateOnly)).Find(&rows)
|
||||
var succ uint64
|
||||
var money float64
|
||||
var money, trx, uTrc20, uPol float64
|
||||
for _, o := range rows {
|
||||
if o.Status == model.OrderStatusSuccess {
|
||||
succ++
|
||||
money += o.Money
|
||||
if o.Status != model.OrderStatusSuccess {
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
succ++
|
||||
money += o.Money
|
||||
|
||||
var amount = cast.ToFloat64(o.Amount)
|
||||
if o.TradeType == model.OrderTradeTypeTronTrx {
|
||||
trx += amount
|
||||
}
|
||||
if o.TradeType == model.OrderTradeTypeUsdtTrc20 {
|
||||
uTrc20 += amount
|
||||
}
|
||||
if o.TradeType == model.OrderTradeTypeUsdtPolygon {
|
||||
uPol += amount
|
||||
}
|
||||
}
|
||||
|
||||
var base = "```" + `
|
||||
🎁今日成功数量:%d
|
||||
💎今日订单总数:%d
|
||||
💰今日成功收款:%.2f
|
||||
🎁今日成功订单:%d
|
||||
💎今日总数订单:%d
|
||||
💰今日收款汇总
|
||||
- %.2f CNY
|
||||
- %.2f TRX
|
||||
- %.2f USDT.Trc20
|
||||
- %.2f USDT.Polygon
|
||||
🌟扫块成功数据
|
||||
- Tron %s
|
||||
- Polygon %s
|
||||
- Tron %s
|
||||
- Polygon %s
|
||||
-----------------------
|
||||
🪧基准汇率(TRX):%v
|
||||
🪧基准汇率(USDT):%v
|
||||
@@ -102,6 +120,9 @@ func cmdStateHandle(ctx context.Context, b *bot.Bot, u *models.Update) {
|
||||
succ,
|
||||
len(rows),
|
||||
money,
|
||||
trx,
|
||||
uTrc20,
|
||||
uPol,
|
||||
conf.GetTronScanSuccRate(),
|
||||
conf.GetPolygonScanSuccRate(),
|
||||
cast.ToString(rate.GetOkxTrxRawRate()),
|
||||
|
||||
+11
-12
@@ -30,9 +30,9 @@ var (
|
||||
cfg Conf
|
||||
path string
|
||||
TronBlockScanTotal uint64
|
||||
TronBlockScanSucc uint64
|
||||
TronBlockScanFail uint64
|
||||
PolygonBlockScanTotal uint64
|
||||
PolygonBlockScanSucc uint64
|
||||
PolygonBlockScanFail uint64
|
||||
)
|
||||
|
||||
func Init() {
|
||||
@@ -70,21 +70,13 @@ func GetTrxRate() string {
|
||||
}
|
||||
|
||||
func GetTronScanSuccRate() string {
|
||||
if TronBlockScanTotal == 0 {
|
||||
|
||||
return "100.00%"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.2f%%", float64(TronBlockScanSucc)/float64(TronBlockScanTotal)*100)
|
||||
return calcScanSuccRate(TronBlockScanTotal, TronBlockScanFail)
|
||||
}
|
||||
|
||||
func GetPolygonScanSuccRate() string {
|
||||
if PolygonBlockScanTotal == 0 {
|
||||
|
||||
return "100.00%"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.2f%%", float64(PolygonBlockScanSucc)/float64(PolygonBlockScanTotal)*100)
|
||||
return calcScanSuccRate(PolygonBlockScanTotal, PolygonBlockScanFail)
|
||||
}
|
||||
|
||||
func GetUsdtAtomicity() (decimal.Decimal, int) {
|
||||
@@ -246,3 +238,10 @@ func GetPaymentAmountMax() decimal.Decimal {
|
||||
|
||||
return decimal.NewFromFloat(val)
|
||||
}
|
||||
|
||||
func calcScanSuccRate(total, fail uint64) string {
|
||||
if total == 0 {
|
||||
return "100.00%"
|
||||
}
|
||||
return fmt.Sprintf("%.2f%%", float64(total-fail)/float64(total)*100)
|
||||
}
|
||||
|
||||
+3
-2
@@ -40,6 +40,7 @@ func polygonProcessBlock(n any) {
|
||||
|
||||
resp, err := client.Post(url, contentType, bytes.NewBuffer(post))
|
||||
if err != nil {
|
||||
atomic.AddUint64(&conf.PolygonBlockScanFail, 1)
|
||||
polygonBlockScanQueue.In <- num
|
||||
log.Warn("Error sending request:", err)
|
||||
|
||||
@@ -48,6 +49,7 @@ func polygonProcessBlock(n any) {
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
atomic.AddUint64(&conf.PolygonBlockScanFail, 1)
|
||||
polygonBlockScanQueue.In <- num
|
||||
log.Warn("Error reading response body:", err)
|
||||
|
||||
@@ -58,6 +60,7 @@ func polygonProcessBlock(n any) {
|
||||
|
||||
var data = gjson.ParseBytes(body)
|
||||
if data.Get("error").Exists() {
|
||||
atomic.AddUint64(&conf.PolygonBlockScanFail, 1)
|
||||
polygonBlockScanQueue.In <- num
|
||||
log.Warn("Polygon getBlockByNumber response error ", data.Get("error").String())
|
||||
|
||||
@@ -104,8 +107,6 @@ func polygonProcessBlock(n any) {
|
||||
})
|
||||
}
|
||||
|
||||
atomic.AddUint64(&conf.PolygonBlockScanSucc, 1)
|
||||
|
||||
log.Info("区块扫描完成", num, conf.GetPolygonScanSuccRate(), "POLYGON")
|
||||
|
||||
if len(transfers) == 0 {
|
||||
|
||||
+2
-4
@@ -136,9 +136,9 @@ func tronProcessBlock(n any) {
|
||||
block, err1 := client.GetBlockByNum2(ctx, &api.NumberMessage{Num: num})
|
||||
cancel()
|
||||
if err1 != nil {
|
||||
log.Warn("GetBlockByNum Error", err1)
|
||||
|
||||
atomic.AddUint64(&conf.TronBlockScanFail, 1)
|
||||
tronBlockScanQueue.In <- num
|
||||
log.Warn("GetBlockByNum Error", err1)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -258,8 +258,6 @@ func tronProcessBlock(n any) {
|
||||
resourceQueue.In <- resources
|
||||
}
|
||||
|
||||
atomic.AddUint64(&conf.TronBlockScanSucc, 1)
|
||||
|
||||
log.Info("区块扫描完成", num, conf.GetTronScanSuccRate(), "TRON")
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package app
|
||||
|
||||
// Version 版本号说明 1.0.0 代表主版本号.功能版本号.修订号
|
||||
const Version = "1.19.1"
|
||||
const Version = "1.19.2"
|
||||
|
||||
Reference in New Issue
Block a user