This commit is contained in:
苏尹岚
2021-01-22 10:05:43 +08:00
parent f85fa9e12a
commit 519592bc31
14 changed files with 145 additions and 30 deletions

View File

@@ -5,6 +5,8 @@ import (
"strings"
"time"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
@@ -222,6 +224,12 @@ func UpdateUserRole(ctx *jxcontext.Context, userIDs []string, roleIDs []int) (er
}
}
}
for _, v := range userIDs {
if user, err := dao.GetUserByID(db, "userID", v); err == nil {
user.Type = user.Type | model.UserTypeRole
dao.UpdateEntity(db, user, "Type")
}
}
dao.Commit(db)
return err
}
@@ -299,3 +307,51 @@ func UpdateRoleMenu(ctx *jxcontext.Context, roleIDs, menuIDs []int) (err error)
dao.Commit(db)
return err
}
func GetUserStoresResultMap(userID string) (resultMap map[int]int, err error) {
var (
db = dao.GetDB()
brandIDMap = make(map[int]int)
cityCodeMap = make(map[int]int)
storeIDMap = make(map[int]int)
brandIDs, cityCodes, storeIDs []int
stores []*model.Store
)
resultMap = make(map[int]int)
userRoles, err := dao.GetUserRole2(db, []string{userID}, nil)
for _, v := range userRoles {
if _, ok := brandIDMap[v.BrandID]; !ok {
brandIDMap[v.BrandID] = 1
}
for _, cityCode := range jxutils.StrListToIntList(strings.Split(v.CityCodes, ",")) {
if _, ok := cityCodeMap[cityCode]; !ok {
cityCodeMap[cityCode] = 1
}
}
for _, storeID := range jxutils.StrListToIntList(strings.Split(v.StoreIDs, ",")) {
if _, ok := storeIDMap[storeID]; !ok {
storeIDMap[storeID] = 1
}
}
}
for k, _ := range brandIDMap {
brandIDs = append(brandIDs, k)
}
for k, _ := range cityCodeMap {
cityCodes = append(cityCodes, k)
}
for k, _ := range storeIDMap {
storeIDs = append(storeIDs, k)
}
if cityCodeMap[0] != 0 {
stores, err = dao.GetStoreList(db, nil, nil, nil, brandIDs, nil, "")
} else {
stores, err = dao.GetStoreList(db, storeIDs, cityCodes, nil, brandIDs, nil, "")
}
for _, v := range stores {
if _, ok := resultMap[v.ID]; !ok {
resultMap[v.ID] = v.ID
}
}
return resultMap, err
}