diff --git a/server/marketserver/api/v1/activity/bitget.go b/server/marketserver/api/v1/activity/bitget.go index b2b24ea4..e7a1f079 100644 --- a/server/marketserver/api/v1/activity/bitget.go +++ b/server/marketserver/api/v1/activity/bitget.go @@ -1,7 +1,13 @@ package activity import ( + "f5" + "fmt" + "main/constant" + "main/service" "q5" + "strings" + "github.com/gin-gonic/gin" ) @@ -9,16 +15,47 @@ type BitGetApi struct { } func (this *BitGetApi) NewUserMission(c *gin.Context) { + email := strings.ToLower(c.DefaultQuery("email", "")) rspObj := struct { - Missions []struct{ + ErrCode int32 `json:"errcode"` + ErrMsg string `json:"errmsg"` + CP string `json:"contributionPoint"` + Missions []struct { MissionId int32 `json:"mission_id"` - Current int32 `json:"current"` - Target int32 `json:"target"` + Current int32 `json:"current"` + Target int32 `json:"target"` } `json:"missions"` }{} q5.NewSlice(&rspObj.Missions, 0, 10) p := q5.NewSliceElement(&rspObj.Missions) p.MissionId = 1 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) } diff --git a/server/marketserver/service/contribution.go b/server/marketserver/service/contribution.go index 29eeacd4..ea604040 100644 --- a/server/marketserver/service/contribution.go +++ b/server/marketserver/service/contribution.go @@ -8,7 +8,7 @@ import ( "time" ) -type accountContricution struct { +type accountContribution struct { history float64 loadhistory bool contribution float64 @@ -23,11 +23,13 @@ type contribution struct { globalContribution float64 gcTime int64 - accountContricutionlist q5.ConcurrentMap[string, *accountContricution] + accountContributionlist q5.ConcurrentMap[string, *accountContribution] + emailContributionlist q5.ConcurrentMap[string, *accountContribution] } 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() } @@ -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) { - accinfo, exist := this.accountContricutionlist.Load(accountAddress) + accinfo, exist := this.accountContributionlist.Load(accountAddress) if exist { 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) { - accinfo, exist := this.accountContricutionlist.Load(accountAddress) + accinfo, exist := this.accountContributionlist.Load(accountAddress) var beforcontribution float64 = 0 if nowseconds := f5.GetApp().GetRealSeconds(); !exist || (*accinfo).gcTime+60 < nowseconds { if !exist { - info := new(accountContricution) - this.accountContricutionlist.Store(accountAddress, info) + info := new(accountContribution) + this.accountContributionlist.Store(accountAddress, info) accinfo = &info } beforcontribution = (*accinfo).contribution @@ -169,6 +208,9 @@ func (this *contribution) GetAddressContribution(accountAddress string, onlyrech (*accinfo).contribution += (*accinfo).history (*accinfo).gcTime = nowseconds + if (*accinfo).loweremail != "" { + this.emailContributionlist.Store((*accinfo).loweremail, *accinfo) + } } if beforcontribution != (*accinfo).contribution { @@ -260,7 +302,7 @@ func (this *contribution) checkContributionList() { if time.Now().UTC().Hour() == 0 { nowseconds := f5.GetApp().GetRealSeconds() 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 { deletelist = append(deletelist, key) } @@ -268,7 +310,11 @@ func (this *contribution) checkContributionList() { }) 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))