email contribution

This commit is contained in:
yangduo 2024-08-20 11:44:07 +08:00
parent f9387d345f
commit aa8d1e27cf
2 changed files with 95 additions and 12 deletions

View File

@ -1,7 +1,13 @@
package activity package activity
import ( import (
"f5"
"fmt"
"main/constant"
"main/service"
"q5" "q5"
"strings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -9,7 +15,11 @@ type BitGetApi struct {
} }
func (this *BitGetApi) NewUserMission(c *gin.Context) { func (this *BitGetApi) NewUserMission(c *gin.Context) {
email := strings.ToLower(c.DefaultQuery("email", ""))
rspObj := struct { rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
CP string `json:"contributionPoint"`
Missions []struct { Missions []struct {
MissionId int32 `json:"mission_id"` MissionId int32 `json:"mission_id"`
Current int32 `json:"current"` Current int32 `json:"current"`
@ -20,5 +30,32 @@ func (this *BitGetApi) NewUserMission(c *gin.Context) {
p := q5.NewSliceElement(&rspObj.Missions) p := q5.NewSliceElement(&rspObj.Missions)
p.MissionId = 1 p.MissionId = 1
p.Target = 5 p.Target = 5
if email != "" {
mycp, accountid, _ := service.Contribution.GetEmailContributionAccountid(email)
rspObj.CP = fmt.Sprintf("%.2f", mycp)
if accountid != "" {
sql := `SELECT count(idx) FROM t_battle_settlement_single 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
}
if ds.Next() {
p.Current = q5.SafeToInt32(ds.GetByIndex(0))
if p.Current > p.Target {
p.Current = p.Target
}
}
})
}
}
c.JSON(200, rspObj) c.JSON(200, rspObj)
} }

View File

@ -8,7 +8,7 @@ import (
"time" "time"
) )
type accountContricution struct { type accountContribution struct {
history float64 history float64
loadhistory bool loadhistory bool
contribution float64 contribution float64
@ -23,11 +23,13 @@ type contribution struct {
globalContribution float64 globalContribution float64
gcTime int64 gcTime int64
accountContricutionlist q5.ConcurrentMap[string, *accountContricution] accountContributionlist q5.ConcurrentMap[string, *accountContribution]
emailContributionlist q5.ConcurrentMap[string, *accountContribution]
} }
func (this *contribution) init() { func (this *contribution) init() {
this.accountContricutionlist = q5.ConcurrentMap[string, *accountContricution]{} this.accountContributionlist = q5.ConcurrentMap[string, *accountContribution]{}
this.emailContributionlist = q5.ConcurrentMap[string, *accountContribution]{}
go this.checkContributionList() go this.checkContributionList()
} }
@ -35,8 +37,45 @@ func (this *contribution) unInit() {
} }
func (this *contribution) GetEmailContributionAccountid(email string) (float64, string, error) {
info, exist := this.emailContributionlist.Load(email)
if exist {
return (*info).contribution, (*info).accountid, nil
}
accountid := ""
accountAddress := ""
sql := `SELECT account_id, address FROM t_immutable_account WHERE idx > 0 AND lower_case_email = ?`
f5.GetGoStyleDb().RawQuery(
constant.ACCOUNT_DB,
sql,
[]string{email},
func(err error, ds *f5.DataSet) {
if err != nil {
return
}
if ds.Next() {
accountid = ds.GetByIndex(0)
accountAddress = ds.GetByIndex(1)
}
})
if accountAddress != "" {
contrinfo := new(accountContribution)
contrinfo.loweremail = email
contrinfo.accountid = accountid
this.accountContributionlist.Store(accountAddress, contrinfo)
contri, _ := this.GetAddressContribution(accountAddress, false)
return contri, accountid, nil
}
return 0, accountid, nil
}
func (this *contribution) GetEmailAccountId(accountAddress string) (string, string) { func (this *contribution) GetEmailAccountId(accountAddress string) (string, string) {
accinfo, exist := this.accountContricutionlist.Load(accountAddress) accinfo, exist := this.accountContributionlist.Load(accountAddress)
if exist { if exist {
return (*accinfo).loweremail, (*accinfo).accountid return (*accinfo).loweremail, (*accinfo).accountid
} }
@ -45,12 +84,12 @@ func (this *contribution) GetEmailAccountId(accountAddress string) (string, stri
} }
func (this *contribution) GetAddressContribution(accountAddress string, onlyrecharge bool) (float64, error) { func (this *contribution) GetAddressContribution(accountAddress string, onlyrecharge bool) (float64, error) {
accinfo, exist := this.accountContricutionlist.Load(accountAddress) accinfo, exist := this.accountContributionlist.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 {
info := new(accountContricution) info := new(accountContribution)
this.accountContricutionlist.Store(accountAddress, info) this.accountContributionlist.Store(accountAddress, info)
accinfo = &info accinfo = &info
} }
beforcontribution = (*accinfo).contribution beforcontribution = (*accinfo).contribution
@ -169,6 +208,9 @@ func (this *contribution) GetAddressContribution(accountAddress string, onlyrech
(*accinfo).contribution += (*accinfo).history (*accinfo).contribution += (*accinfo).history
(*accinfo).gcTime = nowseconds (*accinfo).gcTime = nowseconds
if (*accinfo).loweremail != "" {
this.emailContributionlist.Store((*accinfo).loweremail, *accinfo)
}
} }
if beforcontribution != (*accinfo).contribution { if beforcontribution != (*accinfo).contribution {
@ -260,7 +302,7 @@ func (this *contribution) checkContributionList() {
if time.Now().UTC().Hour() == 0 { if time.Now().UTC().Hour() == 0 {
nowseconds := f5.GetApp().GetRealSeconds() nowseconds := f5.GetApp().GetRealSeconds()
deletelist := []string{} deletelist := []string{}
this.accountContricutionlist.Range(func(key string, value *accountContricution) bool { this.accountContributionlist.Range(func(key string, value *accountContribution) bool {
if value.gcTime+86400 < nowseconds { if value.gcTime+86400 < nowseconds {
deletelist = append(deletelist, key) deletelist = append(deletelist, key)
} }
@ -268,7 +310,11 @@ func (this *contribution) checkContributionList() {
}) })
for _, account := range deletelist { for _, account := range deletelist {
this.accountContricutionlist.Delete(account) v, _ := this.accountContributionlist.Load(account)
if (*v).loweremail != "" {
this.emailContributionlist.Delete((*v).loweremail)
}
this.accountContributionlist.Delete(account)
} }
} }
time.Sleep((time.Second * 1800)) time.Sleep((time.Second * 1800))