1
This commit is contained in:
parent
d0811dd8b2
commit
ad988d90b6
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user