package db import ( "applet/app/db/model" "applet/app/utils" "xorm.io/xorm" ) func GetUserVirtualAmountOne(session *xorm.Session, uid int, coinId int) (*model.UserVirtualAmount, error) { var m model.UserVirtualAmount isExist, err := session.Table("user_virtual_amount").Where("uid = ? AND coin_id = ?", uid, coinId).Get(&m) if err != nil { return nil, err } if !isExist { return nil, nil } return &m, nil } func GetUserVirtualAmountOneEg(eg *xorm.Engine, uid int, coinId int) (*model.UserVirtualAmount, error) { var m model.UserVirtualAmount isExist, err := eg.Table("user_virtual_amount").Where("uid = ? AND coin_id = ?", uid, coinId).Get(&m) if err != nil { return nil, err } if !isExist { return nil, nil } return &m, nil } func GetUserVirtualAmountSum(eg *xorm.Engine, uid int) (string, error) { var m model.UserVirtualAmount sum, err := eg.Table("user_virtual_amount").Where("uid = ? ", uid).Sum(&m, "amount") if err != nil { return "0", err } return utils.Float64ToStr(sum), nil } /*func UserVirtualAmountUpdateWithSession(session *xorm.Session, m *model.UserVirtualAmount) bool { }*/