calc vip_lv

This commit is contained in:
yangduo 2024-10-17 14:44:11 +08:00
parent e57b3051f5
commit 3957d8f9a8
5 changed files with 253 additions and 0 deletions

View File

@ -0,0 +1,14 @@
package mt
import (
"f5"
"main/mtb"
)
type StakingVip struct {
mtb.StakingVip
}
type StakingVipTable struct {
f5.IdMetaTable[StakingVip]
}

View File

@ -19,6 +19,7 @@ type table struct {
HashRateCommon *HashRateCommonTable
Contract *ContractTable
BcCurrency *BcCurrencyTable
StakingVip *StakingVipTable
}
var Table = f5.New(func(this *table) {
@ -86,4 +87,9 @@ var Table = f5.New(func(this *table) {
this.PrimKey = "name"
})
this.StakingVip = f5.New(func(this *StakingVipTable) {
this.FileName = "../res/stakingVip@stakingVip.json"
this.PrimKey = "rank"
})
})

View File

@ -138,6 +138,21 @@ type HashRateCommon struct {
_flags2_ uint64
}
type StakingVip struct {
rights string
require int64
thisPoint int64
rank int32
vip_name string
rate float64
vip_working_tips string
vip_unworking_tips string
id int32
_flags1_ uint64
_flags2_ uint64
}
func (this *BackTaskCluster) GetInstanceId() int32 {
return this.instance_id
}
@ -634,6 +649,78 @@ func (this *HashRateCommon) HasCecPool() bool {
return (this._flags1_ & (uint64(1) << 4)) > 0
}
func (this *StakingVip) GetRights() string {
return this.rights
}
func (this *StakingVip) HasRights() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *StakingVip) GetRequire() int64 {
return this.require
}
func (this *StakingVip) HasRequire() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *StakingVip) GetThisPoint() int64 {
return this.thisPoint
}
func (this *StakingVip) HasThisPoint() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *StakingVip) GetRank() int32 {
return this.rank
}
func (this *StakingVip) HasRank() bool {
return (this._flags1_ & (uint64(1) << 4)) > 0
}
func (this *StakingVip) GetVipName() string {
return this.vip_name
}
func (this *StakingVip) HasVipName() bool {
return (this._flags1_ & (uint64(1) << 5)) > 0
}
func (this *StakingVip) GetRate() float64 {
return this.rate
}
func (this *StakingVip) HasRate() bool {
return (this._flags1_ & (uint64(1) << 6)) > 0
}
func (this *StakingVip) GetVipWorkingTips() string {
return this.vip_working_tips
}
func (this *StakingVip) HasVipWorkingTips() bool {
return (this._flags1_ & (uint64(1) << 7)) > 0
}
func (this *StakingVip) GetVipUnworkingTips() string {
return this.vip_unworking_tips
}
func (this *StakingVip) HasVipUnworkingTips() bool {
return (this._flags1_ & (uint64(1) << 8)) > 0
}
func (this *StakingVip) GetId() int32 {
return this.id
}
func (this *StakingVip) HasId() bool {
return (this._flags1_ & (uint64(1) << 9)) > 0
}
func (this *BackTaskCluster) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv)
@ -732,3 +819,15 @@ func (this *HashRateCommon) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.end_time, "end_time", &this._flags1_, 3, kv)
f5.ReadMetaTableField(&this.cec_pool, "cec_pool", &this._flags1_, 4, kv)
}
func (this *StakingVip) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.rights, "rights", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.require, "require", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.thisPoint, "thisPoint", &this._flags1_, 3, kv)
f5.ReadMetaTableField(&this.rank, "rank", &this._flags1_, 4, kv)
f5.ReadMetaTableField(&this.vip_name, "vip_name", &this._flags1_, 5, kv)
f5.ReadMetaTableField(&this.rate, "rate", &this._flags1_, 6, kv)
f5.ReadMetaTableField(&this.vip_working_tips, "vip_working_tips", &this._flags1_, 7, kv)
f5.ReadMetaTableField(&this.vip_unworking_tips, "vip_unworking_tips", &this._flags1_, 8, kv)
f5.ReadMetaTableField(&this.id, "id", &this._flags1_, 9, kv)
}

View File

@ -110,4 +110,17 @@ message HashRateCommon
optional string start_time = 2;
optional string end_time = 3;
optional int32 cec_pool = 4;
}
message StakingVip
{
optional string rights = 1;
optional int64 require = 2;
optional int64 thisPoint = 3;
optional int32 rank = 4;
optional string vip_name = 5;
optional double rate = 6;
optional string vip_working_tips = 7;
optional string vip_unworking_tips = 8;
optional int32 id = 9;
}

View File

@ -3,6 +3,7 @@ package service
import (
"f5"
"main/constant"
"main/mt"
"math/big"
"q5"
"strings"
@ -31,6 +32,8 @@ func (this *vip) Add(accountAddress string, val string, idx int64, valField stri
defer this.lock.Unlock()
extKv := [][]string{}
lvParams := map[string]string{}
accountAddress = strings.ToLower(accountAddress)
err, ds := f5.GetGoStyleDb().NewOrmSelect(
constant.BCNFT_DB,
@ -66,6 +69,24 @@ func (this *vip) Add(accountAddress string, val string, idx int64, valField stri
}
bnNewVal := bnOldVal.Add(bnOldVal, bnVal)
updateKv = append(updateKv, [][]string{{valField, bnNewVal.String()}}...)
lvParams[valField] = bnNewVal.String()
if valField != "escec_balance" {
lvParams["escec_balance"] = ds.GetByName("escec_balance")
}
if valField != "escec_stacking" {
lvParams["escec_stacking"] = ds.GetByName("escec_stacking")
}
if valField != "escec_convert" {
lvParams["escec_convert"] = ds.GetByName("escec_convert")
}
lvParams["last_convert_time"] = ds.GetByName("last_convert_time")
newlv := this.calcVipLv(lvParams)
updateKv = append(updateKv, []string{"vip_lv", q5.SafeToString(newlv)})
err1, _, _ := f5.GetGoStyleDb().NewUpdate(
constant.BCNFT_DB,
@ -78,6 +99,10 @@ func (this *vip) Add(accountAddress string, val string, idx int64, valField stri
return false
}
} else {
lvParams[valField] = val
newlv := this.calcVipLv(lvParams)
insertKv = append(insertKv, []string{"vip_lv", q5.SafeToString(newlv)})
err1, _, _ := f5.GetGoStyleDb().NewInsert(
constant.BCNFT_DB,
"t_vip_user",
@ -104,6 +129,16 @@ func (this *vip) Replace(accountAddress string, val string, idx int64, valField
if err != nil {
return false
}
lvParams := map[string]string{
valField: val,
}
for _, sli := range extKv {
if len(sli) > 1 {
lvParams[sli[0]] = sli[1]
}
}
nowTime := f5.GetApp().GetRealSeconds()
updateKv := [][]string {
{valField, val},
@ -123,6 +158,26 @@ func (this *vip) Replace(accountAddress string, val string, idx int64, valField
if q5.ToInt64(ds.GetByName(idxField)) >= idx {
return true
}
if _, exist := lvParams["escec_balance"]; !exist {
lvParams["escec_balance"] = ds.GetByName("escec_balance")
}
if _, exist := lvParams["escec_stacking"]; !exist {
lvParams["escec_stacking"] = ds.GetByName("escec_stacking")
}
if _, exist := lvParams["escec_convert"]; !exist {
lvParams["escec_convert"] = ds.GetByName("escec_convert")
}
if _, exist := lvParams["last_convert_time"]; !exist {
lvParams["last_convert_time"] = ds.GetByName("last_convert_time")
}
newlv := this.calcVipLv(lvParams)
updateKv = append(updateKv, []string{"vip_lv", q5.SafeToString(newlv)})
err1, _, _ := f5.GetGoStyleDb().NewUpdate(
constant.BCNFT_DB,
"t_vip_user",
@ -134,6 +189,9 @@ func (this *vip) Replace(accountAddress string, val string, idx int64, valField
return false
}
} else {
newlv := this.calcVipLv(lvParams)
insertKv = append(insertKv, []string{"vip_lv", q5.SafeToString(newlv)})
err1, _, _ := f5.GetGoStyleDb().NewInsert(
constant.BCNFT_DB,
"t_vip_user",
@ -234,3 +292,66 @@ func (this *vip) RecalcEsCecConvert(accountAddress string) error {
}
return nil
}
func (this *vip) calcVipLv(params map[string]string) (lv int64) {
balancestr := params["escec_balance"]
if balancestr == "" {
balancestr = "0"
}
escec_balance, ok := new(big.Int).SetString(balancestr, 10)
if !ok {
escec_balance = new(big.Int).SetInt64(0)
}
stackingstr := params["escec_stacking"]
if stackingstr == "" {
stackingstr = "0"
}
escec_stacking, ok := new(big.Int).SetString(stackingstr, 10)
if !ok {
escec_stacking = new(big.Int).SetInt64(0)
}
curExec := new(big.Int).Add(escec_balance, escec_stacking)
convertstr := params["escec_convert"]
if convertstr == "" {
convertstr = "0"
}
escec_convert, ok := new(big.Int).SetString(convertstr, 10)
if !ok {
escec_convert = new(big.Int).SetInt64(0)
}
last_convert_time := q5.SafeToInt64(params["last_convert_time"])
nowsecs := f5.GetApp().GetRealSeconds()
diff := nowsecs - last_convert_time
if diff < 0 {
diff = 0
}
elapse := new(big.Int).SetInt64(diff)
depositExec := new(big.Int).Mul(escec_convert, elapse)
depositExec = depositExec.Div(depositExec, new(big.Int).SetInt64(365*24*3600))
if depositExec.Cmp(escec_convert) < 0 {
depositExec = new(big.Int).Sub(escec_convert, depositExec)
} else {
depositExec.SetInt64(0)
}
curExec = curExec.Add(curExec, depositExec)
convercurExec := new(big.Int).Div(curExec, new(big.Int).SetInt64(1000*1000*1000*1000*1000*1000)).Int64()
lv = 0
for {
cfg := mt.Table.StakingVip.GetById(lv)
nextlvcfg := mt.Table.StakingVip.GetById(lv + 1)
if cfg != nil && nextlvcfg != nil {
if cfg.GetRequire() <= convercurExec && nextlvcfg.GetRequire() > convercurExec {
return lv
}
} else {
break
}
lv++
}
return
}