作者 唐旭辉

bug修复以及新增接口

@@ -284,7 +284,7 @@ func (c *RbacController) RoleMenuEdit() { @@ -284,7 +284,7 @@ func (c *RbacController) RoleMenuEdit() {
284 return 284 return
285 } 285 }
286 286
287 -//RoleMenuEdit 设置 287 +//RoleMenuOpportunity 机会管理高级设置
288 //@router /role/menu/opportunity 288 //@router /role/menu/opportunity
289 func (c *RbacController) RoleMenuOpportunity() { 289 func (c *RbacController) RoleMenuOpportunity() {
290 var msg *protocol.ResponseMessage 290 var msg *protocol.ResponseMessage
@@ -292,8 +292,7 @@ func (c *RbacController) RoleMenuOpportunity() { @@ -292,8 +292,7 @@ func (c *RbacController) RoleMenuOpportunity() {
292 c.ResposeJson(msg) 292 c.ResposeJson(msg)
293 }() 293 }()
294 type Parameter struct { 294 type Parameter struct {
295 - RoleId int64 `json:"role_id"`  
296 - MenuIds []int64 `json:"menu_ids"` 295 + RoleId int64 `json:"role_id"`
297 } 296 }
298 var param Parameter 297 var param Parameter
299 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil { 298 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
@@ -302,7 +301,30 @@ func (c *RbacController) RoleMenuOpportunity() { @@ -302,7 +301,30 @@ func (c *RbacController) RoleMenuOpportunity() {
302 return 301 return
303 } 302 }
304 companyid := c.GetCompanyId() 303 companyid := c.GetCompanyId()
305 - err := serverbac.RoleMenuEdit(companyid, param.RoleId, param.MenuIds) 304 + data, err := serverbac.GetSetOpportunity(param.RoleId, companyid)
  305 + msg = protocol.NewReturnResponse(data, err)
  306 + return
  307 +}
  308 +
  309 +//RoleMenuOpportunity 机会管理高级设置
  310 +//@router /role/menu/opportunity/edit
  311 +func (c *RbacController) RoleMenuOpportunityEdit() {
  312 + var msg *protocol.ResponseMessage
  313 + defer func() {
  314 + c.ResposeJson(msg)
  315 + }()
  316 + type Parameter struct {
  317 + RoleId int64 `json:"role_id"`
  318 + Option serverbac.OptionOpportunity `json:"option"`
  319 + }
  320 + var param Parameter
  321 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  322 + log.Error("json 解析失败 err:%s", err)
  323 + msg = protocol.BadRequestParam("1")
  324 + return
  325 + }
  326 + companyid := c.GetCompanyId()
  327 + err := serverbac.UpdateSetOpportunity(param.Option, param.RoleId, companyid)
306 msg = protocol.NewReturnResponse(nil, err) 328 msg = protocol.NewReturnResponse(nil, err)
307 return 329 return
308 } 330 }
@@ -76,9 +76,15 @@ func DeleteBulletinQuestion(id int) (err error) { @@ -76,9 +76,15 @@ func DeleteBulletinQuestion(id int) (err error) {
76 76
77 func GetBulletinQuestionByBulletinId(id int) (v *BulletinQuestion, err error) { 77 func GetBulletinQuestionByBulletinId(id int) (v *BulletinQuestion, err error) {
78 o := orm.NewOrm() 78 o := orm.NewOrm()
79 - sql := "select * from bulletin_question where bulletin_id=?"  
80 - if err = o.Raw(sql, id).QueryRow(&v); err == nil {  
81 - return v, nil 79 + // sql := "select * from bulletin_question where bulletin_id=?"
  80 + // if err = o.Raw(sql, id).QueryRow(&v); err == nil {
  81 + // return v, nil
  82 + // }
  83 +
  84 + v = &BulletinQuestion{}
  85 + err = o.QueryTable(v).Filter("bulletin_id", id).One(v)
  86 + if err != nil {
  87 + return nil, err
82 } 88 }
83 - return nil, err 89 + return v, err
84 } 90 }
@@ -60,7 +60,7 @@ func GetMenuByCode(code string) (*Menu, error) { @@ -60,7 +60,7 @@ func GetMenuByCode(code string) (*Menu, error) {
60 Filter("code", code). 60 Filter("code", code).
61 One(menuinfo) 61 One(menuinfo)
62 if err != nil { 62 if err != nil {
63 - return menuinfo, nil 63 + return nil, err
64 } 64 }
65 - return nil, err 65 + return menuinfo, nil
66 } 66 }
1 package models 1 package models
2 2
3 import ( 3 import (
  4 + "fmt"
  5 +
4 "github.com/astaxie/beego/orm" 6 "github.com/astaxie/beego/orm"
5 ) 7 )
6 8
@@ -36,24 +38,22 @@ func GetRoleMenuByRole(roleid int64) ([]RoleMenu, error) { @@ -36,24 +38,22 @@ func GetRoleMenuByRole(roleid int64) ([]RoleMenu, error) {
36 } 38 }
37 39
38 func GetRoleMenuByCode(roleId int64, code string) (*RoleMenu, error) { 40 func GetRoleMenuByCode(roleId int64, code string) (*RoleMenu, error) {
39 - data := []*RoleMenu{} 41 + var data RoleMenu
40 o := orm.NewOrm() 42 o := orm.NewOrm()
41 - _, err := o.QueryTable(&Role{}). 43 + err := o.QueryTable(&RoleMenu{}).
42 Filter("role_id", roleId). 44 Filter("role_id", roleId).
43 Filter("code", code). 45 Filter("code", code).
44 - All(&data) 46 + One(&data)
  47 + fmt.Println(err)
45 if err != nil { 48 if err != nil {
46 return nil, err 49 return nil, err
47 } 50 }
48 - if len(data) > 0 {  
49 - return data[0], nil  
50 - }  
51 - return &RoleMenu{}, nil 51 + return &data, nil
52 } 52 }
53 53
54 func AddRoleMenu(m *RoleMenu, om ...orm.Ormer) (id int64, err error) { 54 func AddRoleMenu(m *RoleMenu, om ...orm.Ormer) (id int64, err error) {
55 var o orm.Ormer 55 var o orm.Ormer
56 - if len(om) == 0 { 56 + if len(om) > 0 {
57 o = om[0] 57 o = om[0]
58 } else { 58 } else {
59 o = orm.NewOrm() 59 o = orm.NewOrm()
@@ -54,7 +54,7 @@ func init() { @@ -54,7 +54,7 @@ func init() {
54 // last inserted Id on success. 54 // last inserted Id on success.
55 func AddUserRole(m *UserRole, om ...orm.Ormer) (id int64, err error) { 55 func AddUserRole(m *UserRole, om ...orm.Ormer) (id int64, err error) {
56 var o orm.Ormer 56 var o orm.Ormer
57 - if len(om) == 0 { 57 + if len(om) > 0 {
58 o = om[0] 58 o = om[0]
59 } else { 59 } else {
60 o = orm.NewOrm() 60 o = orm.NewOrm()
@@ -51,12 +51,13 @@ type BulletinListResponse struct { @@ -51,12 +51,13 @@ type BulletinListResponse struct {
51 } 51 }
52 52
53 type BulletinItem struct { 53 type BulletinItem struct {
54 - Id int `json:"id"`  
55 - Type int8 `json:"type"`  
56 - Title string `json:"title"`  
57 - Status int8 `json:"status"`  
58 - Receiver []VisibleObject `json:"receiver" valid:"Required"`  
59 - CreateAt string `json:"time"` 54 + Id int `json:"id"`
  55 + Type int8 `json:"type"`
  56 + Title string `json:"title"`
  57 + Status int8 `json:"status"`
  58 + QuestionSwitch int8 `json:"question_switch"`
  59 + Receiver []VisibleObject `json:"receiver" valid:"Required"`
  60 + CreateAt string `json:"time"`
60 } 61 }
61 62
62 /*GetBulletin */ 63 /*GetBulletin */
@@ -42,6 +42,8 @@ func init() { @@ -42,6 +42,8 @@ func init() {
42 beego.NSRouter("/menu/list", &controllers.RbacController{}, "post:MenuList"), 42 beego.NSRouter("/menu/list", &controllers.RbacController{}, "post:MenuList"),
43 beego.NSRouter("/role/menu", &controllers.RbacController{}, "post:RoleHasMenu"), 43 beego.NSRouter("/role/menu", &controllers.RbacController{}, "post:RoleHasMenu"),
44 beego.NSRouter("/role/menu/edit", &controllers.RbacController{}, "post:RoleMenuEdit"), 44 beego.NSRouter("/role/menu/edit", &controllers.RbacController{}, "post:RoleMenuEdit"),
  45 + beego.NSRouter("/role/menu/opportunity", &controllers.RbacController{}, "post:RoleMenuOpportunity"),
  46 + beego.NSRouter("/role/menu/opportunity/edit", &controllers.RbacController{}, "post:RoleMenuOpportunityEdit"),
45 ), 47 ),
46 beego.NSNamespace("/user", 48 beego.NSNamespace("/user",
47 beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"), 49 beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"),
@@ -3,7 +3,6 @@ package bulletin @@ -3,7 +3,6 @@ package bulletin
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
5 "fmt" 5 "fmt"
6 - orm2 "github.com/astaxie/beego/orm"  
7 "oppmg/common/log" 6 "oppmg/common/log"
8 "oppmg/models" 7 "oppmg/models"
9 "oppmg/protocol" 8 "oppmg/protocol"
@@ -12,6 +11,8 @@ import ( @@ -12,6 +11,8 @@ import (
12 "strconv" 11 "strconv"
13 "strings" 12 "strings"
14 "time" 13 "time"
  14 +
  15 + orm2 "github.com/astaxie/beego/orm"
15 ) 16 )
16 17
17 //发布公告 18 //发布公告
@@ -182,11 +183,12 @@ func BulletinList(uid, companyId int64, request *protocol.BulletinListRequest) ( @@ -182,11 +183,12 @@ func BulletinList(uid, companyId int64, request *protocol.BulletinListRequest) (
182 for i := range list { 183 for i := range list {
183 bulletin := list[i] 184 bulletin := list[i]
184 item := &protocol.BulletinItem{ 185 item := &protocol.BulletinItem{
185 - Id: bulletin.Id,  
186 - Type: bulletin.Type,  
187 - Title: bulletin.Title,  
188 - Status: int8(bulletin.Status),  
189 - CreateAt: bulletin.CreateAt.Format("2006-01-02 15:04:05"), 186 + Id: bulletin.Id,
  187 + Type: bulletin.Type,
  188 + Title: bulletin.Title,
  189 + QuestionSwitch: bulletin.QuestionSwitch,
  190 + Status: int8(bulletin.Status),
  191 + CreateAt: bulletin.CreateAt.Format("2006-01-02 15:04:05"),
190 } 192 }
191 if e := json.Unmarshal([]byte(bulletin.Receiver), &item.Receiver); e != nil { 193 if e := json.Unmarshal([]byte(bulletin.Receiver), &item.Receiver); e != nil {
192 log.Error(e.Error()) 194 log.Error(e.Error())
@@ -256,6 +258,9 @@ func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest) @@ -256,6 +258,9 @@ func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest)
256 AllowClose: int(bulletin.AllowClose), 258 AllowClose: int(bulletin.AllowClose),
257 //AllowCondition: int(bulletin.AllowCondition), 259 //AllowCondition: int(bulletin.AllowCondition),
258 Cover: protocol.Cover(bulletin.Cover), 260 Cover: protocol.Cover(bulletin.Cover),
  261 + Question: protocol.Question{
  262 + Content: []protocol.QuestionContent{},
  263 + },
259 } 264 }
260 if bulletin.QuestionSwitch == 1 { 265 if bulletin.QuestionSwitch == 1 {
261 if question, err = models.GetBulletinQuestionByBulletinId(bulletin.Id); err != nil { 266 if question, err = models.GetBulletinQuestionByBulletinId(bulletin.Id); err != nil {
@@ -324,26 +329,48 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r @@ -324,26 +329,48 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r
324 } 329 }
325 330
326 if bulletin.QuestionSwitch == 1 { 331 if bulletin.QuestionSwitch == 1 {
327 - if bulletinQuestion, err = models.GetBulletinQuestionByBulletinId(bulletin.Id); err != nil { 332 + bulletinQuestion, err = models.GetBulletinQuestionByBulletinId(bulletin.Id)
  333 + if err != nil && err != orm2.ErrNoRows {
328 log.Error(err.Error()) 334 log.Error(err.Error())
329 return 335 return
330 } 336 }
331 - if bulletinQuestion.BulletinId != bulletin.Id {  
332 - err = protocol.NewErrWithMessage("1")  
333 - log.Error("UpdateBulletin:BulletinId not equal:(%v!=%v)", bulletinQuestion.BulletinId, bulletin.Id)  
334 - return  
335 - }  
336 - if questionContent, err = json.Marshal(request.Question.Content); err != nil {  
337 - log.Error(err.Error())  
338 - return 337 + if err == nil {
  338 + //更新
  339 + if bulletinQuestion.BulletinId != bulletin.Id {
  340 + err = protocol.NewErrWithMessage("1")
  341 + log.Error("UpdateBulletin:BulletinId not equal:(%v!=%v)", bulletinQuestion.BulletinId, bulletin.Id)
  342 + return
  343 + }
  344 + if questionContent, err = json.Marshal(request.Question.Content); err != nil {
  345 + log.Error(err.Error())
  346 + return
  347 + }
  348 + bulletinQuestion.Title = request.Title
  349 + bulletinQuestion.Content = string(questionContent)
  350 + bulletinQuestion.Type = int8(request.Question.Type)
  351 + bulletinQuestion.UpdateAt = time.Now()
  352 + if err = models.UpdateBulletinQuestionById(bulletinQuestion); err != nil {
  353 + log.Error(err.Error())
  354 + return
  355 + }
339 } 356 }
340 - bulletinQuestion.Content = string(questionContent)  
341 - bulletinQuestion.Type = int8(request.Question.Type)  
342 - bulletinQuestion.UpdateAt = time.Now()  
343 - if err = models.UpdateBulletinQuestionById(bulletinQuestion); err != nil {  
344 - log.Error(err.Error())  
345 - return 357 + if err == orm2.ErrNoRows {
  358 + //添加
  359 + bulletinQuestion = &models.BulletinQuestion{
  360 + BulletinId: bulletin.Id,
  361 + Type: int8(request.Question.Type),
  362 + Title: request.Title,
  363 + Content: string(questionContent),
  364 + CreateAt: time.Now(),
  365 + UpdateAt: time.Now(),
  366 + }
  367 + _, err = models.AddBulletinQuestion(bulletinQuestion)
  368 + if err != nil {
  369 + log.Error("添加问题失败:%s", err)
  370 + return
  371 + }
346 } 372 }
  373 +
347 } 374 }
348 return 375 return
349 } 376 }
@@ -62,9 +62,9 @@ func FilterRoleAll(adminid int64, companyid int64, list []protocol.RoleBase) []p @@ -62,9 +62,9 @@ func FilterRoleAll(adminid int64, companyid int64, list []protocol.RoleBase) []p
62 } 62 }
63 } 63 }
64 for k, v := range list { 64 for k, v := range list {
65 - if v.Types == models.ROLETYPES_ROLE && v.IsDefault == models.ROLE_DEFAULR {  
66 - continue  
67 - } 65 + // if v.Types == models.ROLETYPES_ROLE && v.IsDefault == models.ROLE_DEFAULR {
  66 + // continue
  67 + // }
68 if companyInfo.AdminId != adminid { 68 if companyInfo.AdminId != adminid {
69 //非主管理员 69 //非主管理员
70 if v.Id == admingoroupId || v.ParentId == admingoroupId { 70 if v.Id == admingoroupId || v.ParentId == admingoroupId {
@@ -63,7 +63,7 @@ OptionOpportunity @@ -63,7 +63,7 @@ OptionOpportunity
63 type CheckDeparment struct { 63 type CheckDeparment struct {
64 Id int64 `json:"id"` 64 Id int64 `json:"id"`
65 Name string `json:"name,omitempty"` 65 Name string `json:"name,omitempty"`
66 - Wait int `json:"wail"` 66 + Wait int `json:"wait"`
67 OpenAll int `json:"open_all"` 67 OpenAll int `json:"open_all"`
68 OpenDepart int `json:"open_depart"` 68 OpenDepart int `json:"open_depart"`
69 } 69 }
@@ -75,11 +75,11 @@ type CheckOpp struct { @@ -75,11 +75,11 @@ type CheckOpp struct {
75 75
76 //OptionOpportunity 机会管理 高级权限设置 76 //OptionOpportunity 机会管理 高级权限设置
77 type OptionOpportunity struct { 77 type OptionOpportunity struct {
78 - Check int `json:"check"`  
79 - CheckOption CheckOpp  
80 - EditSorce int `json:"edit_sorce"`  
81 - EditPublicStatus int `json:"edit_public_status"`  
82 - CloseChance int `json:"close_chance"` 78 + Check int `json:"check"`
  79 + CheckOption CheckOpp `json:"check_option"`
  80 + EditSorce int `json:"edit_sorce"`
  81 + EditPublicStatus int `json:"edit_public_status"`
  82 + CloseChance int `json:"close_chance"`
83 } 83 }
84 84
85 /* 85 /*