|
|
@@ -0,0 +1,35 @@ |
|
|
|
package implement |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.fnuoos.com/EggPlanet/egg_models.git/src/dao" |
|
|
|
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
func NewUserVirtualAmountDb(engine *xorm.Engine) dao.UserVirtualAmountDao { |
|
|
|
return &UserVirtualAmountDb{Db: engine} |
|
|
|
} |
|
|
|
|
|
|
|
type UserVirtualAmountDb struct { |
|
|
|
Db *xorm.Engine |
|
|
|
} |
|
|
|
|
|
|
|
func (u UserVirtualAmountDb) GetUserVirtualWalletBySession(uid int64, coinId int) (*model.UserVirtualAmount, error) { |
|
|
|
var UserVirtualWallet model.UserVirtualAmount |
|
|
|
get, err := u.Db.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, err1 := u.Db.InsertOne(&UserVirtualWallet) |
|
|
|
if err1 != nil || one == 0 { |
|
|
|
return nil, err1 |
|
|
|
} |
|
|
|
return &UserVirtualWallet, nil |
|
|
|
} |
|
|
|
} |