|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- package db
-
- import (
- "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db/model"
- zhios_condition_statistics_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils/logx"
- "errors"
- "fmt"
- "reflect"
- "xorm.io/xorm"
- )
-
- //UserLevelByID is 根据用户id 获取对应的等级信息
- func UserLevelByID(Db *xorm.Engine, id interface{}) (*model.UserLevel, error) {
- m := new(model.UserLevel)
- has, err := Db.Where("id = ?", id).Get(m)
- if err != nil {
- return nil, err
- }
- if !has {
- return nil, errors.New("not found")
- }
-
- return m, nil
- }
- func UserLevelAuditInsertWithEngine(Db *xorm.Engine, data *model.UserLevelAudit) (int64, error) {
- affect, err := Db.Insert(data)
- if err != nil || affect != 1 {
- return 0, err
- }
-
- return affect, nil
- }
-
- func UserLevelAuditUpdateById(eg *xorm.Engine, id int, audit *model.UserLevelAudit, forceColumns ...string) (int64, error) {
- var (
- affected int64
- err error
- )
- if forceColumns != nil {
- affected, err = eg.Where("id=?", id).Cols(forceColumns...).Update(audit)
- } else {
- affected, err = eg.Where("id=?", id).Update(audit)
- }
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- func UserLevelOrderById(Db *xorm.Engine, id string) (*model.UserLevelOrd, error) {
- var m model.UserLevelOrd
- has, err := Db.Where("id = ? ", id).Desc("expire_at").Get(&m)
- if err != nil || has == false {
- return nil, err
- }
- return &m, nil
- }
-
- //UserLevelOrdUpdateOne is 更新付费升级订单
- func UserLevelOrdUpdateOne(Db *xorm.Engine, order *model.UserLevelOrd) (int64, error) {
- affect, err := Db.ID(order.Id).Update(order)
- if err != nil {
- return 0, err
- }
- return affect, nil
- }
-
- func UserUpdate(Db *xorm.Engine, uid interface{}, user *model.User, forceColums ...string) (int64, error) {
- var (
- affected int64
- err error
- )
- if forceColums != nil {
- affected, err = Db.Where("uid=?", uid).Cols(forceColums...).Update(user)
- } else {
- affected, err = Db.Where("uid=?", uid).Update(user)
- }
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
- func BatchSelectUserLevelUpgradeTasks(Db *xorm.Engine, params map[string]interface{}) (*[]model.UserLevelUpgradeTask, error) {
- var m []model.UserLevelUpgradeTask
-
- if params["key"] == nil {
- //查询全部数据
- err := Db.Find(&m)
- if err != nil {
- return nil, err
- }
- return &m, nil
- } else {
- if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
- //指定In查询
- if err := Db.In(zhios_condition_statistics_logx.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
- return nil, err
- }
- return &m, nil
- } else {
- var query = fmt.Sprintf("%s =?", params["key"])
- err := Db.Where(query, params["value"]).Find(&m)
- if err != nil {
- return nil, err
- }
- return &m, nil
- }
-
- }
- }
- func UserLevelByAllMap(Db *xorm.Engine) map[int]*model.UserLevel {
- var maps = make(map[int]*model.UserLevel, 0)
- var m []*model.UserLevel
- err := Db.Where("is_use = ?", 1).Asc("level_weight").Find(&m)
- if err != nil {
- return maps
- }
- for _, v := range m {
- maps[v.Id] = v
- }
- return maps
- }
|