This commit is contained in:
苏尹岚
2021-01-22 16:59:13 +08:00
parent 6462231c86
commit 61d01e7cbf
3 changed files with 10 additions and 18 deletions

View File

@@ -82,32 +82,22 @@ func UpdateMenu(ctx *jxcontext.Context, menuID int, payload map[string]interface
return num, err return num, err
} }
type GetRoleResult struct { func GetRole(ctx *jxcontext.Context, name string) (roles []*model.Role, err error) {
Role *model.Role
CityInfo []*model.Place `json:"cityInfo"`
Stores []*model.Store `json:"storeInfo"`
}
func GetRole(ctx *jxcontext.Context, name string) (getRoleResults []*GetRoleResult, err error) {
var ( var (
db = dao.GetDB() db = dao.GetDB()
) )
roles, err := dao.GetRole(db, name, "") roles, err := dao.GetRole(db, name, "")
for _, v := range roles { for _, v := range roles {
getRoleResult := &GetRoleResult{
Role: v,
}
if v.CityCodes != "" { if v.CityCodes != "" {
if cityInfos, err := dao.GetPlaces(db, jxutils.StrListToIntList(strings.Split(v.CityCodes, ","))); err == nil { if cityInfos, err := dao.GetPlaces(db, jxutils.StrListToIntList(strings.Split(v.CityCodes, ","))); err == nil {
getRoleResult.CityInfo = cityInfos v.CityInfo = cityInfos
} }
} }
if v.StoreIDs != "" { if v.StoreIDs != "" {
if stores, err := dao.GetStoreList(db, jxutils.StrListToIntList(strings.Split(v.StoreIDs, ",")), nil, nil, nil, nil, ""); err == nil { if stores, err := dao.GetStoreList(db, jxutils.StrListToIntList(strings.Split(v.StoreIDs, ",")), nil, nil, nil, nil, ""); err == nil {
getRoleResult.Stores = stores v.Stores = stores
} }
} }
getRoleResults = append(getRoleResults, getRoleResult)
} }
return getRoleResults, err return getRoleResults, err
} }

View File

@@ -94,7 +94,7 @@ func GetPlaces(db *DaoDB, cityCodes []int) (places []*model.Place, err error) {
` `
sqlParams := []interface{}{} sqlParams := []interface{}{}
if len(cityCodes) > 0 { if len(cityCodes) > 0 {
sql += " AND city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")" sql += " AND code IN (" + GenQuestionMarks(len(cityCodes)) + ")"
sqlParams = append(sqlParams, cityCodes) sqlParams = append(sqlParams, cityCodes)
} }
return places, err return places, err

View File

@@ -228,10 +228,12 @@ func (v *UserMember) TableIndex() [][]string {
type Role struct { type Role struct {
ModelIDCULD ModelIDCULD
Name string `json:"name"` //角色名 Name string `json:"name"` //角色名
BrandID int `orm:"column(brand_id)" json:"brandID"` BrandID int `orm:"column(brand_id)" json:"brandID"`
CityCodes string `orm:"type(text)" json:"cityCodes"` CityCodes string `orm:"type(text)" json:"cityCodes"`
StoreIDs string `orm:"column(store_ids);type(text)" json:"storeIDs"` StoreIDs string `orm:"column(store_ids);type(text)" json:"storeIDs"`
CityInfo []*Place `orm:"-" json:"cityInfo"`
Stores []*Store `orm:"-" json:"storeInfo"`
} }
func (*Role) TableUnique() [][]string { func (*Role) TableUnique() [][]string {