This commit is contained in:
aozhiwei 2024-06-25 20:11:51 +08:00
parent ad988d90b6
commit 559e2f2ee2
5 changed files with 136 additions and 43 deletions

View File

@ -1,4 +1,6 @@
{
"gameapi_url": "https://game2006api-test.kingsome.cn",
"net_id": 13473
"net_id": 13473,
"immutable_base_url": "https://api.sandbox.immutable.com",
"chain_name": "imtbl-zkevm-testnet"
}

View File

@ -49,6 +49,8 @@ type BcEventDb struct {
type Config struct {
gameapi_url string
net_id int32
immutable_base_url string
chain_name string
_flags1_ uint64
_flags2_ uint64
@ -72,15 +74,6 @@ type Language struct {
_flags2_ uint64
}
type Mail struct {
name string
subject string
content string
_flags1_ uint64
_flags2_ uint64
}
type RankSeason struct {
id int32
name string
@ -261,6 +254,22 @@ func (this *Config) HasNetId() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *Config) GetImmutableBaseUrl() string {
return this.immutable_base_url
}
func (this *Config) HasImmutableBaseUrl() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *Config) GetChainName() string {
return this.chain_name
}
func (this *Config) HasChainName() bool {
return (this._flags1_ & (uint64(1) << 4)) > 0
}
func (this *Item) GetName() string {
return this.name
}
@ -309,30 +318,6 @@ func (this *Language) HasEn() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *Mail) GetName() string {
return this.name
}
func (this *Mail) HasName() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *Mail) GetSubject() string {
return this.subject
}
func (this *Mail) HasSubject() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *Mail) GetContent() string {
return this.content
}
func (this *Mail) HasContent() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *RankSeason) GetId() int32 {
return this.id
}
@ -431,6 +416,8 @@ func (this *BcEventDb) LoadFromKv(kv map[string]interface{}) {
func (this *Config) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.gameapi_url, "gameapi_url", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.net_id, "net_id", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.immutable_base_url, "immutable_base_url", &this._flags1_, 3, kv)
f5.ReadMetaTableField(&this.chain_name, "chain_name", &this._flags1_, 4, kv)
}
func (this *Item) LoadFromKv(kv map[string]interface{}) {
@ -445,12 +432,6 @@ func (this *Language) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.en, "en", &this._flags1_, 2, kv)
}
func (this *Mail) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.name, "name", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.subject, "subject", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.content, "content", &this._flags1_, 3, kv)
}
func (this *RankSeason) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.id, "id", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.name, "name", &this._flags1_, 2, kv)

View File

@ -40,6 +40,8 @@ message Config
{
optional string gameapi_url = 1;
optional int32 net_id = 2;
optional string immutable_base_url = 3;
optional string chain_name = 4;
}
message Item

View File

@ -80,3 +80,70 @@ func OpenGoldBullion(accountId string, accountAddress string, netId int32, token
result := false
return result
}
func ReturnGoldBullion(accountId string, accountAddress string, netId int32, tokenId string) bool {
GetTaskMgr().LockOpenGodBullion()
defer GetTaskMgr().UnLockOpenGodBullion()
if !AccountIdExistsAndIgnoreError(accountId) {
return false
}
var itemId int32
if !GetNoOpenGoldBullionItemIdByTokenId(tokenId, &itemId) {
return false
}
goldNum := jccommon.GetGoldBullionGoldNum(itemId)
if goldNum <= 0 {
return false
}
{
var dbErr error
nowTime := f5.GetApp().GetRealSeconds()
f5.GetGoStyleDb().Update(
constant.GAME_DB,
"t_gold_bullion",
[][]string {
{"token_id", tokenId},
},
[][]string {
{"return_status", q5.ToString(1)},
{"returned", q5.ToString(1)},
{"return_time", q5.ToString(nowTime)},
},
func (err error, lastInsertId int64, rowsAffected int64) {
dbErr = err
})
if dbErr != nil {
return false
}
}
{
if !UserAddGold(accountId, goldNum) {
return false
}
}
{
var dbErr error
f5.GetGoStyleDb().Update(
constant.GAME_DB,
"t_gold_bullion",
[][]string {
{"token_id", tokenId},
},
[][]string {
{"return_status", q5.ToString(2)},
},
func (err error, lastInsertId int64, rowsAffected int64) {
dbErr = err
})
if dbErr != nil {
return false
}
}
return true
}

View File

@ -1,9 +1,10 @@
package task
import (
//"q5"
"q5"
"f5"
"time"
"mt"
"fmt"
"main/constant"
)
@ -21,12 +22,12 @@ func (this* goldBullionReturn) unInit() {
func (this* goldBullionReturn) loadExpiredGoldBullion() {
f5.GetGoStyleDb().LoopLoad(
constant.BCNFT_DB,
constant.GAME_DB,
func (lastIdx int64) string {
nowTime := f5.GetApp().GetRealSeconds()
expiredTime := nowTime - 3600 * 24 - 60 * 5
sql := fmt.Sprintf(`
SELECT * FROM t_gold_bullion WHERE idx > %d AND activated = 0 AND createtime < %d LIMIT 1000`,
SELECT * FROM t_gold_bullion WHERE idx > %d AND activated = 0 AND returned = 0 AND createtime < %d LIMIT 1000`,
lastIdx,
expiredTime)
return sql
@ -43,5 +44,45 @@ SELECT * FROM t_gold_bullion WHERE idx > %d AND activated = 0 AND createtime < %
}
func (this* goldBullionReturn) returnGold(ds *f5.DataSet) bool {
contractAddress := ds.GetByName("contract_address")
tokenId := ds.GetByName("token_id")
{
rspObj := struct {
Result *struct {
TokenId string `json:"token_id"`
} `json:"result"`
}{}
url := fmt.Sprintf("https://%s/v1/chains/%s/collections/%s:/nfts/%s",
mt.Table.Config.GetById(0).GetImmutableBaseUrl(),
mt.Table.Config.GetById(0).GetChainName(),
contractAddress,
tokenId)
var httpErr error
f5.GetHttpCliMgr().SendGoStyleRequest(
url,
map[string]string{},
func (rsp f5.HttpCliResponse) {
httpErr = rsp.GetErr()
if rsp.GetErr() != nil {
f5.GetSysLog().Info("returnGold immutable api:%s request error:%s",
url,
rsp.GetErr())
return
}
if err := q5.DecodeJson("", &rspObj); err != nil {
f5.GetSysLog().Info("returnGold immutable api:%s decodeJson error:%s",
url,
err)
}
})
if httpErr != nil {
return false
}
if rspObj.Result.TokenId == tokenId {
f5.GetSysLog().Info("returnGold tokenId:%s exists",
tokenId)
return true
}
}
return true
}