附近小店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

db_user_virtual_amount.go 1.1 KiB

3 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils"
  5. "xorm.io/xorm"
  6. )
  7. func GetUserVirtualAmountOne(session *xorm.Session, uid int, coinId int) (*model.UserVirtualAmount, error) {
  8. var m model.UserVirtualAmount
  9. isExist, err := session.Table("user_virtual_amount").Where("uid = ? AND coin_id = ?", uid, coinId).Get(&m)
  10. if err != nil {
  11. return nil, err
  12. }
  13. if !isExist {
  14. return nil, nil
  15. }
  16. return &m, nil
  17. }
  18. func GetUserVirtualAmountOneEg(eg *xorm.Engine, uid int, coinId int) (*model.UserVirtualAmount, error) {
  19. var m model.UserVirtualAmount
  20. isExist, err := eg.Table("user_virtual_amount").Where("uid = ? AND coin_id = ?", uid, coinId).Get(&m)
  21. if err != nil {
  22. return nil, err
  23. }
  24. if !isExist {
  25. return nil, nil
  26. }
  27. return &m, nil
  28. }
  29. func GetUserVirtualAmountSum(eg *xorm.Engine, uid int) (string, error) {
  30. var m model.UserVirtualAmount
  31. sum, err := eg.Table("user_virtual_amount").Where("uid = ? ", uid).Sum(&m, "amount")
  32. if err != nil {
  33. return "0", err
  34. }
  35. return utils.Float64ToStr(sum), nil
  36. }
  37. /*func UserVirtualAmountUpdateWithSession(session *xorm.Session, m *model.UserVirtualAmount) bool {
  38. }*/