From eff2547175e320f1f7c4d4007e9d82af14d9d6e2 Mon Sep 17 00:00:00 2001 From: yangduo Date: Sat, 17 Aug 2024 18:08:51 +0800 Subject: [PATCH 1/2] contribution history --- .../api/v1/activity/contribution.go | 109 ++++++++++++------ server/marketserver/service/contribution.go | 31 +++-- 2 files changed, 97 insertions(+), 43 deletions(-) diff --git a/server/marketserver/api/v1/activity/contribution.go b/server/marketserver/api/v1/activity/contribution.go index 4eae9f75..09177bcd 100644 --- a/server/marketserver/api/v1/activity/contribution.go +++ b/server/marketserver/api/v1/activity/contribution.go @@ -3,7 +3,9 @@ package activity import ( "f5" "main/constant" + "main/service" "q5" + "sort" "strings" "github.com/gin-gonic/gin" @@ -22,54 +24,92 @@ func (cta *ContriApi) HistoryQuery(c *gin.Context) { return } - rspObj := struct { - Errcode int32 `json:"errcode"` - Msg int32 `json:"errmsg"` - CP string `json:"contributionPoint"` - Rows []interface{} `json:"rows"` - }{} - - rspObj.CP = "12345.67" - item := struct { + type info struct { Type int32 `json:"type"` Time int32 `json:"give_time"` CP string `json:"contribution_point"` + } + + rspObj := struct { + Errcode int32 `json:"errcode"` + Msg int32 `json:"errmsg"` + CP string `json:"contributionPoint"` + Rows []info `json:"rows"` }{} - item.Type = 0 - item.Time = int32(f5.GetApp().GetRealSeconds()) - item.CP = "12345.67" + mycp, _ := service.Contribution.GetAddressContribution(account) + rspObj.CP = q5.SafeToString(mycp) q5.NewSlice(&rspObj.Rows, 0, 10) - rspObj.Rows = append(rspObj.Rows, item) - { - sql := ` -SELECT * FROM t_contribution_history WHERE idx > 0 AND account_id = ? -` - params := []string{ - account, - } + if mycp > 0.000001 { + sql := `SELECT * FROM t_staking_daily_settlement WHERE idx > 0 and account_address = ?` f5.GetGoStyleDb().RawQuery( - constant.GAME_DB, + constant.BCNFT_DB, sql, - params, + []string{account}, func(err error, ds *f5.DataSet) { if err != nil { return } for ds.Next() { - p := struct { - Type int32 `json:"type"` - Time int32 `json:"give_time"` - CP string `json:"contribution_point"` - }{} - p.Type = q5.ToInt32(ds.GetByName("net_id")) - p.Time = q5.ToInt32(ds.GetByName("")) + p := q5.NewSliceElement(&rspObj.Rows) + p.Type = 1 + p.Time = q5.SafeToInt32(ds.GetByName("settle_date")) + p.CP = ds.GetByName("contribution") } }) + + { + loweremail, accountid := service.Contribution.GetEmailAccountId(account) + sql := `SELECT * FROM t_contribution_history WHERE idx > 0 AND account_id = ?` + f5.GetGoStyleDb().RawQuery( + constant.GAME_DB, + sql, + []string{accountid}, + func(err error, ds *f5.DataSet) { + if err != nil { + return + } + + for ds.Next() { + p := q5.NewSliceElement(&rspObj.Rows) + p.Type = 2 + p.Time = q5.SafeToInt32(ds.GetByName("createtime")) + p.CP = ds.GetByName("contribution") + } + }) + + sql = `SELECT * FROM t_recharge_return_contribution WHERE idx > 0 AND user_identity IN (?` + + if loweremail != "" { + sql += ", " + loweremail + } + sql += ")" + + f5.GetGoStyleDb().RawQuery( + constant.BCNFT_DB, + sql, + []string{account}, + func(err error, ds *f5.DataSet) { + if err != nil { + return + } + + for ds.Next() { + p := q5.NewSliceElement(&rspObj.Rows) + p.Type = 3 + p.Time = q5.SafeToInt32(ds.GetByName("pay_time")) + p.CP = ds.GetByName("return_contribution") + } + }) + } } + sort.Slice(rspObj.Rows, func(a int, b int) bool { + return rspObj.Rows[a].Time > rspObj.Rows[b].Time + }) + c.JSON(200, rspObj) } @@ -95,11 +135,12 @@ func (cta *ContriApi) CECQuery(c *gin.Context) { } `json:"info"` }{} - rspObj.CP = "12345.67" - rspObj.Info.MyCP = "12345.67" - rspObj.Info.GCP = "12345.67" - rspObj.Info.GCEC = 10000 - rspObj.Info.MyCEC = 10000 + totalgcp, _ := service.Contribution.GetGlobalContribution(false) + mycp, _ := service.Contribution.GetAddressContribution(account) + rspObj.Info.MyCP = q5.ToString(mycp) + rspObj.Info.GCP = q5.ToString(totalgcp) + rspObj.Info.GCEC = 500000 + rspObj.Info.MyCEC = q5.SafeToInt64(float64(rspObj.Info.GCEC) * (mycp) / totalgcp) c.JSON(200, rspObj) } diff --git a/server/marketserver/service/contribution.go b/server/marketserver/service/contribution.go index 70888bbf..b60419c7 100644 --- a/server/marketserver/service/contribution.go +++ b/server/marketserver/service/contribution.go @@ -12,6 +12,7 @@ type accountContricution struct { contribution float64 gcTime int64 loweremail string + accountid string } type contribution struct { @@ -30,18 +31,28 @@ func (this *contribution) unInit() { } +func (this *contribution) GetEmailAccountId(accountAddress string) (string, string) { + accinfo, exist := this.accountContricutionlist.Load(accountAddress) + if exist { + return (*accinfo).loweremail, (*accinfo).accountid + } + + return "", "" +} + func (this *contribution) GetAddressContribution(accountAddress string) (float64, error) { accinfo, exist := this.accountContricutionlist.Load(accountAddress) var beforcontribution float64 = 0 if nowseconds := f5.GetApp().GetRealSeconds(); !exist || (*accinfo).gcTime+60 < nowseconds { if !exist { - *accinfo = new(accountContricution) + info := new(accountContricution) + this.accountContricutionlist.Store(accountAddress, info) + accinfo = &info } beforcontribution = (*accinfo).contribution if (*accinfo).loweremail == "" { sql := `SELECT account_id FROM t_user WHERE idx > 0 AND address = ?` - accountid := "" f5.GetGoStyleDb().RawQuery( constant.GAME_DB, sql, @@ -52,16 +63,16 @@ func (this *contribution) GetAddressContribution(accountAddress string) (float64 } if ds.Next() { - accountid = ds.GetByIndex(0) + (*accinfo).accountid = ds.GetByIndex(0) } }) - if accountid != "" { + if (*accinfo).accountid != "" { sql := `SELECT lower_case_email FROM t_immutable_account WHERE idx > 0 AND account_id = ?` f5.GetGoStyleDb().RawQuery( constant.ACCOUNT_DB, sql, - []string{accountid}, + []string{(*accinfo).accountid}, func(err error, ds *f5.DataSet) { if err != nil { return @@ -109,12 +120,12 @@ func (this *contribution) GetAddressContribution(accountAddress string) (float64 (*accinfo).loadhistory = true } - { - sql := `SELECT SUM(contribution) FROM t_contribution WHERE idx > 0 AND user_identity = ?` + if (*accinfo).accountid != "" { + sql := `SELECT contribution FROM t_contribution WHERE idx > 0 AND account_id = ?` f5.GetGoStyleDb().RawQuery( constant.GAME_DB, sql, - []string{accountAddress}, + []string{(*accinfo).accountid}, func(err error, ds *f5.DataSet) { if err != nil { return @@ -124,8 +135,10 @@ func (this *contribution) GetAddressContribution(accountAddress string) (float64 (*accinfo).contribution, _ = q5.ToFloat64Ex(ds.GetByIndex(0)) } }) + } - sql = `SELECT SUM(return_contribution) FROM t_recharge_return_contribution WHERE idx > 0 AND user_identity IN (?` + { + sql := `SELECT SUM(return_contribution) FROM t_recharge_return_contribution WHERE idx > 0 AND user_identity IN (?` if (*accinfo).loweremail != "" { sql += ", " + (*accinfo).loweremail } From 8ae5aec135e8d033c6190ea7f4cc83454f76a44c Mon Sep 17 00:00:00 2001 From: yangduo Date: Sat, 17 Aug 2024 18:32:36 +0800 Subject: [PATCH 2/2] =?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)