aozhiwei 7affbd8c60 1
2024-07-12 17:17:13 +08:00

130 lines
2.7 KiB
Go

package service
import (
"q5"
"f5"
"main/constant"
"fmt"
"jccommon"
)
func GetAccountIdByAddress(accountAddress string) string {
accountId := ""
f5.GetGoStyleDb().OrmSelectOne(
constant.GAME_DB,
"t_user",
[][]string {
{"address", accountAddress},
},
func (err error, ds *f5.DataSet) {
if err != nil {
return
}
if ds.Next() {
accountId = ds.GetByName("account_id")
}
})
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, netId int32, tokenId string, reason int32) bool {
var oldGold float64
{
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() {
oldGold = q5.ToFloat64(ds.GetByName("gold"))
AddGameLog(accountId, jccommon.GAME_LOG_TYPE_BACKTASK_USER_ADD_GOLD_START,
q5.ToString(reason),
q5.ToString(netId), tokenId, q5.ToString(oldGold), q5.ToString(goldNum))
}
})
}
result := false
f5.GetGoStyleDb().Update(
constant.GAME_DB,
"t_user",
[][]string {
{"account_id", accountId},
},
[][]string {
{"!gold", func () string {
return fmt.Sprintf("gold + %d", goldNum)
}()},
},
func (err error, lastInsertId int64, rowsAffected int64) {
result = err == nil
if err != nil {
return
}
})
{
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() {
newGold := q5.ToFloat64(ds.GetByName("gold"))
AddGameLog(accountId, jccommon.GAME_LOG_TYPE_BACKTASK_USER_ADD_GOLD_END,
q5.ToString(reason),
q5.ToString(netId), tokenId, q5.ToString(oldGold), q5.ToString(newGold))
}
})
}
return result
}
func AddGameLog(accountId string, logType string, subType string,
param1 string, param2 string, param3 string, param4 string) {
nowTime := f5.GetApp().GetRealSeconds()
f5.GetGoStyleDb().Insert(
constant.GAME_DB,
"t_game_log",
[][]string {
{"account_id", accountId},
{"type", logType},
{"subtype", subType},
{"param1", param1},
{"param2", param2},
{"param3", param3},
{"param4", param4},
{"createtime", q5.ToString(nowTime)},
{"modifytime", q5.ToString(nowTime)},
},
func (err error, lastInsertId int64, rowsAffected int64) {
})
}