相关条件的统计
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123 linhas
3.0 KiB

  1. package db
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db/model"
  4. zhios_condition_statistics_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils/logx"
  5. "errors"
  6. "fmt"
  7. "reflect"
  8. "xorm.io/xorm"
  9. )
  10. //UserLevelByID is 根据用户id 获取对应的等级信息
  11. func UserLevelByID(Db *xorm.Engine, id interface{}) (*model.UserLevel, error) {
  12. m := new(model.UserLevel)
  13. has, err := Db.Where("id = ?", id).Get(m)
  14. if err != nil {
  15. return nil, err
  16. }
  17. if !has {
  18. return nil, errors.New("not found")
  19. }
  20. return m, nil
  21. }
  22. func UserLevelAuditInsertWithEngine(Db *xorm.Engine, data *model.UserLevelAudit) (int64, error) {
  23. affect, err := Db.Insert(data)
  24. if err != nil || affect != 1 {
  25. return 0, err
  26. }
  27. return affect, nil
  28. }
  29. func UserLevelAuditUpdateById(eg *xorm.Engine, id int, audit *model.UserLevelAudit, forceColumns ...string) (int64, error) {
  30. var (
  31. affected int64
  32. err error
  33. )
  34. if forceColumns != nil {
  35. affected, err = eg.Where("id=?", id).Cols(forceColumns...).Update(audit)
  36. } else {
  37. affected, err = eg.Where("id=?", id).Update(audit)
  38. }
  39. if err != nil {
  40. return 0, err
  41. }
  42. return affected, nil
  43. }
  44. func UserLevelOrderById(Db *xorm.Engine, id string) (*model.UserLevelOrd, error) {
  45. var m model.UserLevelOrd
  46. has, err := Db.Where("id = ? ", id).Desc("expire_at").Get(&m)
  47. if err != nil || has == false {
  48. return nil, err
  49. }
  50. return &m, nil
  51. }
  52. //UserLevelOrdUpdateOne is 更新付费升级订单
  53. func UserLevelOrdUpdateOne(Db *xorm.Engine, order *model.UserLevelOrd) (int64, error) {
  54. affect, err := Db.ID(order.Id).Update(order)
  55. if err != nil {
  56. return 0, err
  57. }
  58. return affect, nil
  59. }
  60. func UserUpdate(Db *xorm.Engine, uid interface{}, user *model.User, forceColums ...string) (int64, error) {
  61. var (
  62. affected int64
  63. err error
  64. )
  65. if forceColums != nil {
  66. affected, err = Db.Where("uid=?", uid).Cols(forceColums...).Update(user)
  67. } else {
  68. affected, err = Db.Where("uid=?", uid).Update(user)
  69. }
  70. if err != nil {
  71. return 0, err
  72. }
  73. return affected, nil
  74. }
  75. func BatchSelectUserLevelUpgradeTasks(Db *xorm.Engine, params map[string]interface{}) (*[]model.UserLevelUpgradeTask, error) {
  76. var m []model.UserLevelUpgradeTask
  77. if params["key"] == nil {
  78. //查询全部数据
  79. err := Db.Find(&m)
  80. if err != nil {
  81. return nil, err
  82. }
  83. return &m, nil
  84. } else {
  85. if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
  86. //指定In查询
  87. if err := Db.In(zhios_condition_statistics_logx.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
  88. return nil, err
  89. }
  90. return &m, nil
  91. } else {
  92. var query = fmt.Sprintf("%s =?", params["key"])
  93. err := Db.Where(query, params["value"]).Find(&m)
  94. if err != nil {
  95. return nil, err
  96. }
  97. return &m, nil
  98. }
  99. }
  100. }
  101. func UserLevelByAllMap(Db *xorm.Engine) map[int]*model.UserLevel {
  102. var maps = make(map[int]*model.UserLevel, 0)
  103. var m []*model.UserLevel
  104. err := Db.Where("is_use = ?", 1).Asc("level_weight").Find(&m)
  105. if err != nil {
  106. return maps
  107. }
  108. for _, v := range m {
  109. maps[v.Id] = v
  110. }
  111. return maps
  112. }