From ca75efd0bbdea92ba1c96bb1b52a6a5427534eaa Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 25 Jun 2024 11:42:44 +0800 Subject: [PATCH] 1 --- server/backtask/service/nftutils.go | 20 +++++ .../task/spec_transfer721/gold_bullion.go | 81 ++++++++++++++++++- 2 files changed, 98 insertions(+), 3 deletions(-) diff --git a/server/backtask/service/nftutils.go b/server/backtask/service/nftutils.go index 6342f8e4..f31e926b 100644 --- a/server/backtask/service/nftutils.go +++ b/server/backtask/service/nftutils.go @@ -85,3 +85,23 @@ func GetGoldBullionByNetIdTokenId(netId int32, tokenId string, itemId *int32) bo }) return result } + +func GetGoldBullionByTokenId(tokenId string, itemId *int32) bool { + result := false + f5.GetGoStyleDb().OrmSelectOne( + constant.GAME_DB, + "t_gold_bullion", + [][]string { + {"token_id", tokenId}, + }, + func (err error, ds *f5.DataSet) { + if err != nil { + return + } + if ds.Next() { + *itemId = q5.ToInt32(ds.GetByName("item_id")) + result = true + } + }) + return result +} diff --git a/server/backtask/task/spec_transfer721/gold_bullion.go b/server/backtask/task/spec_transfer721/gold_bullion.go index 7e383f19..a3c6b7a1 100644 --- a/server/backtask/task/spec_transfer721/gold_bullion.go +++ b/server/backtask/task/spec_transfer721/gold_bullion.go @@ -1,24 +1,99 @@ package spec_transfer721 +import ( + "q5" + "f5" + "main/service" + "main/constant" + "mt" + "jccommon" + "fmt" +) + type goldBullion struct { + mailCfgHash *q5.ConcurrentMap[string, *jccommon.MailConfig] } func (this* goldBullion) onMint(dbIdx int64, netId int32, contractAddress string, tokenId string, from string, to string) bool { - return true + ok := this.internalSendMail(dbIdx, to, constant.MAIL_GOLD_BULLION_MINT, tokenId) + return ok } func (this* goldBullion) onLock(dbIdx int64, netId int32, contractAddress string, tokenId string, from string, to string) bool { - return true + ok := this.internalSendMail(dbIdx, from, constant.MAIL_GOLD_BULLION_LOCK, tokenId) + return ok } func (this *goldBullion) onUnlock(dbIdx int64, netId int32, contractAddress string, tokenId string, from string, to string) bool { - return true + ok := this.internalSendMail(dbIdx, to, constant.MAIL_GOLD_BULLION_UNLOCK, tokenId) + return ok +} + +func (this* goldBullion) internalSendMail(dbIdx int64, accountAddress string, mailName string, tokenId string) bool { + var itemId int32 + if !service.GetGoldBullionByTokenId(tokenId, &itemId) { + return true + } + 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() + 3600 * 24 * 7 + subject := mailMeta.GetTitle() + content := mailMeta.ReplaceContent(map[string]string{ + "${goldBullion.name}": itemMeta.GetRealName(), + }) + uniKey := fmt.Sprintf("%s_%s_%d", mailName, tokenId, dbIdx) + sendOk := service.SendSysMail( + uniKey, + accountId, + subject, + content, + q5.ToInt32(nowTime), + mailCfg.Tag1, + mailCfg.Tag2) + if sendOk { + return service.UpdateSpecTransferStatus(dbIdx, 1) + } + return false +} + +func (this *goldBullion) getMailConfig(mailName string) *jccommon.MailConfig { + if v, ok := this.mailCfgHash.Load(mailName); ok { + return *v + } else { + return nil + } +} + +func (this *goldBullion) 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) } func newGoldBullion() *goldBullion { p := new(goldBullion) + p.mailCfgHash = new(q5.ConcurrentMap[string, *jccommon.MailConfig]) + p.registerMailConfig(constant.MAIL_GOLD_BULLION_MINT, jccommon.MAIL_TAG1_GOLD_BULLION, jccommon.MAIL_TAG2_GOLD_BULLION_MINT) + p.registerMailConfig(constant.MAIL_GOLD_BULLION_LOCK, jccommon.MAIL_TAG1_GOLD_BULLION, jccommon.MAIL_TAG2_GOLD_BULLION_LOCK) + p.registerMailConfig(constant.MAIL_GOLD_BULLION_UNLOCK, jccommon.MAIL_TAG1_GOLD_BULLION, jccommon.MAIL_TAG2_GOLD_BULLION_UNLOCK) return p }