|
@@ -141,20 +141,29 @@ func UpdateLevel(c *gin.Context) { |
|
|
level.LevelWeight = utils.StrToInt(req.LevelWeight) |
|
|
level.LevelWeight = utils.StrToInt(req.LevelWeight) |
|
|
forceColumns = append(forceColumns, "level_weight") |
|
|
forceColumns = append(forceColumns, "level_weight") |
|
|
} |
|
|
} |
|
|
|
|
|
levelDb := implement.NewUserLevelDb(db.Db) |
|
|
if req.IsUse == "0" || req.IsUse == "1" { |
|
|
if req.IsUse == "0" || req.IsUse == "1" { |
|
|
// 判断当前该等级有没有被使用 |
|
|
|
|
|
userDb := implement.NewUserDb(db.Db) |
|
|
|
|
|
has, err := userDb.UserExistByParams(map[string]interface{}{ |
|
|
|
|
|
"key": "level", |
|
|
|
|
|
"value": req.LevelID, |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
// 查询当前等级状态是否被改变 |
|
|
|
|
|
oldLevel, err := levelDb.UserLevelByID(req.LevelID) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
if has { |
|
|
|
|
|
e.OutErr(c, e.ERR, errors.New("该等级下存在会员,无法关闭该会员等级,请移除对应等级下会员或将会员移动到其他等级").Error()) |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
if utils.StrToInt(req.IsUse) != oldLevel.IsUse { |
|
|
|
|
|
// 判断当前该等级有没有被使用 |
|
|
|
|
|
userDb := implement.NewUserDb(db.Db) |
|
|
|
|
|
has, err := userDb.UserExistByParams(map[string]interface{}{ |
|
|
|
|
|
"key": "level", |
|
|
|
|
|
"value": req.LevelID, |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if has { |
|
|
|
|
|
e.OutErr(c, e.ERR, errors.New("该等级下存在会员,无法关闭该会员等级,请移除对应等级下会员或将会员移动到其他等级").Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
level.IsUse = utils.StrToInt(req.IsUse) |
|
|
level.IsUse = utils.StrToInt(req.IsUse) |
|
@@ -169,7 +178,6 @@ func UpdateLevel(c *gin.Context) { |
|
|
defer session.Close() |
|
|
defer session.Close() |
|
|
|
|
|
|
|
|
// 1. 更新等级信息 |
|
|
// 1. 更新等级信息 |
|
|
levelDb := implement.NewUserLevelDb(db.Db) |
|
|
|
|
|
affected, err := levelDb.UserLevelUpdateBySession(session, req.LevelID, level, forceColumns...) |
|
|
affected, err := levelDb.UserLevelUpdateBySession(session, req.LevelID, level, forceColumns...) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
if err.Error() == "no columns found to be updated" { |
|
|
if err.Error() == "no columns found to be updated" { |
|
|