From ad988d90b6f44148eec622be4cda516cedb51dad Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 25 Jun 2024 17:56:44 +0800 Subject: [PATCH] 1 --- server/backtask/service/nftutils.go | 21 ++++++++ server/backtask/service/spec_transfer.go | 63 +++++++++++++++++++----- server/backtask/service/user.go | 42 ++++++++++++++++ server/jccommon/constant.go | 10 ++++ 4 files changed, 125 insertions(+), 11 deletions(-) diff --git a/server/backtask/service/nftutils.go b/server/backtask/service/nftutils.go index 798c4c72..4e1f75c9 100644 --- a/server/backtask/service/nftutils.go +++ b/server/backtask/service/nftutils.go @@ -105,3 +105,24 @@ func GetGoldBullionItemIdByTokenId(tokenId string, itemId *int32) bool { }) return result } + +func GetNoOpenGoldBullionItemIdByTokenId(tokenId string, itemId *int32) bool { + result := false + f5.GetGoStyleDb().OrmSelectOne( + constant.GAME_DB, + "t_gold_bullion", + [][]string { + {"token_id", tokenId}, + {"status", q5.ToString(jccommon.GOLD_BULLION_NO_OPEN)}, + }, + 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/service/spec_transfer.go b/server/backtask/service/spec_transfer.go index 7f45f056..ba985df8 100644 --- a/server/backtask/service/spec_transfer.go +++ b/server/backtask/service/spec_transfer.go @@ -3,6 +3,7 @@ package service import ( "q5" "f5" + "jccommon" "main/constant" . "main/global" ) @@ -11,31 +12,71 @@ func UpdateSpecTransferStatus(dbIdx int64, status int32) bool { return true } -func OpenGoldBullion(accountId string, netId int32, tokenId string, goldNum int32) bool { +func OpenGoldBullion(accountId string, accountAddress string, netId int32, tokenId string) bool { GetTaskMgr().LockOpenGodBullion() defer GetTaskMgr().UnLockOpenGodBullion() - result := false + 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 - f5.GetGoStyleDb().OrmSelectOne( + nowTime := f5.GetApp().GetRealSeconds() + f5.GetGoStyleDb().Update( constant.GAME_DB, "t_gold_bullion", [][]string { - {"net_id", q5.ToString(netId)}, - {"token_id", tokenId}, + {"token_id", tokenId}, + {"status", q5.ToString(jccommon.GOLD_BULLION_NO_OPEN)}, }, - func (err error, ds *f5.DataSet) { + [][]string { + {"status", q5.ToString(jccommon.GOLD_BULLION_OPENED)}, + {"open_status", q5.ToString(jccommon.GOLD_BULLION_OPEN_STATUS_SENT)}, + {"open_address", accountAddress}, + {"open_time", q5.ToString(nowTime)}, + {"open_account_id", accountId}, + }, + func (err error, lastInsertId int64, rowsAffected int64) { dbErr = err - if err != nil { - return - } - if ds.Next() { - } }) 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}, + {"status", q5.ToString(jccommon.GOLD_BULLION_OPEN_STATUS_SENT)}, + }, + [][]string { + {"open_status", q5.ToString(jccommon.GOLD_BULLION_OPEN_STATUS_RECEIVED)}, + }, + func (err error, lastInsertId int64, rowsAffected int64) { + dbErr = err + }) + if dbErr != nil { + return false + } + } + result := false return result } diff --git a/server/backtask/service/user.go b/server/backtask/service/user.go index e8dcce3b..5944260f 100644 --- a/server/backtask/service/user.go +++ b/server/backtask/service/user.go @@ -3,6 +3,7 @@ package service import ( "f5" "main/constant" + "fmt" ) func GetAccountIdByAddress(accountAddress string) string { @@ -23,3 +24,44 @@ func GetAccountIdByAddress(accountAddress string) string { }) return accountId } + +func AccountIdExistsAndIgnoreError(accountId string) bool { + isExists := false + f5.GetGoStyleDb().OrmSelectOne( + constant.GAME_DB, + "t_user", + [][]string { + {"account_id", accountId}, + }, + func (err error, ds *f5.DataSet) { + if err != nil { + return + } + if ds.Next() { + isExists = true + } + }) + return isExists +} + +func UserAddGold(accountId string, goldNum int32) bool { + result := false + f5.GetGoStyleDb().Update( + constant.GAME_DB, + "t_user", + [][]string { + {"account_id", accountId}, + }, + [][]string { + {"!gold", func () string { + return fmt.Sprintf("gold = gold + %d", goldNum) + }()}, + }, + func (err error, lastInsertId int64, rowsAffected int64) { + result = err == nil + if err != nil { + return + } + }) + return result +} diff --git a/server/jccommon/constant.go b/server/jccommon/constant.go index 71d21439..bf3fbd7a 100644 --- a/server/jccommon/constant.go +++ b/server/jccommon/constant.go @@ -50,3 +50,13 @@ const ( V_ITEM_GOLD_BULLION_1W = 10017 V_ITEM_GOLD_BULLION_10W = 10018 ) + +const ( + GOLD_BULLION_NO_OPEN = 0 + GOLD_BULLION_OPENED = 1 +) + +const ( + GOLD_BULLION_OPEN_STATUS_SENT = 1 + GOLD_BULLION_OPEN_STATUS_RECEIVED = 2 +)