|
@@ -160,7 +160,56 @@ func RoleMenuEdit(companyid int64, roleId int64, menuids []int64) error { |
|
@@ -160,7 +160,56 @@ func RoleMenuEdit(companyid int64, roleId int64, menuids []int64) error { |
160
|
}
|
160
|
}
|
161
|
|
161
|
|
162
|
//机会管理高级设置
|
162
|
//机会管理高级设置
|
163
|
-func UpdateSetOpportunity() error {
|
163
|
+func UpdateSetOpportunity(param OptionOpportunity, roleid int64, companyid int64) error {
|
|
|
164
|
+ var (
|
|
|
165
|
+ //code = M_SYSTEM_OPPORTUNITY
|
|
|
166
|
+ rolemenu *models.RoleMenu
|
|
|
167
|
+ roleInfo *models.Role
|
|
|
168
|
+ err error
|
|
|
169
|
+ menuinfo *models.Menu
|
|
|
170
|
+ )
|
|
|
171
|
+ menuinfo, err = models.GetMenuByCode(M_SYSTEM_OPPORTUNITY)
|
|
|
172
|
+ if err != nil {
|
|
|
173
|
+ log.Error("获取菜单数据失败GetMenuByCode(%s):%s", M_SYSTEM_OPPORTUNITY, err)
|
|
|
174
|
+ return protocol.NewErrWithMessage("1")
|
|
|
175
|
+ }
|
|
|
176
|
+ roleInfo, err = models.GetRoleById(roleid)
|
|
|
177
|
+ if err != nil {
|
|
|
178
|
+ log.Error("获取角色数据失败:%s", err)
|
|
|
179
|
+ return protocol.NewErrWithMessage("1")
|
|
|
180
|
+ }
|
|
|
181
|
+ if roleInfo.CompanyId != companyid {
|
|
|
182
|
+ log.Error("角色公司不匹配")
|
|
|
183
|
+ return protocol.NewErrWithMessage("1")
|
|
|
184
|
+ }
|
|
|
185
|
+ rolemenu, err = models.GetRoleMenuByCode(roleInfo.Id, M_SYSTEM_OPPORTUNITY)
|
|
|
186
|
+ if err != nil && err != orm.ErrNoRows {
|
|
|
187
|
+ log.Debug("为获取到role_menu数据:%s", err)
|
|
|
188
|
+ return protocol.NewErrWithMessage("1")
|
|
|
189
|
+ }
|
|
|
190
|
+ setToString, _ := json.Marshal(param)
|
|
|
191
|
+ if err == orm.ErrNoRows {
|
|
|
192
|
+ //没有数据 新增
|
|
|
193
|
+ rolemenu = &models.RoleMenu{
|
|
|
194
|
+ RoleId: roleid,
|
|
|
195
|
+ Opption: string(setToString),
|
|
|
196
|
+ Code: M_SYSTEM_OPPORTUNITY,
|
|
|
197
|
+ MenuId: menuinfo.Id,
|
|
|
198
|
+ }
|
|
|
199
|
+ _, err = models.AddRoleMenu(rolemenu)
|
|
|
200
|
+ if err != nil {
|
|
|
201
|
+ log.Error("添加角色菜单失败:%s", err)
|
|
|
202
|
+ return protocol.NewErrWithMessage("1")
|
|
|
203
|
+ }
|
|
|
204
|
+ return nil
|
|
|
205
|
+ }
|
|
|
206
|
+ // 有数据更新
|
|
|
207
|
+ rolemenu.Opption = string(setToString)
|
|
|
208
|
+ err = models.UpdateRoleMenuById(rolemenu, []string{"Opption"})
|
|
|
209
|
+ if err != nil {
|
|
|
210
|
+ log.Error("更新角色菜单失败:%s", err)
|
|
|
211
|
+ return protocol.NewErrWithMessage("1")
|
|
|
212
|
+ }
|
164
|
return nil
|
213
|
return nil
|
165
|
}
|
214
|
}
|
166
|
|
215
|
|
|
@@ -173,6 +222,7 @@ func GetSetOpportunity(roleid int64, companyid int64) (*OptionOpportunity, error |
|
@@ -173,6 +222,7 @@ func GetSetOpportunity(roleid int64, companyid int64) (*OptionOpportunity, error |
173
|
}
|
222
|
}
|
174
|
var (
|
223
|
var (
|
175
|
//code = M_SYSTEM_OPPORTUNITY
|
224
|
//code = M_SYSTEM_OPPORTUNITY
|
|
|
225
|
+ rolemenu *models.RoleMenu
|
176
|
roleInfo *models.Role
|
226
|
roleInfo *models.Role
|
177
|
err error
|
227
|
err error
|
178
|
)
|
228
|
)
|
|
@@ -185,5 +235,29 @@ func GetSetOpportunity(roleid int64, companyid int64) (*OptionOpportunity, error |
|
@@ -185,5 +235,29 @@ func GetSetOpportunity(roleid int64, companyid int64) (*OptionOpportunity, error |
185
|
log.Error("角色公司不匹配")
|
235
|
log.Error("角色公司不匹配")
|
186
|
return setting, protocol.NewErrWithMessage("1")
|
236
|
return setting, protocol.NewErrWithMessage("1")
|
187
|
}
|
237
|
}
|
|
|
238
|
+ rolemenu, err = models.GetRoleMenuByCode(roleInfo.Id, M_SYSTEM_OPPORTUNITY)
|
|
|
239
|
+ if err != nil {
|
|
|
240
|
+ log.Debug("为获取到role_menu数据:%s", err)
|
|
|
241
|
+ return setting, nil
|
|
|
242
|
+ }
|
|
|
243
|
+ err = json.Unmarshal([]byte(rolemenu.Opption), setting)
|
|
|
244
|
+ if err != nil {
|
|
|
245
|
+ log.Error("解析配置json失败:%s", err)
|
|
|
246
|
+ }
|
|
|
247
|
+ departInSetting := []CheckDeparment{}
|
|
|
248
|
+ for k, v := range setting.CheckOption.Departments {
|
|
|
249
|
+ d, err := models.GetDepartmentById(v.Id)
|
|
|
250
|
+ if err != nil {
|
|
|
251
|
+ log.Error("获取部门失败GetDepartmentById(%d):%s", v.Id, err)
|
|
|
252
|
+ continue
|
|
|
253
|
+ }
|
|
|
254
|
+ if d.DeleteAt.Unix() <= 0 {
|
|
|
255
|
+ //部门已被删除
|
|
|
256
|
+ continue
|
|
|
257
|
+ }
|
|
|
258
|
+ setting.CheckOption.Departments[k].Name = d.Name
|
|
|
259
|
+ departInSetting = append(departInSetting, setting.CheckOption.Departments[k])
|
|
|
260
|
+ }
|
|
|
261
|
+ setting.CheckOption.Departments = departInSetting
|
188
|
return setting, nil
|
262
|
return setting, nil
|
189
|
} |
263
|
} |