作者 yangfu

机会权限

@@ -179,3 +179,24 @@ func (this *UserController) UserStatistics() { @@ -179,3 +179,24 @@ func (this *UserController) UserStatistics() {
179 header := controllers.GetRequestHeader(this.Ctx) 179 header := controllers.GetRequestHeader(this.Ctx)
180 msg = protocol.NewReturnResponse(user.UserStatistics(header, request)) 180 msg = protocol.NewReturnResponse(user.UserStatistics(header, request))
181 } 181 }
  182 +
  183 +//Permission 用户权限
  184 +//@router /permission [post]
  185 +func (this *UserController) Permission() {
  186 + var msg *protocol.ResponseMessage
  187 + defer func() {
  188 + this.Resp(msg)
  189 + }()
  190 + var request *protocol.PermissionRequest
  191 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  192 + log.Error(err)
  193 + msg = protocol.BadRequestParam(1)
  194 + return
  195 + }
  196 + if b, m := this.Valid(request); !b {
  197 + msg = m
  198 + return
  199 + }
  200 + header := controllers.GetRequestHeader(this.Ctx)
  201 + msg = protocol.NewReturnResponse(user.Permission(header, request))
  202 +}
@@ -103,3 +103,13 @@ type TypeTotalItem struct { @@ -103,3 +103,13 @@ type TypeTotalItem struct {
103 Total int `json:"total"` //总数 103 Total int `json:"total"` //总数
104 HaveUpdate int `json:"haveUpdate"` //是否含有更新(0无更新,1有更新) 104 HaveUpdate int `json:"haveUpdate"` //是否含有更新(0无更新,1有更新)
105 } 105 }
  106 +
  107 +/*Permission 用户权限*/
  108 +type PermissionRequest struct {
  109 +}
  110 +type PermissionResponse struct {
  111 + EditSorce int `json:"editSorce"` //修改评分 1:允许 0:不允许
  112 + EditPublicStatus int `json:"editPublicStatus"` //修改公开状态 1:允许 0:不允许
  113 + CloseChance int `json:"closeChance"` //关闭机会 1:允许 0:不允许
  114 + EditChance int `json:"editChance"` //编辑机会 1:允许 0:不允许
  115 +}
@@ -441,6 +441,14 @@ func init() { @@ -441,6 +441,14 @@ func init() {
441 441
442 beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"], 442 beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
443 beego.ControllerComments{ 443 beego.ControllerComments{
  444 + Method: "Permission",
  445 + Router: `/permission`,
  446 + AllowHTTPMethods: []string{"post"},
  447 + MethodParams: param.Make(),
  448 + Params: nil})
  449 +
  450 + beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
  451 + beego.ControllerComments{
444 Method: "ResetPassword", 452 Method: "ResetPassword",
445 Router: `/resetPassword`, 453 Router: `/resetPassword`,
446 AllowHTTPMethods: []string{"post"}, 454 AllowHTTPMethods: []string{"post"},
@@ -256,7 +256,7 @@ func (p *OptionOpportunity) ValidEditPublicStatus(obj UserObject) bool { @@ -256,7 +256,7 @@ func (p *OptionOpportunity) ValidEditPublicStatus(obj UserObject) bool {
256 return false 256 return false
257 } 257 }
258 258
259 -func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, error) { 259 +func getUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, error) {
260 type CodeOpptionData struct { 260 type CodeOpptionData struct {
261 Code string `orm:"column(code)"` 261 Code string `orm:"column(code)"`
262 Opption string `orm:"column(opption)"` 262 Opption string `orm:"column(opption)"`
@@ -265,13 +265,13 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, @@ -265,13 +265,13 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject,
265 FROM role_menu AS a 265 FROM role_menu AS a
266 JOIN user_role AS b ON a.role_id = b.role_id 266 JOIN user_role AS b ON a.role_id = b.role_id
267 JOIN role AS c ON a.role_id = c.id 267 JOIN role AS c ON a.role_id = c.id
268 - WHERE b.user_company_id=? AND c.delete_at =0` 268 + WHERE a.code=? AND b.user_company_id=? AND c.delete_at =0`
269 var ( 269 var (
270 data []CodeOpptionData 270 data []CodeOpptionData
271 err error 271 err error
272 objMap = make(map[string]PermissionOptionObject) 272 objMap = make(map[string]PermissionOptionObject)
273 ) 273 )
274 - err = utils.ExecuteQueryAll(&data, datasql, userCompanyid) 274 + err = utils.ExecuteQueryAll(&data, datasql, M_SYSTEM_OPPORTUNITY, userCompanyid)
275 if err != nil { 275 if err != nil {
276 e := fmt.Errorf("EXCUTE SQL ERR:%s", err) 276 e := fmt.Errorf("EXCUTE SQL ERR:%s", err)
277 return nil, e 277 return nil, e
@@ -287,7 +287,7 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, @@ -287,7 +287,7 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject,
287 if fn, ok := CodePermissionObject[v.Code]; ok { 287 if fn, ok := CodePermissionObject[v.Code]; ok {
288 obj := fn() 288 obj := fn()
289 if err = json.Unmarshal([]byte(v.Opption), obj); err != nil { 289 if err = json.Unmarshal([]byte(v.Opption), obj); err != nil {
290 - log.Debug("解析权限配置option 失败%s", err) 290 + log.Debug("解析权限配置option 失败", v.Opption, err)
291 } 291 }
292 objMap[v.Code] = obj 292 objMap[v.Code] = obj
293 } else { 293 } else {
@@ -297,3 +297,21 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, @@ -297,3 +297,21 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject,
297 } 297 }
298 return objMap, nil 298 return objMap, nil
299 } 299 }
  300 +
  301 +//获取用户权限
  302 +func GetUserPermission(userCompanyid int64) (op *OptionOpportunity, err error) {
  303 + op = &OptionOpportunity{}
  304 + mp, e := getUserPermission(userCompanyid)
  305 + if e != nil {
  306 + log.Error(e)
  307 + }
  308 + if len(mp) == 0 {
  309 + return
  310 + }
  311 + if v, ok := mp[M_SYSTEM_OPPORTUNITY]; ok {
  312 + if op, ok = v.(*OptionOpportunity); ok {
  313 + return
  314 + }
  315 + }
  316 + return
  317 +}
@@ -447,3 +447,18 @@ func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatis @@ -447,3 +447,18 @@ func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatis
447 //log.Debug(buf.String()) 447 //log.Debug(buf.String())
448 return 448 return
449 } 449 }
  450 +
  451 +//用户权限
  452 +func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequest) (rsp *protocol.PermissionResponse, err error) {
  453 + var (
  454 + op *agg.OptionOpportunity
  455 + )
  456 + rsp = &protocol.PermissionResponse{}
  457 + if op, err = agg.GetUserPermission(header.UserId); err == nil {
  458 + rsp.EditChance = op.EditChance
  459 + //rsp.CloseChance = op.CloseChance
  460 + rsp.EditPublicStatus = op.EditPublicStatus
  461 + rsp.EditSorce = op.EditSorce
  462 + }
  463 + return
  464 +}