This commit is contained in:
苏尹岚
2021-01-21 17:37:12 +08:00
parent 5eeb60c12d
commit ada312f753
3 changed files with 30 additions and 5 deletions

View File

@@ -2,8 +2,11 @@ package cms
import (
"fmt"
"strings"
"time"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
@@ -105,10 +108,18 @@ func AddRole(ctx *jxcontext.Context, name string) (err error) {
return err
}
func UpdateRole(ctx *jxcontext.Context, roleID int, name string, isDelete bool) (num int64, err error) {
func UpdateRole(ctx *jxcontext.Context, roleID int, name string, isDelete bool, brandID int, cityCodes, storeIDs []int) (num int64, err error) {
var (
db = dao.GetDB()
db = dao.GetDB()
cityCodesStr []string
storeIDsStr []string
)
for _, v := range cityCodes {
cityCodesStr = append(cityCodesStr, utils.Int2Str(v))
}
for _, v := range storeIDs {
storeIDsStr = append(storeIDsStr, utils.Int2Str(v))
}
if roleID == 1 {
return 0, fmt.Errorf("管理员不允许修改!")
}
@@ -129,7 +140,10 @@ func UpdateRole(ctx *jxcontext.Context, roleID int, name string, isDelete bool)
role.Name = name
role.UpdatedAt = time.Now()
role.LastOperator = ctx.GetUserName()
num, err = dao.UpdateEntity(db, role, "Name", "UpdatedAt", "LastOperator")
role.BrandID = brandID
role.CityCodes = strings.Join(cityCodesStr, ",")
role.StoreIDs = strings.Join(storeIDsStr, ",")
num, err = dao.UpdateEntity(db, role, "Name", "UpdatedAt", "LastOperator", "BrandID", "CityCodes", "StoreIDs")
} else {
role.DeletedAt = time.Now()
num, err = dao.UpdateEntity(db, role, "DeletedAt")