From 4aa93288437e1b7f761afe605efac0d74b8746ff Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Wed, 25 Dec 2024 16:51:44 +0800 Subject: [PATCH] fix: update level --- .../member_center/hdl_level__management.go | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/app/hdl/member_center/hdl_level__management.go b/app/hdl/member_center/hdl_level__management.go index 039f2a1..43ab745 100644 --- a/app/hdl/member_center/hdl_level__management.go +++ b/app/hdl/member_center/hdl_level__management.go @@ -141,20 +141,29 @@ func UpdateLevel(c *gin.Context) { level.LevelWeight = utils.StrToInt(req.LevelWeight) forceColumns = append(forceColumns, "level_weight") } + levelDb := implement.NewUserLevelDb(db.Db) 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 { e.OutErr(c, e.ERR_DB_ORM, err.Error()) 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) @@ -169,7 +178,6 @@ func UpdateLevel(c *gin.Context) { defer session.Close() // 1. 更新等级信息 - levelDb := implement.NewUserLevelDb(db.Db) affected, err := levelDb.UserLevelUpdateBySession(session, req.LevelID, level, forceColumns...) if err != nil { if err.Error() == "no columns found to be updated" {