247 lines
5.6 KiB
Go
247 lines
5.6 KiB
Go
package service
|
|
|
|
import (
|
|
"f5"
|
|
"main/constant"
|
|
"q5"
|
|
)
|
|
|
|
type accountContricution struct {
|
|
history float64
|
|
loadhistory bool
|
|
contribution float64
|
|
gcTime int64
|
|
loweremail string
|
|
accountid string
|
|
}
|
|
|
|
type contribution struct {
|
|
historyContribution float64
|
|
globalContribution float64
|
|
gcTime int64
|
|
|
|
accountContricutionlist q5.ConcurrentMap[string, *accountContricution]
|
|
}
|
|
|
|
func (this *contribution) init() {
|
|
this.accountContricutionlist = q5.ConcurrentMap[string, *accountContricution]{}
|
|
}
|
|
|
|
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 {
|
|
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 = ?`
|
|
f5.GetGoStyleDb().RawQuery(
|
|
constant.GAME_DB,
|
|
sql,
|
|
[]string{accountAddress},
|
|
func(err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if ds.Next() {
|
|
(*accinfo).accountid = ds.GetByIndex(0)
|
|
}
|
|
})
|
|
|
|
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{(*accinfo).accountid},
|
|
func(err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if ds.Next() {
|
|
(*accinfo).loweremail = ds.GetByIndex(0)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
if !(*accinfo).loadhistory {
|
|
sql := `SELECT contribution FROM t_contribution WHERE idx > 0 and account_address = ?`
|
|
f5.GetGoStyleDb().RawQuery(
|
|
constant.BCNFT_DB,
|
|
sql,
|
|
[]string{accountAddress},
|
|
func(err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if ds.Next() {
|
|
(*accinfo).history, _ = q5.ToFloat64Ex(ds.GetByIndex(0))
|
|
}
|
|
})
|
|
|
|
sql = `SELECT SUM(contribution) FROM t_staking_daily_settlement WHERE idx > 0 and account_address = ?`
|
|
f5.GetGoStyleDb().RawQuery(
|
|
constant.BCNFT_DB,
|
|
sql,
|
|
[]string{accountAddress},
|
|
func(err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if ds.Next() {
|
|
tmp, _ := q5.ToFloat64Ex(ds.GetByIndex(0))
|
|
(*accinfo).history += tmp
|
|
}
|
|
})
|
|
|
|
(*accinfo).loadhistory = true
|
|
}
|
|
|
|
if (*accinfo).accountid != "" {
|
|
sql := `SELECT contribution FROM t_contribution WHERE idx > 0 AND account_id = ?`
|
|
f5.GetGoStyleDb().RawQuery(
|
|
constant.GAME_DB,
|
|
sql,
|
|
[]string{(*accinfo).accountid},
|
|
func(err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if ds.Next() {
|
|
(*accinfo).contribution, _ = q5.ToFloat64Ex(ds.GetByIndex(0))
|
|
}
|
|
})
|
|
}
|
|
|
|
{
|
|
params := []string{accountAddress}
|
|
sql := `SELECT SUM(return_contribution) FROM t_recharge_return_contribution WHERE idx > 0 AND user_identity IN (?`
|
|
if (*accinfo).loweremail != "" {
|
|
sql += ", ?"
|
|
params = append(params, (*accinfo).loweremail)
|
|
}
|
|
sql += ")"
|
|
|
|
f5.GetGoStyleDb().RawQuery(
|
|
constant.BCNFT_DB,
|
|
sql,
|
|
params,
|
|
func(err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if ds.Next() {
|
|
tmp, _ := q5.ToFloat64Ex(ds.GetByIndex(0))
|
|
(*accinfo).contribution += tmp
|
|
}
|
|
})
|
|
}
|
|
|
|
(*accinfo).contribution += (*accinfo).history
|
|
(*accinfo).gcTime = nowseconds
|
|
}
|
|
|
|
if beforcontribution != (*accinfo).contribution {
|
|
this.GetGlobalContribution(true)
|
|
}
|
|
|
|
return (*accinfo).contribution, nil
|
|
}
|
|
|
|
func (this *contribution) GetGlobalContribution(instant bool) (float64, error) {
|
|
if this.historyContribution < 0.000001 {
|
|
sql := `SELECT SUM(contribution) FROM t_contribution WHERE idx > 0`
|
|
f5.GetGoStyleDb().RawQuery(
|
|
constant.BCNFT_DB,
|
|
sql,
|
|
[]string{},
|
|
func(err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if ds.Next() {
|
|
this.historyContribution, _ = q5.ToFloat64Ex(ds.GetByIndex(0))
|
|
}
|
|
})
|
|
|
|
sql = `SELECT SUM(contribution) FROM t_staking_daily_settlement WHERE idx > 0`
|
|
f5.GetGoStyleDb().RawQuery(
|
|
constant.BCNFT_DB,
|
|
sql,
|
|
[]string{},
|
|
func(err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if ds.Next() {
|
|
tmp, _ := q5.ToFloat64Ex(ds.GetByIndex(0))
|
|
this.historyContribution += tmp
|
|
}
|
|
})
|
|
}
|
|
|
|
if nowseconds := f5.GetApp().GetRealSeconds(); nowseconds > this.gcTime+60 || instant {
|
|
sql := `SELECT SUM(contribution) FROM t_contribution WHERE idx > 0`
|
|
f5.GetGoStyleDb().RawQuery(
|
|
constant.GAME_DB,
|
|
sql,
|
|
[]string{},
|
|
func(err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if ds.Next() {
|
|
this.globalContribution, _ = q5.ToFloat64Ex(ds.GetByIndex(0))
|
|
}
|
|
})
|
|
sql = `SELECT SUM(return_contribution) FROM t_recharge_return_contribution WHERE idx > 0`
|
|
f5.GetGoStyleDb().RawQuery(
|
|
constant.BCNFT_DB,
|
|
sql,
|
|
[]string{},
|
|
func(err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if ds.Next() {
|
|
tmp, _ := q5.ToFloat64Ex(ds.GetByIndex(0))
|
|
this.globalContribution += tmp
|
|
}
|
|
})
|
|
|
|
this.globalContribution += this.historyContribution
|
|
this.gcTime = nowseconds
|
|
}
|
|
|
|
return this.globalContribution, nil
|
|
}
|