This commit is contained in:
aozhiwei 2024-08-17 18:48:43 +08:00
commit 1b4ff79bdc
2 changed files with 100 additions and 43 deletions

View File

@ -2,7 +2,9 @@ package activity
import ( import (
"f5" "f5"
"fmt"
"main/constant" "main/constant"
"main/service"
"q5" "q5"
"strings" "strings"
@ -22,53 +24,94 @@ func (cta *ContriApi) HistoryQuery(c *gin.Context) {
return return
} }
type info struct {
Type int32 `json:"type"`
Time int32 `json:"give_time"`
CP string `json:"contribution_point"`
}
rspObj := struct { rspObj := struct {
Errcode int32 `json:"errcode"` Errcode int32 `json:"errcode"`
Msg int32 `json:"errmsg"` Msg int32 `json:"errmsg"`
CP string `json:"contributionPoint"` CP string `json:"contributionPoint"`
Rows []interface{} `json:"rows"` Rows []*info `json:"rows"`
}{} }{}
rspObj.CP = "12345.67" mycp, _ := service.Contribution.GetAddressContribution(account)
item := struct { rspObj.CP = fmt.Sprintf("%.2f", mycp)
Type int32 `json:"type"`
Time int32 `json:"give_time"`
CP string `json:"contribution_point"`
}{}
item.Type = 0
item.Time = int32(f5.GetApp().GetRealSeconds())
item.CP = "12345.67"
q5.NewSlice(&rspObj.Rows, 0, 10) q5.NewSlice(&rspObj.Rows, 0, 10)
rspObj.Rows = append(rspObj.Rows, item)
{ if mycp > 0.000001 {
sql := ` sql := `SELECT * FROM t_staking_daily_settlement WHERE idx > 0 and account_address = ?`
SELECT * FROM t_contribution_history WHERE idx > 0 AND account_id = ?
`
params := []string{
account,
}
f5.GetGoStyleDb().RawQuery( f5.GetGoStyleDb().RawQuery(
constant.GAME_DB, constant.BCNFT_DB,
sql, sql,
params, []string{account},
func(err error, ds *f5.DataSet) { func(err error, ds *f5.DataSet) {
if err != nil { if err != nil {
return return
} }
for ds.Next() { for ds.Next() {
p := struct { p := new(info)
Type int32 `json:"type"` p.Type = 1
Time int32 `json:"give_time"` p.Time = q5.SafeToInt32(ds.GetByName("settle_date"))
CP string `json:"contribution_point"` p.CP = fmt.Sprintf("%.2f", q5.ToFloat64(ds.GetByName("contribution")))
}{} q5.AppendSlice(&rspObj.Rows, p)
p.Type = q5.ToInt32(ds.GetByName("net_id")) }
p.Time = q5.ToInt32(ds.GetByName("")) })
{
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 := new(info)
p.Type = 2
p.Time = q5.SafeToInt32(ds.GetByName("createtime"))
p.CP = fmt.Sprintf("%.2f", q5.ToFloat64(ds.GetByName("contribution")))
q5.AppendSlice(&rspObj.Rows, p)
}
})
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 := new(info)
p.Type = 3
p.Time = q5.SafeToInt32(ds.GetByName("pay_time"))
p.CP = fmt.Sprintf("%.2f", q5.ToFloat64(ds.GetByName("return_contribution")))
q5.AppendSlice(&rspObj.Rows, p)
} }
}) })
} }
}
q5.Sort(rspObj.Rows, func(a *info, b *info) bool {
return a.Time > b.Time
})
c.JSON(200, rspObj) c.JSON(200, rspObj)
} }
@ -95,11 +138,12 @@ func (cta *ContriApi) CECQuery(c *gin.Context) {
} `json:"info"` } `json:"info"`
}{} }{}
rspObj.CP = "12345.67" totalgcp, _ := service.Contribution.GetGlobalContribution(false)
rspObj.Info.MyCP = "12345.67" mycp, _ := service.Contribution.GetAddressContribution(account)
rspObj.Info.GCP = "12345.67" rspObj.Info.MyCP = fmt.Sprintf("%.2f", mycp)
rspObj.Info.GCEC = 10000 rspObj.Info.GCP = fmt.Sprintf("%.2f", totalgcp)
rspObj.Info.MyCEC = 10000 rspObj.Info.GCEC = 500000
rspObj.Info.MyCEC = q5.SafeToInt64(float64(rspObj.Info.GCEC) * (mycp) / totalgcp)
c.JSON(200, rspObj) c.JSON(200, rspObj)
} }

View File

@ -12,6 +12,7 @@ type accountContricution struct {
contribution float64 contribution float64
gcTime int64 gcTime int64
loweremail string loweremail string
accountid string
} }
type contribution struct { type contribution struct {
@ -30,19 +31,29 @@ 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) { func (this *contribution) GetAddressContribution(accountAddress string) (float64, error) {
return 0, nil return 0, nil
accinfo, exist := this.accountContricutionlist.Load(accountAddress) accinfo, exist := this.accountContricutionlist.Load(accountAddress)
var beforcontribution float64 = 0 var beforcontribution float64 = 0
if nowseconds := f5.GetApp().GetRealSeconds(); !exist || (*accinfo).gcTime+60 < nowseconds { if nowseconds := f5.GetApp().GetRealSeconds(); !exist || (*accinfo).gcTime+60 < nowseconds {
if !exist { if !exist {
*accinfo = new(accountContricution) info := new(accountContricution)
this.accountContricutionlist.Store(accountAddress, info)
accinfo = &info
} }
beforcontribution = (*accinfo).contribution beforcontribution = (*accinfo).contribution
if (*accinfo).loweremail == "" { if (*accinfo).loweremail == "" {
sql := `SELECT account_id FROM t_user WHERE idx > 0 AND address = ?` sql := `SELECT account_id FROM t_user WHERE idx > 0 AND address = ?`
accountid := ""
f5.GetGoStyleDb().RawQuery( f5.GetGoStyleDb().RawQuery(
constant.GAME_DB, constant.GAME_DB,
sql, sql,
@ -53,16 +64,16 @@ func (this *contribution) GetAddressContribution(accountAddress string) (float64
} }
if ds.Next() { 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 = ?` sql := `SELECT lower_case_email FROM t_immutable_account WHERE idx > 0 AND account_id = ?`
f5.GetGoStyleDb().RawQuery( f5.GetGoStyleDb().RawQuery(
constant.ACCOUNT_DB, constant.ACCOUNT_DB,
sql, sql,
[]string{accountid}, []string{(*accinfo).accountid},
func(err error, ds *f5.DataSet) { func(err error, ds *f5.DataSet) {
if err != nil { if err != nil {
return return
@ -110,12 +121,12 @@ func (this *contribution) GetAddressContribution(accountAddress string) (float64
(*accinfo).loadhistory = true (*accinfo).loadhistory = true
} }
{ if (*accinfo).accountid != "" {
sql := `SELECT SUM(contribution) FROM t_contribution WHERE idx > 0 AND user_identity = ?` sql := `SELECT contribution FROM t_contribution WHERE idx > 0 AND account_id = ?`
f5.GetGoStyleDb().RawQuery( f5.GetGoStyleDb().RawQuery(
constant.GAME_DB, constant.GAME_DB,
sql, sql,
[]string{accountAddress}, []string{(*accinfo).accountid},
func(err error, ds *f5.DataSet) { func(err error, ds *f5.DataSet) {
if err != nil { if err != nil {
return return
@ -125,8 +136,10 @@ func (this *contribution) GetAddressContribution(accountAddress string) (float64
(*accinfo).contribution, _ = q5.ToFloat64Ex(ds.GetByIndex(0)) (*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 != "" { if (*accinfo).loweremail != "" {
sql += ", " + (*accinfo).loweremail sql += ", " + (*accinfo).loweremail
} }