77 lines
1.6 KiB
Go
77 lines
1.6 KiB
Go
package service
|
|
|
|
import (
|
|
"q5"
|
|
"f5"
|
|
"sync"
|
|
"strings"
|
|
"main/constant"
|
|
)
|
|
|
|
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 {
|
|
return this.AddEx(accountAddress, val, idx, valField, idxField, [][]string{})
|
|
}
|
|
|
|
func (this *vip) AddEx(accountAddress string, val string, idx int64, valField string, idxField string,
|
|
extKv [][]string) bool {
|
|
this.lock.Lock()
|
|
defer this.lock.Unlock()
|
|
|
|
accountAddress = strings.ToLower(accountAddress)
|
|
err, ds := f5.GetGoStyleDb().NewOrmSelect(
|
|
constant.BCNFT_DB,
|
|
"t_vip_user",
|
|
[][]string {
|
|
{"address", accountAddress},
|
|
})
|
|
if err != nil {
|
|
return false
|
|
}
|
|
nowTime := f5.GetApp().GetRealSeconds()
|
|
updateKv := [][]string {
|
|
{valField, val},
|
|
{idxField, q5.ToString(idx)},
|
|
{"modifytime", q5.ToString(nowTime)},
|
|
}
|
|
insertKv := [][]string {
|
|
{"account_address", accountAddress},
|
|
{valField, val},
|
|
{idxField, q5.ToString(idx)},
|
|
{"createtime", q5.ToString(nowTime)},
|
|
{"modifytime", q5.ToString(nowTime)},
|
|
}
|
|
updateKv = append(updateKv, extKv...)
|
|
insertKv = append(insertKv, extKv...)
|
|
if ds.Next() {
|
|
if q5.ToInt64(ds.GetByName(idxField)) <= idx {
|
|
return true
|
|
}
|
|
err1, _, _ := f5.GetGoStyleDb().NewUpdate(
|
|
constant.BCNFT_DB,
|
|
"t_vip_user",
|
|
[][]string {
|
|
{"address", accountAddress},
|
|
},
|
|
updateKv)
|
|
if err1 != nil {
|
|
return false
|
|
}
|
|
} else {
|
|
err1, _, _ := f5.GetGoStyleDb().NewInsert(
|
|
constant.BCNFT_DB,
|
|
"t_vip_user",
|
|
insertKv)
|
|
if err1 != nil {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|