aa
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -226,7 +226,10 @@ func (v *UserMember) TableIndex() [][]string {
|
||||
type Role struct {
|
||||
ModelIDCULD
|
||||
|
||||
Name string `json:"name"` //角色名
|
||||
Name string `json:"name"` //角色名
|
||||
BrandID int `orm:"column(brand_id)" json:"brandID"`
|
||||
CityCodes string `json:"cityCodes"`
|
||||
StoreIDs string `orm:"column(store_ids)" json:"storeIDs"`
|
||||
}
|
||||
|
||||
func (*Role) TableUnique() [][]string {
|
||||
|
||||
@@ -95,12 +95,20 @@ func (c *PowerController) GetRole() {
|
||||
// @Param name formData string true "角色名"
|
||||
// @Param roleID formData int true "角色ID"
|
||||
// @Param isDelete formData bool true "是否是删除"
|
||||
// @Param brandID formData int false "品牌ID"
|
||||
// @Param cityCodes formData string false "城市IDs"
|
||||
// @Param storeIDs formData string false "门店IDs"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /UpdateRole [put]
|
||||
func (c *PowerController) UpdateRole() {
|
||||
c.callUpdateRole(func(params *tPowerUpdateRoleParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.UpdateRole(params.Ctx, params.RoleID, params.Name, params.IsDelete)
|
||||
var (
|
||||
cityCodes, storeIDs []int
|
||||
)
|
||||
if err = jxutils.Strings2Objs(params.CityCodes, &cityCodes, params.StoreIDs, &storeIDs); err == nil {
|
||||
retVal, err = cms.UpdateRole(params.Ctx, params.RoleID, params.Name, params.IsDelete, params.BrandID, cityCodes, storeIDs)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user