From 8ae5aec135e8d033c6190ea7f4cc83454f76a44c Mon Sep 17 00:00:00 2001 From: yangduo Date: Sat, 17 Aug 2024 18:32:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/activity/contribution.go | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/server/marketserver/api/v1/activity/contribution.go b/server/marketserver/api/v1/activity/contribution.go index 09177bcd..fa662a5f 100644 --- a/server/marketserver/api/v1/activity/contribution.go +++ b/server/marketserver/api/v1/activity/contribution.go @@ -2,10 +2,10 @@ package activity import ( "f5" + "fmt" "main/constant" "main/service" "q5" - "sort" "strings" "github.com/gin-gonic/gin" @@ -31,14 +31,14 @@ func (cta *ContriApi) HistoryQuery(c *gin.Context) { } rspObj := struct { - Errcode int32 `json:"errcode"` - Msg int32 `json:"errmsg"` - CP string `json:"contributionPoint"` - Rows []info `json:"rows"` + Errcode int32 `json:"errcode"` + Msg int32 `json:"errmsg"` + CP string `json:"contributionPoint"` + Rows []*info `json:"rows"` }{} mycp, _ := service.Contribution.GetAddressContribution(account) - rspObj.CP = q5.SafeToString(mycp) + rspObj.CP = fmt.Sprintf("%.2f", mycp) q5.NewSlice(&rspObj.Rows, 0, 10) if mycp > 0.000001 { @@ -53,10 +53,11 @@ func (cta *ContriApi) HistoryQuery(c *gin.Context) { } for ds.Next() { - p := q5.NewSliceElement(&rspObj.Rows) + p := new(info) p.Type = 1 p.Time = q5.SafeToInt32(ds.GetByName("settle_date")) - p.CP = ds.GetByName("contribution") + p.CP = fmt.Sprintf("%.2f", q5.ToFloat64(ds.GetByName("contribution"))) + q5.AppendSlice(&rspObj.Rows, p) } }) @@ -73,10 +74,11 @@ func (cta *ContriApi) HistoryQuery(c *gin.Context) { } for ds.Next() { - p := q5.NewSliceElement(&rspObj.Rows) + p := new(info) p.Type = 2 p.Time = q5.SafeToInt32(ds.GetByName("createtime")) - p.CP = ds.GetByName("contribution") + p.CP = fmt.Sprintf("%.2f", q5.ToFloat64(ds.GetByName("contribution"))) + q5.AppendSlice(&rspObj.Rows, p) } }) @@ -97,17 +99,18 @@ func (cta *ContriApi) HistoryQuery(c *gin.Context) { } for ds.Next() { - p := q5.NewSliceElement(&rspObj.Rows) + p := new(info) p.Type = 3 p.Time = q5.SafeToInt32(ds.GetByName("pay_time")) - p.CP = ds.GetByName("return_contribution") + p.CP = fmt.Sprintf("%.2f", q5.ToFloat64(ds.GetByName("return_contribution"))) + q5.AppendSlice(&rspObj.Rows, p) } }) } } - sort.Slice(rspObj.Rows, func(a int, b int) bool { - return rspObj.Rows[a].Time > rspObj.Rows[b].Time + q5.Sort(rspObj.Rows, func(a *info, b *info) bool { + return a.Time > b.Time }) c.JSON(200, rspObj) @@ -137,8 +140,8 @@ func (cta *ContriApi) CECQuery(c *gin.Context) { totalgcp, _ := service.Contribution.GetGlobalContribution(false) mycp, _ := service.Contribution.GetAddressContribution(account) - rspObj.Info.MyCP = q5.ToString(mycp) - rspObj.Info.GCP = q5.ToString(totalgcp) + rspObj.Info.MyCP = fmt.Sprintf("%.2f", mycp) + rspObj.Info.GCP = fmt.Sprintf("%.2f", totalgcp) rspObj.Info.GCEC = 500000 rspObj.Info.MyCEC = q5.SafeToInt64(float64(rspObj.Info.GCEC) * (mycp) / totalgcp)