aozhiwei 16067f7f70 1
2024-09-18 19:31:43 +08:00

74 lines
1.4 KiB
Go

package service
import (
"q5"
"f5"
"sync"
"main/constant"
"math/big"
)
type vip struct {
lock sync.Mutex
}
func (this *vip) init() () {
}
func (this *vip) Add(accountAddress string, val string, idx int64, valField string, idxField string) bool {
this.lock.Lock()
defer this.lock.Unlock()
err, ds := f5.GetGoStyleDb().NewOrmSelect(
constant.BCNFT_DB,
"t_vip_user",
[][]string {
{"address", accountAddress},
})
if err != nil {
return false
}
nowTime := f5.GetApp().GetRealSeconds()
if ds.Next() {
bnVal, ok := new(big.Int).SetString(val, 10)
if !ok {
return false
}
bnTotal, ok := new(big.Int).SetString(ds.GetByName("escec_total"), 10)
if !ok {
return false
}
bnTotal.Add(bnTotal, bnVal)
err1, _, _ := f5.GetGoStyleDb().NewInsert(
constant.BCNFT_DB,
"t_vip_user",
[][]string {
{"account_address", accountAddress},
{valField, val},
{idxField, q5.ToString(idx)},
{"escec_total", bnTotal.String()},
{"createtime", q5.ToString(nowTime)},
{"modifytime", q5.ToString(nowTime)},
})
if err1 != nil {
return false
}
} else {
err1, _, _ := f5.GetGoStyleDb().NewInsert(
constant.BCNFT_DB,
"t_vip_user",
[][]string {
{"account_address", accountAddress},
{valField, val},
{idxField, q5.ToString(idx)},
{"escec_total", val},
{"createtime", q5.ToString(nowTime)},
{"modifytime", q5.ToString(nowTime)},
})
if err1 != nil {
return false
}
}
return false
}