This commit is contained in:
aozhiwei 2024-07-05 15:41:00 +08:00
parent 36fbd33dab
commit 70c63765b9
2 changed files with 138 additions and 13 deletions

View File

@ -90,8 +90,7 @@ func OpenGoldBullion(accountId string, accountAddress string, netId int32, token
return false
}
}
result := false
return result
return true
}
func ReturnGoldBullion(accountId string, netId int32, tokenId string) bool {

View File

@ -5,6 +5,8 @@ import (
"f5"
"fmt"
"strings"
"mt"
"jccommon"
"main/constant"
"main/service"
"math/rand"
@ -18,10 +20,14 @@ type lockReturnValues struct {
}
type nftLock struct {
mailCfgHash *q5.ConcurrentMap[string, *jccommon.MailConfig]
}
func (this* nftLock) init() {
this.mailCfgHash = new(q5.ConcurrentMap[string, *jccommon.MailConfig])
this.registerMailConfig(constant.MAIL_GOLD_BULLION_LOCK,
jccommon.MAIL_TAG1_GOLD_BULLION,
jccommon.MAIL_TAG2_GOLD_BULLION_LOCK)
go this.process()
}
@ -73,18 +79,138 @@ func (this* nftLock) repair(ds *f5.DataSet) bool {
}
}
if nftUseStatus == 0 {
/*
goldContractMeta := mt.Table.Contract.GetByNetIdName(netId, jccommon.)
p := new(lockReturnValues)
if q5.DecodeJson(ds.GetByName("return_values"), p) == nil {
for _, val := range p.TokenIds {
contractAddress := strings.ToLower(p.Nft)
tokenId := val
if service.NftExists(netId, contractAddress, tokenId) {
service.NftUpdateLock(netId, contractAddress, tokenId, idx, lockTo)
}
}
}*/
this.useNft(idx, netId, lockTo, p)
}
}
return true
}
func (this *nftLock) useNft(dbIdx int64, netId int32, lockTo string, p *lockReturnValues) {
lockTo = strings.ToLower(lockTo)
contractAddress := strings.ToLower(p.Nft)
goldMeta := mt.Table.Contract.GetByNetIdName(netId, jccommon.CONTRACT_NAME_GoldBrick)
if goldMeta == nil {
return
}
if contractAddress != strings.ToLower(goldMeta.GetAddress()) {
f5.GetGoStyleDb().Update(
constant.BCEVENT_DB,
"t_nft_lock_event",
[][]string {
{"idx", q5.ToString(dbIdx)},
},
[][]string {
{"nft_use_status", q5.ToString(1)},
},
func (err error, lastInsertId int64, rowsAffected int64) {
})
return
}
accountId := service.GetAccountIdByAddress(lockTo)
if accountId == "" {
return
}
ok := true
for _, tokenId := range p.TokenIds {
var itemId int32
if service.GetGoldBullionByNetIdTokenId(netId, tokenId, &itemId) {
if service.OpenGoldBullion(accountId, lockTo, netId, tokenId) {
if this.internalSendMail(dbIdx, lockTo, constant.MAIL_GOLD_BULLION_LOCK, tokenId) {
} else {
ok = false
break
}
} else {
ok = false
break
}
} else {
ok = false
break
}
}
if ok {
f5.GetGoStyleDb().Update(
constant.BCEVENT_DB,
"t_nft_lock_event",
[][]string {
{"idx", q5.ToString(dbIdx)},
},
[][]string {
{"nft_use_status", q5.ToString(1)},
},
func (err error, lastInsertId int64, rowsAffected int64) {
})
}
}
func (this* nftLock) internalSendMail(dbIdx int64, accountAddress string, mailName string, tokenId string) bool {
var itemId int32
if !service.GetGoldBullionItemIdByTokenId(tokenId, &itemId) {
return true
}
goldNum := jccommon.GetGoldBullionGoldNum(itemId)
goldNumStr := this.formatGoldNum(goldNum)
itemMeta := mt.Table.Item.GetById(q5.ToInt64(itemId))
if itemMeta == nil {
return true
}
accountId := service.GetAccountIdByAddress(accountAddress)
if accountId == "" {
return true
}
mailMeta := mt.Table.Mail.GetByName(mailName)
if mailMeta == nil {
return true
}
mailCfg := this.getMailConfig(mailName)
if mailCfg == nil {
return true
}
nowTime := f5.GetApp().GetRealSeconds()
subject := mailMeta.GetTitle()
content := mailMeta.ReplaceContent(map[string]string{
"${item.name}": itemMeta.GetRealName(),
"${gold}": goldNumStr,
})
uniKey := fmt.Sprintf("%s_%s_%d", mailName, tokenId, dbIdx)
sendOk := service.SendSysMail(
uniKey,
accountId,
subject,
content,
q5.ToInt32(nowTime),
q5.ToInt32(nowTime) + 3600 * 24 * 7,
mailCfg.Tag1,
mailCfg.Tag2)
return sendOk
}
func (this *nftLock) formatGoldNum(goldNum int32) string {
if goldNum == 1000 {
return "1,000"
} else if goldNum == 10000 {
return "10,000"
}
return q5.ToString(goldNum)
}
func (this *nftLock) getMailConfig(mailName string) *jccommon.MailConfig {
if v, ok := this.mailCfgHash.Load(mailName); ok {
return *v
} else {
return nil
}
}
func (this *nftLock) registerMailConfig(mailName string, tag1 int32, tag2 int32) {
p := new(jccommon.MailConfig)
p.MailName = mailName
p.Tag1 = tag1
p.Tag2 = tag2
this.mailCfgHash.Store(mailName, p)
}