@@ -73,107 +73,122 @@ func cmdStateHandle(ctx context.Context, b *bot.Bot, u *models.Update) {
7373 var rows []model.TradeOrders
7474 model .DB .Where ("created_at > ?" , time .Now ().Format (time .DateOnly )).Find (& rows )
7575 var succ uint64
76- var money , trx , uTrc20 , uErc20 , uBep20 , uXlayer , uSolana , uPol , uArb , uAptos float64
76+ var money float64
77+
78+ var types []string
79+ model .DB .Model (& model.WalletAddress {}).Distinct ("trade_type" ).Where ("status = ?" , model .StatusEnable ).Pluck ("trade_type" , & types )
80+
81+ // 动态统计各类型金额
82+ typeAmounts := make (map [string ]float64 )
83+ for _ , t := range types {
84+ typeAmounts [t ] = 0
85+ }
86+
7787 for _ , o := range rows {
7888 if o .Status != model .OrderStatusSuccess {
7989
8090 continue
8191 }
82-
8392 succ ++
8493 money += o .Money
8594
86- var amount = cast .ToFloat64 (o .Amount )
87- if o .TradeType == model .OrderTradeTypeTronTrx {
88- trx += amount
89- }
90- if o .TradeType == model .OrderTradeTypeUsdtBep20 {
91- uBep20 += amount
92- }
93- if o .TradeType == model .OrderTradeTypeUsdtTrc20 {
94- uTrc20 += amount
95+ // 只统计启用类型的金额
96+ if _ , exists := typeAmounts [o .TradeType ]; exists {
97+ typeAmounts [o .TradeType ] += cast .ToFloat64 (o .Amount )
9598 }
96- if o .TradeType == model .OrderTradeTypeUsdtErc20 {
97- uErc20 += amount
98- }
99- if o .TradeType == model .OrderTradeTypeUsdtPolygon {
100- uPol += amount
101- }
102- if o .TradeType == model .OrderTradeTypeUsdtArbitrum {
103- uArb += amount
104- }
105- if o .TradeType == model .OrderTradeTypeUsdtXlayer {
106- uXlayer += amount
99+ }
100+
101+ // 构建基础统计信息
102+ var text = "```\n "
103+ text += fmt .Sprintf ("🎁今日成功订单:%d\n " , succ )
104+ text += fmt .Sprintf ("💎今日总数订单:%d\n " , len (rows ))
105+ text += "💰今日收款汇总\n "
106+ text += fmt .Sprintf (" - %.2f CNY\n " , money )
107+
108+ // 动态显示启用类型的收款汇总
109+ typeDisplayNames := map [string ]string {
110+ model .OrderTradeTypeTronTrx : "TRX" ,
111+ model .OrderTradeTypeUsdtTrc20 : "USDT.Trc20" ,
112+ model .OrderTradeTypeUsdtErc20 : "USDT.Erc20" ,
113+ model .OrderTradeTypeUsdtBep20 : "USDT.Bep20" ,
114+ model .OrderTradeTypeUsdtAptos : "USDT.Aptos" ,
115+ model .OrderTradeTypeUsdtXlayer : "USDT.Xlayer" ,
116+ model .OrderTradeTypeUsdtSolana : "USDT.Solana" ,
117+ model .OrderTradeTypeUsdtPolygon : "USDT.Polygon" ,
118+ model .OrderTradeTypeUsdtArbitrum : "USDT.Arbitrum" ,
119+ }
120+
121+ for _ , t := range types {
122+ if displayName , exists := typeDisplayNames [t ]; exists {
123+ text += fmt .Sprintf (" - %.2f %s\n " , typeAmounts [t ], displayName )
107124 }
108- if o .TradeType == model .OrderTradeTypeUsdtSolana {
109- uSolana += amount
125+ }
126+
127+ // 动态显示扫块成功数据
128+ text += "🌟扫块成功数据\n "
129+ blockchainMap := map [string ]string {
130+ model .OrderTradeTypeUsdtBep20 : conf .Bsc ,
131+ model .OrderTradeTypeTronTrx : conf .Tron ,
132+ model .OrderTradeTypeUsdtTrc20 : conf .Tron ,
133+ model .OrderTradeTypeUsdtAptos : conf .Aptos ,
134+ model .OrderTradeTypeUsdtXlayer : conf .Xlayer ,
135+ model .OrderTradeTypeUsdtSolana : conf .Solana ,
136+ model .OrderTradeTypeUsdtPolygon : conf .Polygon ,
137+ model .OrderTradeTypeUsdtArbitrum : conf .Arbitrum ,
138+ model .OrderTradeTypeUsdtErc20 : conf .Ethereum ,
139+ }
140+
141+ blockchainNames := map [string ]string {
142+ conf .Bsc : "Bsc" ,
143+ conf .Tron : "Tron" ,
144+ conf .Aptos : "Aptos" ,
145+ conf .Xlayer : "Xlayer" ,
146+ conf .Solana : "Solana" ,
147+ conf .Polygon : "Polygon" ,
148+ conf .Arbitrum : "Arbitrum" ,
149+ conf .Ethereum : "Ethereum" ,
150+ }
151+
152+ // 收集需要显示的区块链
153+ blockchainSet := make (map [string ]bool )
154+ for _ , t := range types {
155+ if blockchain , exists := blockchainMap [t ]; exists {
156+ blockchainSet [blockchain ] = true
110157 }
111- if o .TradeType == model .OrderTradeTypeUsdtAptos {
112- uAptos += amount
158+ }
159+
160+ // 将区块链转换为切片并按名字长度排序
161+ var blockchains []string
162+ for blockchain := range blockchainSet {
163+ blockchains = append (blockchains , blockchain )
164+ }
165+
166+ // 按区块链名字长度排序,名字越长排越后
167+ for i := 0 ; i < len (blockchains )- 1 ; i ++ {
168+ for j := 0 ; j < len (blockchains )- 1 - i ; j ++ {
169+ name1 := blockchainNames [blockchains [j ]]
170+ name2 := blockchainNames [blockchains [j + 1 ]]
171+ if len (name1 ) > len (name2 ) {
172+ blockchains [j ], blockchains [j + 1 ] = blockchains [j + 1 ], blockchains [j ]
173+ }
113174 }
114175 }
115176
116- var base = "```" + `
117- 🎁今日成功订单:%d
118- 💎今日总数订单:%d
119- 💰今日收款汇总
120- - %.2f CNY
121- - %.2f TRX
122- - %.2f USDT.Trc20
123- - %.2f USDT.Erc20
124- - %.2f USDT.Bep20
125- - %.2f USDT.Aptos
126- - %.2f USDT.Xlayer
127- - %.2f USDT.Solana
128- - %.2f USDT.Polygon
129- - %.2f USDT.Arbitrum
130- 🌟扫块成功数据
131- - Bsc %s
132- - Tron %s
133- - Aptos %s
134- - Xlayer %s
135- - Solana %s
136- - Polygon %s
137- - Arbitrum %s
138- - Ethereum %s
139- -----------------------
140- 🪧基准汇率(TRX):%v
141- 🪧基准汇率(USDT):%v
142- ✅订单汇率(TRX):%v
143- ✅订单汇率(USDT):%v
144- -----------------------
145- ` + "```" + `
146- >基准汇率:来源于交易所的原始数据。
147- >订单汇率:订单创建过程中实际使用的汇率。
148- >扫块成功数据:如果该值过低,说明您的服务器与区块链网络连接不稳定,请尝试更换区块节点。
149- `
150-
151- var text = fmt .Sprintf (base ,
152- succ ,
153- len (rows ),
154- money ,
155- trx ,
156- uTrc20 ,
157- uErc20 ,
158- uBep20 ,
159- uAptos ,
160- uXlayer ,
161- uSolana ,
162- uPol ,
163- uArb ,
164- conf .GetBlockSuccRate (conf .Bsc ),
165- conf .GetBlockSuccRate (conf .Tron ),
166- conf .GetBlockSuccRate (conf .Aptos ),
167- conf .GetBlockSuccRate (conf .Xlayer ),
168- conf .GetBlockSuccRate (conf .Solana ),
169- conf .GetBlockSuccRate (conf .Polygon ),
170- conf .GetBlockSuccRate (conf .Arbitrum ),
171- conf .GetBlockSuccRate (conf .Ethereum ),
172- cast .ToString (rate .GetOkxTrxRawRate ()),
173- cast .ToString (rate .GetOkxUsdtRawRate ()),
174- cast .ToString (rate .GetTrxCalcRate ()),
175- cast .ToString (rate .GetUsdtCalcRate ()),
176- )
177+ // 按排序后的顺序显示区块链数据
178+ for _ , blockchain := range blockchains {
179+ text += fmt .Sprintf (" - %s %s\n " , blockchainNames [blockchain ], conf .GetBlockSuccRate (blockchain ))
180+ }
181+
182+ text += "-----------------------\n "
183+ text += fmt .Sprintf ("🪧基准汇率(TRX):%v\n " , cast .ToString (rate .GetOkxTrxRawRate ()))
184+ text += fmt .Sprintf ("🪧基准汇率(USDT):%v\n " , cast .ToString (rate .GetOkxUsdtRawRate ()))
185+ text += fmt .Sprintf ("✅订单汇率(TRX):%v\n " , cast .ToString (rate .GetTrxCalcRate ()))
186+ text += fmt .Sprintf ("✅订单汇率(USDT):%v\n " , cast .ToString (rate .GetUsdtCalcRate ()))
187+ text += "-----------------------\n "
188+ text += "```\n "
189+ text += ">基准汇率:来源于交易所的原始数据。\n "
190+ text += ">订单汇率:订单创建过程中实际使用的汇率。\n "
191+ text += ">扫块成功数据:如果该值过低,说明您的服务器与区块链网络连接不稳定,请尝试更换区块节点。"
177192
178193 SendMessage (& bot.SendMessageParams {
179194 ChatID : u .Message .Chat .ID ,
0 commit comments