...
|
...
|
@@ -160,7 +160,56 @@ func RoleMenuEdit(companyid int64, roleId int64, menuids []int64) error { |
|
|
}
|
|
|
|
|
|
//机会管理高级设置
|
|
|
func UpdateSetOpportunity() error {
|
|
|
func UpdateSetOpportunity(param OptionOpportunity, roleid int64, companyid int64) error {
|
|
|
var (
|
|
|
//code = M_SYSTEM_OPPORTUNITY
|
|
|
rolemenu *models.RoleMenu
|
|
|
roleInfo *models.Role
|
|
|
err error
|
|
|
menuinfo *models.Menu
|
|
|
)
|
|
|
menuinfo, err = models.GetMenuByCode(M_SYSTEM_OPPORTUNITY)
|
|
|
if err != nil {
|
|
|
log.Error("获取菜单数据失败GetMenuByCode(%s):%s", M_SYSTEM_OPPORTUNITY, err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
roleInfo, err = models.GetRoleById(roleid)
|
|
|
if err != nil {
|
|
|
log.Error("获取角色数据失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if roleInfo.CompanyId != companyid {
|
|
|
log.Error("角色公司不匹配")
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
rolemenu, err = models.GetRoleMenuByCode(roleInfo.Id, M_SYSTEM_OPPORTUNITY)
|
|
|
if err != nil && err != orm.ErrNoRows {
|
|
|
log.Debug("为获取到role_menu数据:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
setToString, _ := json.Marshal(param)
|
|
|
if err == orm.ErrNoRows {
|
|
|
//没有数据 新增
|
|
|
rolemenu = &models.RoleMenu{
|
|
|
RoleId: roleid,
|
|
|
Opption: string(setToString),
|
|
|
Code: M_SYSTEM_OPPORTUNITY,
|
|
|
MenuId: menuinfo.Id,
|
|
|
}
|
|
|
_, err = models.AddRoleMenu(rolemenu)
|
|
|
if err != nil {
|
|
|
log.Error("添加角色菜单失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
// 有数据更新
|
|
|
rolemenu.Opption = string(setToString)
|
|
|
err = models.UpdateRoleMenuById(rolemenu, []string{"Opption"})
|
|
|
if err != nil {
|
|
|
log.Error("更新角色菜单失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -173,6 +222,7 @@ func GetSetOpportunity(roleid int64, companyid int64) (*OptionOpportunity, error |
|
|
}
|
|
|
var (
|
|
|
//code = M_SYSTEM_OPPORTUNITY
|
|
|
rolemenu *models.RoleMenu
|
|
|
roleInfo *models.Role
|
|
|
err error
|
|
|
)
|
...
|
...
|
@@ -185,5 +235,29 @@ func GetSetOpportunity(roleid int64, companyid int64) (*OptionOpportunity, error |
|
|
log.Error("角色公司不匹配")
|
|
|
return setting, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
rolemenu, err = models.GetRoleMenuByCode(roleInfo.Id, M_SYSTEM_OPPORTUNITY)
|
|
|
if err != nil {
|
|
|
log.Debug("为获取到role_menu数据:%s", err)
|
|
|
return setting, nil
|
|
|
}
|
|
|
err = json.Unmarshal([]byte(rolemenu.Opption), setting)
|
|
|
if err != nil {
|
|
|
log.Error("解析配置json失败:%s", err)
|
|
|
}
|
|
|
departInSetting := []CheckDeparment{}
|
|
|
for k, v := range setting.CheckOption.Departments {
|
|
|
d, err := models.GetDepartmentById(v.Id)
|
|
|
if err != nil {
|
|
|
log.Error("获取部门失败GetDepartmentById(%d):%s", v.Id, err)
|
|
|
continue
|
|
|
}
|
|
|
if d.DeleteAt.Unix() <= 0 {
|
|
|
//部门已被删除
|
|
|
continue
|
|
|
}
|
|
|
setting.CheckOption.Departments[k].Name = d.Name
|
|
|
departInSetting = append(departInSetting, setting.CheckOption.Departments[k])
|
|
|
}
|
|
|
setting.CheckOption.Departments = departInSetting
|
|
|
return setting, nil
|
|
|
} |
...
|
...
|
|