diff --git a/db/db_user_virtual_amount.go b/db/db_user_virtual_amount.go index 663214f..51e72ea 100644 --- a/db/db_user_virtual_amount.go +++ b/db/db_user_virtual_amount.go @@ -95,6 +95,27 @@ func GetUserVirtualWalletWithSession(session *xorm.Session, uid, coinId int) (*m return nil, errors.New("获取用户虚拟币钱包失败") } +func GetUserVirtualWallet(session *xorm.Engine, uid, coinId int) (*model.UserVirtualAmount, error) { + var UserVirtualWallet model.UserVirtualAmount + get, err := session.Where("uid = ? AND coin_id = ?", uid, coinId).Get(&UserVirtualWallet) + if err != nil { + return nil, err + } + if get { + return &UserVirtualWallet, nil + } else { + UserVirtualWallet.Amount = "0" + UserVirtualWallet.CoinId = coinId + UserVirtualWallet.Uid = uid + one, err := session.InsertOne(&UserVirtualWallet) + if err != nil || one == 0 { + return nil, err + } + return &UserVirtualWallet, nil + } + return nil, errors.New("获取用户虚拟币钱包失败") +} + // UserVirtualAmountGetOneByParams 通过传入的参数查询数据(单条) func UserVirtualAmountGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.UserVirtualAmount, error) { var m model.UserVirtualAmount diff --git a/svc/svc_block_star_chain_settlement.go b/svc/svc_block_star_chain_settlement.go index 6d926f0..235e7f6 100644 --- a/svc/svc_block_star_chain_settlement.go +++ b/svc/svc_block_star_chain_settlement.go @@ -16,7 +16,7 @@ func GetUserCoinAmount(session *xorm.Session, masterId string, coinId, uid int) amount, err = cache.GetString(redisKey) if err != nil { if err.Error() == "redigo: nil returned" { - userVirtualAmount, err := db.GetUserVirtualWalletWithSession(session, uid, coinId) + userVirtualAmount, err := db.GetUserVirtualWallet(session.Engine(), uid, coinId) if err != nil { return amount, err }