作者 Administrator

合并分支 'test' 到 'master'

Test



查看合并请求 !1
@@ -2,11 +2,13 @@ package controllers @@ -2,11 +2,13 @@ package controllers
2 2
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
  5 + "fmt"
5 "oppmg/common/log" 6 "oppmg/common/log"
6 "oppmg/models" 7 "oppmg/models"
7 "oppmg/protocol" 8 "oppmg/protocol"
8 serveaudit "oppmg/services/audit" 9 serveaudit "oppmg/services/audit"
9 servecommon "oppmg/services/common" 10 servecommon "oppmg/services/common"
  11 + serverbac "oppmg/services/rbac"
10 "strconv" 12 "strconv"
11 "time" 13 "time"
12 ) 14 )
@@ -23,22 +25,32 @@ func (c *AuditController) AuditList() { @@ -23,22 +25,32 @@ func (c *AuditController) AuditList() {
23 c.ResposeJson(msg) 25 c.ResposeJson(msg)
24 }() 26 }()
25 var param protocol.RequestAuditList 27 var param protocol.RequestAuditList
  28 + param.Status = -1
  29 + param.ReviewStatus = -1
  30 + param.PublishStatus = -1
26 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil { 31 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
27 log.Error("json 解析失败", err) 32 log.Error("json 解析失败", err)
28 msg = protocol.BadRequestParam("1") 33 msg = protocol.BadRequestParam("1")
29 return 34 return
30 } 35 }
31 - beginTime, err := time.Parse("2006-01-02", param.CreateTimeBeginS) 36 + beginTime, err := time.ParseInLocation("2006-01-02", param.CreateTimeBeginS, time.Local)
32 if err == nil && len(param.CreateTimeBeginS) > 0 { 37 if err == nil && len(param.CreateTimeBeginS) > 0 {
33 param.CreateTimeBegin = beginTime.Unix() 38 param.CreateTimeBegin = beginTime.Unix()
34 } 39 }
35 - endTime, err := time.Parse("2006-01-02", param.CreateTimeEndS) 40 + endTime, err := time.ParseInLocation("2006-01-02", param.CreateTimeEndS, time.Local)
36 if err == nil && len(param.CreateTimeEndS) > 0 { 41 if err == nil && len(param.CreateTimeEndS) > 0 {
37 - param.CreateTimeEnd = endTime.Unix() + 864399 42 + param.CreateTimeEnd = endTime.Unix() + 86399
38 } 43 }
  44 + fmt.Println(err, param.CreateTimeBegin, param.CreateTimeEnd)
  45 + if len(param.StatusS) > 0 {
39 param.Status, _ = strconv.Atoi(param.StatusS) 46 param.Status, _ = strconv.Atoi(param.StatusS)
  47 + }
  48 + if len(param.ReviewStatusS) > 0 {
40 param.ReviewStatus, _ = strconv.Atoi(param.ReviewStatusS) 49 param.ReviewStatus, _ = strconv.Atoi(param.ReviewStatusS)
  50 + }
  51 + if len(param.PublishStatusS) > 0 {
41 param.PublishStatus, _ = strconv.Atoi(param.PublishStatusS) 52 param.PublishStatus, _ = strconv.Atoi(param.PublishStatusS)
  53 + }
42 uid := c.GetUserId() 54 uid := c.GetUserId()
43 companyId := c.GetCompanyId() 55 companyId := c.GetCompanyId()
44 list, err := serveaudit.GetAuditList(param, companyId, uid) 56 list, err := serveaudit.GetAuditList(param, companyId, uid)
@@ -53,7 +65,7 @@ func (c *AuditController) AuditListBefore() { @@ -53,7 +65,7 @@ func (c *AuditController) AuditListBefore() {
53 defer func() { 65 defer func() {
54 c.ResposeJson(msg) 66 c.ResposeJson(msg)
55 }() 67 }()
56 - // uid := c.GetUserId() 68 + uid := c.GetUserId()
57 companyId := c.GetCompanyId() 69 companyId := c.GetCompanyId()
58 templatelist := servecommon.SelectGetTemplateList(companyId) 70 templatelist := servecommon.SelectGetTemplateList(companyId)
59 chanceTypeList := servecommon.SeleteGetChanceTypeList(companyId) 71 chanceTypeList := servecommon.SeleteGetChanceTypeList(companyId)
@@ -61,6 +73,10 @@ func (c *AuditController) AuditListBefore() { @@ -61,6 +73,10 @@ func (c *AuditController) AuditListBefore() {
61 publicStatus := models.ChancePublishStatusMap 73 publicStatus := models.ChancePublishStatusMap
62 Status := models.ChanceStatusMap 74 Status := models.ChanceStatusMap
63 reviewStatus := models.ChanceReviewStatusMap 75 reviewStatus := models.ChanceReviewStatusMap
  76 + var (
  77 + auditPermission serverbac.OptionOpportunity
  78 + )
  79 + auditPermission = serveaudit.GetPermissionInAuditPage(uid, companyId)
64 data := map[string]interface{}{ 80 data := map[string]interface{}{
65 "template": templatelist, 81 "template": templatelist,
66 "chance_type": chanceTypeList, 82 "chance_type": chanceTypeList,
@@ -68,6 +84,7 @@ func (c *AuditController) AuditListBefore() { @@ -68,6 +84,7 @@ func (c *AuditController) AuditListBefore() {
68 "enable_status": Status, 84 "enable_status": Status,
69 "review_status": reviewStatus, 85 "review_status": reviewStatus,
70 "department": departmentList, 86 "department": departmentList,
  87 + "permission": auditPermission,
71 } 88 }
72 msg = protocol.NewReturnResponse(data, nil) 89 msg = protocol.NewReturnResponse(data, nil)
73 return 90 return
@@ -104,10 +104,10 @@ func GetAuditTemplateByTypeId(chanceTypeId int) (v []*AuditTemplate, err error) @@ -104,10 +104,10 @@ func GetAuditTemplateByTypeId(chanceTypeId int) (v []*AuditTemplate, err error)
104 return 104 return
105 } 105 }
106 106
107 -func GetAuditTemplateByCode(companyId int64, code string) (v *ChanceType, err error) { 107 +func GetAuditTemplateByCode(companyId int64, code string, chanceTypeId int) (v *ChanceType, err error) {
108 o := orm.NewOrm() 108 o := orm.NewOrm()
109 - sql := "select * from audit_template where binary code=? and company_id=?"  
110 - if err = o.Raw(sql, code, companyId).QueryRow(&v); err == nil { 109 + sql := "select * from audit_template where binary code=? and company_id=? and chance_type_id=?"
  110 + if err = o.Raw(sql, code, companyId, chanceTypeId).QueryRow(&v); err == nil {
111 return 111 return
112 } 112 }
113 return 113 return
@@ -56,8 +56,8 @@ func GetBulletinById(id int) (v *Bulletin, err error) { @@ -56,8 +56,8 @@ func GetBulletinById(id int) (v *Bulletin, err error) {
56 56
57 // UpdateBulletin updates Bulletin by Id and returns error if 57 // UpdateBulletin updates Bulletin by Id and returns error if
58 // the record to be updated doesn't exist 58 // the record to be updated doesn't exist
59 -func UpdateBulletinById(m *Bulletin) (err error) {  
60 - o := orm.NewOrm() 59 +func UpdateBulletinById(o orm.Ormer, m *Bulletin) (err error) {
  60 + //o := orm.NewOrm()
61 v := Bulletin{Id: m.Id} 61 v := Bulletin{Id: m.Id}
62 // ascertain id exists in the database 62 // ascertain id exists in the database
63 if err = o.Read(&v); err == nil { 63 if err = o.Read(&v); err == nil {
@@ -46,8 +46,8 @@ func GetBulletinQuestionById(id int) (v *BulletinQuestion, err error) { @@ -46,8 +46,8 @@ func GetBulletinQuestionById(id int) (v *BulletinQuestion, err error) {
46 46
47 // UpdateBulletinQuestion updates BulletinQuestion by Id and returns error if 47 // UpdateBulletinQuestion updates BulletinQuestion by Id and returns error if
48 // the record to be updated doesn't exist 48 // the record to be updated doesn't exist
49 -func UpdateBulletinQuestionById(m *BulletinQuestion) (err error) {  
50 - o := orm.NewOrm() 49 +func UpdateBulletinQuestionById(o orm.Ormer, m *BulletinQuestion) (err error) {
  50 + //o := orm.NewOrm()
51 v := BulletinQuestion{Id: m.Id} 51 v := BulletinQuestion{Id: m.Id}
52 // ascertain id exists in the database 52 // ascertain id exists in the database
53 if err = o.Read(&v); err == nil { 53 if err = o.Read(&v); err == nil {
@@ -33,8 +33,15 @@ const ( @@ -33,8 +33,15 @@ const (
33 SourceTypeBulletin = 3 33 SourceTypeBulletin = 3
34 ) 34 )
35 35
  36 +//列表是否展示(公告列表)
  37 +const (
  38 + Public = 1 //公开
  39 + NoPublic = 0 //不公开
  40 +)
  41 +
36 const ( 42 const (
37 SqlDeleteUserMsg = "delete from user_msg where company_id=? and msg_type=? and source_id=?" 43 SqlDeleteUserMsg = "delete from user_msg where company_id=? and msg_type=? and source_id=?"
  44 + SqlUpdateUserMsgPublic = "update user_msg set is_public=? where company_id=? and msg_type=? and source_id=?"
38 ) 45 )
39 46
40 func (t *UserMsg) TableName() string { 47 func (t *UserMsg) TableName() string {
@@ -94,6 +101,17 @@ func DeleteUserMsg(id int64) (err error) { @@ -94,6 +101,17 @@ func DeleteUserMsg(id int64) (err error) {
94 return 101 return
95 } 102 }
96 103
  104 +//获取userMsg
  105 +func GetUserMsgBy(userCompanyId int64, msgType int, sourceType int, sourceId int64) (v *UserMsg, err error) {
  106 + sql := "select * from user_msg where receive_user_id=? and msg_type=? and source_type=? and source_id=?"
  107 + o := orm.NewOrm()
  108 + if err = o.Raw(sql, userCompanyId, msgType, sourceType, sourceId).QueryRow(&v); err != nil {
  109 + //log.Error(err.Error())
  110 + return
  111 + }
  112 + return
  113 +}
  114 +
97 func NewUserMsg(companId, userCompanyId int64, msgType int, sourceType int, sourceId int64, message string) *UserMsg { 115 func NewUserMsg(companId, userCompanyId int64, msgType int, sourceType int, sourceId int64, message string) *UserMsg {
98 return &UserMsg{ 116 return &UserMsg{
99 Id: utils.GenerateIDBySonyflake(), 117 Id: utils.GenerateIDBySonyflake(),
@@ -104,5 +122,6 @@ func NewUserMsg(companId, userCompanyId int64, msgType int, sourceType int, sour @@ -104,5 +122,6 @@ func NewUserMsg(companId, userCompanyId int64, msgType int, sourceType int, sour
104 SourceId: sourceId, 122 SourceId: sourceId,
105 Message: message, 123 Message: message,
106 CreateAt: time.Now(), 124 CreateAt: time.Now(),
  125 + IsPublic: Public,
107 } 126 }
108 } 127 }
@@ -237,7 +237,7 @@ type RequestAuditList struct { @@ -237,7 +237,7 @@ type RequestAuditList struct {
237 ReviewStatus int `json:"-"` // 237 ReviewStatus int `json:"-"` //
238 ReviewStatusS string `json:"review_status"` // 238 ReviewStatusS string `json:"review_status"` //
239 Status int `json:"-"` //关闭状态 239 Status int `json:"-"` //关闭状态
240 - StatusS string `json:"enable_status"` //关闭状态 240 + StatusS string `json:"status"` //关闭状态
241 DepartmentID int `json:"department_id"` //提交部门 241 DepartmentID int `json:"department_id"` //提交部门
242 CreateTimeBegin int64 `json:"-"` // 242 CreateTimeBegin int64 `json:"-"` //
243 CreateTimeBeginS string `json:"create_time_begin"` 243 CreateTimeBeginS string `json:"create_time_begin"`
@@ -2,6 +2,7 @@ package audit @@ -2,6 +2,7 @@ package audit
2 2
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
  5 + "errors"
5 "fmt" 6 "fmt"
6 "oppmg/common/log" 7 "oppmg/common/log"
7 "oppmg/models" 8 "oppmg/models"
@@ -21,7 +22,7 @@ type SqlData struct { @@ -21,7 +22,7 @@ type SqlData struct {
21 AuditTemplateId int64 `orm:"column(audit_template_id)"` 22 AuditTemplateId int64 `orm:"column(audit_template_id)"`
22 ChanceTypeId int `orm:"column(chance_type_id)"` 23 ChanceTypeId int `orm:"column(chance_type_id)"`
23 PublishStatus int `orm:"column(publish_status)"` 24 PublishStatus int `orm:"column(publish_status)"`
24 - CreateAt string `orm:"column(create_at)` 25 + CreateAt string `orm:"column(create_at)"`
25 ReviewStatus int8 `orm:"column(review_status)"` 26 ReviewStatus int8 `orm:"column(review_status)"`
26 Status int8 `orm:"column(status)"` 27 Status int8 `orm:"column(status)"`
27 DiscoveryScore string `orm:"column(discovery_score)"` 28 DiscoveryScore string `orm:"column(discovery_score)"`
@@ -29,6 +30,35 @@ type SqlData struct { @@ -29,6 +30,35 @@ type SqlData struct {
29 Code string `orm:"column(code)"` 30 Code string `orm:"column(code)"`
30 } 31 }
31 32
  33 +func getAuditUserHasPermission(userid int64, usercompanyid int64) (
  34 + serverabc.PermissionOptionObject, error) {
  35 + var permissionObject serverabc.PermissionOptionObject
  36 + var err error
  37 + if ok := redisdata.ExistUserPermission(userid); !ok {
  38 + //尝试重数据库获取
  39 + log.Debug("从数据库读取权限")
  40 + permissionMap, err := serverabc.GetUserPermission(usercompanyid, serverabc.M_SYSTEM_OPPORTUNITY)
  41 + if err != nil {
  42 + log.Debug("从数据库未获得对应权限 :%s", err)
  43 + return nil, err
  44 + }
  45 + if v, ok := permissionMap[serverabc.M_SYSTEM_OPPORTUNITY]; !ok {
  46 + return nil, errors.New("can not found object")
  47 + } else {
  48 + permissionObject = v
  49 + }
  50 + } else {
  51 + //使用缓存
  52 + log.Debug("从缓存读取权限")
  53 + permissionObject, err = redisdata.GetUserPermission(userid, serverabc.M_SYSTEM_OPPORTUNITY)
  54 + if err != nil {
  55 + log.Debug("从缓存未获得对应权限 :%s", err)
  56 + return nil, err
  57 + }
  58 + }
  59 + return permissionObject, nil
  60 +}
  61 +
32 //根据权限获取机会列表 62 //根据权限获取机会列表
33 func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) string { 63 func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) string {
34 /* 64 /*
@@ -63,32 +93,38 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st @@ -63,32 +93,38 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st
63 permissionObject serverabc.PermissionOptionObject 93 permissionObject serverabc.PermissionOptionObject
64 err error 94 err error
65 ) 95 )
66 - //获取权限  
67 - if ok := redisdata.ExistUserPermission(userid); !ok {  
68 - //尝试重数据库获取  
69 - log.Debug("从数据库读取权限")  
70 - permissionMap, err := serverabc.GetUserPermission(usercompanyid, serverabc.M_SYSTEM_OPPORTUNITY)  
71 - if err != nil {  
72 - log.Debug("从数据库未获得对应权限 :%s", err) 96 + //---------------------------------
  97 + if permissionObject, err = getAuditUserHasPermission(userid, usercompanyid); err != nil {
73 unionsql = sql1 + " UNION " + sql2 98 unionsql = sql1 + " UNION " + sql2
74 return fmt.Sprintf(allsql, unionsql) 99 return fmt.Sprintf(allsql, unionsql)
75 } 100 }
76 - if v, ok := permissionMap[serverabc.M_SYSTEM_OPPORTUNITY]; !ok {  
77 - unionsql = sql1 + " UNION " + sql2  
78 - return fmt.Sprintf(allsql, unionsql)  
79 - } else {  
80 - permissionObject = v  
81 - }  
82 - } else {  
83 - //使用缓存  
84 - log.Debug("从缓存读取权限")  
85 - permissionObject, err = redisdata.GetUserPermission(userid, serverabc.M_SYSTEM_OPPORTUNITY)  
86 - if err != nil {  
87 - log.Debug("从缓存未获得对应权限 :%s", err)  
88 - unionsql = sql1 + " UNION " + sql2  
89 - return fmt.Sprintf(allsql, unionsql)  
90 - }  
91 - } 101 + // //获取权限
  102 + // if ok := redisdata.ExistUserPermission(userid); !ok {
  103 + // //尝试重数据库获取
  104 + // log.Debug("从数据库读取权限")
  105 + // permissionMap, err := serverabc.GetUserPermission(usercompanyid, serverabc.M_SYSTEM_OPPORTUNITY)
  106 + // if err != nil {
  107 + // log.Debug("从数据库未获得对应权限 :%s", err)
  108 + // unionsql = sql1 + " UNION " + sql2
  109 + // return fmt.Sprintf(allsql, unionsql)
  110 + // }
  111 + // if v, ok := permissionMap[serverabc.M_SYSTEM_OPPORTUNITY]; !ok {
  112 + // unionsql = sql1 + " UNION " + sql2
  113 + // return fmt.Sprintf(allsql, unionsql)
  114 + // } else {
  115 + // permissionObject = v
  116 + // }
  117 + // } else {
  118 + // //使用缓存
  119 + // log.Debug("从缓存读取权限")
  120 + // permissionObject, err = redisdata.GetUserPermission(userid, serverabc.M_SYSTEM_OPPORTUNITY)
  121 + // if err != nil {
  122 + // log.Debug("从缓存未获得对应权限 :%s", err)
  123 + // unionsql = sql1 + " UNION " + sql2
  124 + // return fmt.Sprintf(allsql, unionsql)
  125 + // }
  126 + // }
  127 + // -------------------------
92 var ( 128 var (
93 usrPermission *serverabc.OptionOpportunity 129 usrPermission *serverabc.OptionOpportunity
94 ok bool 130 ok bool
@@ -475,3 +511,43 @@ func ForbidChanceEnableStatus(chanceid int64, companyid int64) error { @@ -475,3 +511,43 @@ func ForbidChanceEnableStatus(chanceid int64, companyid int64) error {
475 } 511 }
476 return nil 512 return nil
477 } 513 }
  514 +
  515 +//获取用户在机会管理中的权限
  516 +func GetPermissionInAuditPage(userid int64, companyid int64) serverabc.OptionOpportunity {
  517 + var (
  518 + option serverabc.OptionOpportunity
  519 + err error
  520 + ucompany *models.UserCompany
  521 + companyinfo *models.Company
  522 + )
  523 + companyinfo, err = models.GetCompanyById(companyid)
  524 + if err != nil {
  525 + log.Error("GetCompanyById err:%s", err)
  526 + return option
  527 + }
  528 + if companyinfo.AdminId == userid {
  529 + option = serverabc.OptionOpportunity{
  530 + Check: serverabc.OpportunityCheckLv4,
  531 + EditSorce: 1,
  532 + EditPublicStatus: 1,
  533 + CloseChance: 1,
  534 + EditChance: 1,
  535 + }
  536 + return option
  537 + }
  538 + ucompany, err = models.GetUserCompanyBy(userid, companyid)
  539 + if err != nil {
  540 + log.Error("获取用户数据失败:GetUserCompanyBy err:%s", err)
  541 + return option
  542 + }
  543 + permissionobj, err := getAuditUserHasPermission(userid, ucompany.Id)
  544 + if err != nil {
  545 + return option
  546 + }
  547 + if v, ok := permissionobj.(*serverabc.OptionOpportunity); ok {
  548 + option = *v
  549 + option.CheckMap = nil
  550 + option.CheckOption = nil
  551 + }
  552 + return option
  553 +}
@@ -30,7 +30,7 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs @@ -30,7 +30,7 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs
30 err = protocol.NewErrWithMessage("10065") 30 err = protocol.NewErrWithMessage("10065")
31 return 31 return
32 } 32 }
33 - if _, err = models.GetAuditTemplateByCode(companyId, request.Template.Code); err == nil { 33 + if _, err = models.GetAuditTemplateByCode(companyId, request.Template.Code, request.Template.ChanceTypeId); err == nil {
34 err = protocol.NewErrWithMessage("10064") 34 err = protocol.NewErrWithMessage("10064")
35 return 35 return
36 } 36 }
@@ -823,7 +823,7 @@ func ValidFormList(inputs []*protocol.InputElement) (msg *protocol.ResponseMessa @@ -823,7 +823,7 @@ func ValidFormList(inputs []*protocol.InputElement) (msg *protocol.ResponseMessa
823 msg = protocol.BadRequestParam("10285") 823 msg = protocol.BadRequestParam("10285")
824 return 824 return
825 } 825 }
826 - if countBasic >= 10 || countExtral >= 10 { 826 + if countBasic > 10 || countExtral > 10 {
827 msg = protocol.BadRequestParam("10274") 827 msg = protocol.BadRequestParam("10274")
828 return 828 return
829 } 829 }
@@ -200,7 +200,7 @@ func LoginAuthByUCenter(account, password string) ( @@ -200,7 +200,7 @@ func LoginAuthByUCenter(account, password string) (
200 ucompany, err := models.GetUserCompanyBy(userdata.Id, companyid) 200 ucompany, err := models.GetUserCompanyBy(userdata.Id, companyid)
201 if err != nil { 201 if err != nil {
202 log.Error("获取user_company失败;%s", err) 202 log.Error("获取user_company失败;%s", err)
203 - return logintoken, protocol.NewErrWithMessage("1") 203 + return logintoken, protocol.NewErrWithMessage("10022")
204 } 204 }
205 usercompanyid = ucompany.Id 205 usercompanyid = ucompany.Id
206 logintoken, _ = GenerateAuthToken(userdata.Id, companyid, usercompanyid) 206 logintoken, _ = GenerateAuthToken(userdata.Id, companyid, usercompanyid)
@@ -528,6 +528,7 @@ func ValidUserPermission(urlPath string, userid int64, companyid int64) bool { @@ -528,6 +528,7 @@ func ValidUserPermission(urlPath string, userid int64, companyid int64) bool {
528 528
529 permissionObj, err = redisdata.GetUserPermission(userid, permissionbase.CodeName) 529 permissionObj, err = redisdata.GetUserPermission(userid, permissionbase.CodeName)
530 if err != nil { 530 if err != nil {
  531 + //尝试从 数据库取权限 TODO
531 log.Error("未取到权限数据 err:%s", err) 532 log.Error("未取到权限数据 err:%s", err)
532 return false 533 return false
533 } 534 }
@@ -169,17 +169,26 @@ func sendBulletinUserMsg(orm orm2.Ormer, receivers []protocol.VisibleObject, com @@ -169,17 +169,26 @@ func sendBulletinUserMsg(orm orm2.Ormer, receivers []protocol.VisibleObject, com
169 return 169 return
170 } 170 }
171 } 171 }
  172 + if err = utils.ExecuteSQLWithOrmer(orm, models.SqlUpdateUserMsgPublic, models.Public, companyId, models.MsgTypeBulletin, sourceId); err != nil {
  173 + log.Error(err.Error())
  174 + orm.Rollback()
  175 + return
  176 + }
172 for i := range ids { 177 for i := range ids {
173 if _, ok := sended[ids[i]]; ok { 178 if _, ok := sended[ids[i]]; ok {
174 continue 179 continue
175 } 180 }
176 sended[ids[i]] = ids[i] 181 sended[ids[i]] = ids[i]
  182 + //这条消息不存在,插入一条消息
  183 + if _, e := models.GetUserMsgBy(ids[i], models.MsgTypeBulletin, models.SourceTypeBulletin, sourceId); e != nil && e == orm2.ErrNoRows {
177 msg := models.NewUserMsg(companyId, ids[i], models.MsgTypeBulletin, models.SourceTypeBulletin, sourceId, message) 184 msg := models.NewUserMsg(companyId, ids[i], models.MsgTypeBulletin, models.SourceTypeBulletin, sourceId, message)
178 if _, err = orm.Insert(msg); err != nil { 185 if _, err = orm.Insert(msg); err != nil {
  186 + orm.Rollback()
179 log.Error(err.Error()) 187 log.Error(err.Error())
180 return 188 return
181 } 189 }
182 } 190 }
  191 + }
183 return 192 return
184 } 193 }
185 194
@@ -345,6 +354,17 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r @@ -345,6 +354,17 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r
345 log.Error(err.Error()) 354 log.Error(err.Error())
346 return 355 return
347 } 356 }
  357 + orm := orm2.NewOrm()
  358 + orm.Begin()
  359 +
  360 + if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease {
  361 + if err = sendBulletinUserMsg(orm, request.Receiver, companyId, int64(bulletin.Id), bulletin.Title, request.AllPeo); err != nil {
  362 + log.Error(err.Error())
  363 + orm.Rollback()
  364 + return
  365 + }
  366 + }
  367 +
348 //update 368 //update
349 { 369 {
350 bulletin.Title = request.Title 370 bulletin.Title = request.Title
@@ -360,8 +380,10 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r @@ -360,8 +380,10 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r
360 if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease { 380 if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease {
361 bulletin.Status = protocol.BulletinRelease 381 bulletin.Status = protocol.BulletinRelease
362 } 382 }
363 - if err = models.UpdateBulletinById(bulletin); err != nil { 383 +
  384 + if err = models.UpdateBulletinById(orm, bulletin); err != nil {
364 log.Error(err.Error()) 385 log.Error(err.Error())
  386 + orm.Rollback()
365 return 387 return
366 } 388 }
367 } 389 }
@@ -371,6 +393,7 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r @@ -371,6 +393,7 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r
371 validQuestion(&request.Question) 393 validQuestion(&request.Question)
372 if err != nil && err != orm2.ErrNoRows { 394 if err != nil && err != orm2.ErrNoRows {
373 log.Error(err.Error()) 395 log.Error(err.Error())
  396 + orm.Rollback()
374 return 397 return
375 } 398 }
376 if err == nil { 399 if err == nil {
@@ -388,8 +411,9 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r @@ -388,8 +411,9 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r
388 bulletinQuestion.Content = string(questionContent) 411 bulletinQuestion.Content = string(questionContent)
389 bulletinQuestion.Type = int8(request.Question.Type) 412 bulletinQuestion.Type = int8(request.Question.Type)
390 bulletinQuestion.UpdateAt = time.Now() 413 bulletinQuestion.UpdateAt = time.Now()
391 - if err = models.UpdateBulletinQuestionById(bulletinQuestion); err != nil { 414 + if err = models.UpdateBulletinQuestionById(orm, bulletinQuestion); err != nil {
392 log.Error(err.Error()) 415 log.Error(err.Error())
  416 + orm.Rollback()
393 return 417 return
394 } 418 }
395 } 419 }
@@ -403,22 +427,16 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r @@ -403,22 +427,16 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r
403 CreateAt: time.Now(), 427 CreateAt: time.Now(),
404 UpdateAt: time.Now(), 428 UpdateAt: time.Now(),
405 } 429 }
406 - _, err = models.AddBulletinQuestion(bulletinQuestion) 430 + _, err = orm.Insert(bulletinQuestion)
407 if err != nil { 431 if err != nil {
  432 + orm.Rollback()
408 log.Error("添加问题失败:%s", err) 433 log.Error("添加问题失败:%s", err)
409 return 434 return
410 } 435 }
411 } 436 }
412 437
413 } 438 }
414 - orm := orm2.NewOrm()  
415 - if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease {  
416 - if err = sendBulletinUserMsg(orm, request.Receiver, companyId, int64(bulletin.Id), bulletin.Title, request.AllPeo); err != nil {  
417 - log.Error(err.Error())  
418 - orm.Rollback()  
419 - return  
420 - }  
421 - } 439 + orm.Commit()
422 return 440 return
423 } 441 }
424 442
@@ -453,7 +471,7 @@ func OperateBulletin(companyId int64, request *protocol.OperateBulletinRequest) @@ -453,7 +471,7 @@ func OperateBulletin(companyId int64, request *protocol.OperateBulletinRequest)
453 orm.Begin() 471 orm.Begin()
454 if request.CmdType == protocol.BulletinUnRelease { //下架 472 if request.CmdType == protocol.BulletinUnRelease { //下架
455 status = protocol.BulletinUnRelease 473 status = protocol.BulletinUnRelease
456 - if err = utils.ExecuteSQLWithOrmer(orm, models.SqlDeleteUserMsg, companyId, models.MsgTypeBulletin, bulletin.Id); err != nil { 474 + if err = utils.ExecuteSQLWithOrmer(orm, models.SqlUpdateUserMsgPublic, models.NoPublic, companyId, models.MsgTypeBulletin, bulletin.Id); err != nil {
457 log.Error(err.Error()) 475 log.Error(err.Error())
458 orm.Rollback() 476 orm.Rollback()
459 return 477 return
@@ -477,7 +477,7 @@ func UserDelete(userCompanyids []int64, companyid int64) error { @@ -477,7 +477,7 @@ func UserDelete(userCompanyids []int64, companyid int64) error {
477 ids []int64 477 ids []int64
478 ) 478 )
479 for _, v := range updateIds { 479 for _, v := range updateIds {
480 - if v.Id == companyInfo.AdminId { 480 + if v.UserId == companyInfo.AdminId {
481 return protocol.NewErrWithMessage("10071") 481 return protocol.NewErrWithMessage("10071")
482 } 482 }
483 ids = append(ids, v.Id) 483 ids = append(ids, v.Id)
@@ -123,7 +123,7 @@ var ( @@ -123,7 +123,7 @@ var (
123 123
124 func NewOptionOpportunity() PermissionOptionObject { 124 func NewOptionOpportunity() PermissionOptionObject {
125 return &OptionOpportunity{ 125 return &OptionOpportunity{
126 - Check: OpportunityCheckLv1, 126 + Check: OpportunityCheckLv2,
127 CheckMap: make(map[int]int), 127 CheckMap: make(map[int]int),
128 CheckOption: &CheckOpp{ 128 CheckOption: &CheckOpp{
129 Departments: []CheckDeparment{}, 129 Departments: []CheckDeparment{},
@@ -6,7 +6,6 @@ import ( @@ -6,7 +6,6 @@ import (
6 "oppmg/models" 6 "oppmg/models"
7 "oppmg/protocol" 7 "oppmg/protocol"
8 "oppmg/utils" 8 "oppmg/utils"
9 - "strings"  
10 "time" 9 "time"
11 ) 10 )
12 11
@@ -334,23 +333,19 @@ func GetRoleHasRole(roleid int64, companyid int64) ([]protocol.RoleHasUser, erro @@ -334,23 +333,19 @@ func GetRoleHasRole(roleid int64, companyid int64) ([]protocol.RoleHasUser, erro
334 return roleuserlist, protocol.NewErrWithMessage("1") 333 return roleuserlist, protocol.NewErrWithMessage("1")
335 } 334 }
336 var ( 335 var (
337 - ucid []string  
338 - datasql string = `SELECT user_company_id FROM user_role  
339 - WHERE company_id=? AND role_id =? AND enable_status = 1`  
340 - datasql2 string = `SELECT a.nick_name,b.id AS user_company_id FROM user AS a,user_company AS b  
341 - WHERE a.id= b.user_id AND b.id IN(?)` 336 + datasql2 string = `SELECT a.nick_name,b.id AS user_company_id
  337 + FROM user AS a
  338 + JOIN user_company AS b ON a.id=b.user_id
  339 + JOIN user_role AS c ON b.id= c.user_company_id
  340 + WHERE c.company_id=?
  341 + AND c.role_id =?
  342 + AND c.enable_status = 1
  343 + AND b.enable = 1 AND b.delete_at = 0 `
342 ) 344 )
343 - err = utils.ExecuteQueryAll(&ucid, datasql, companyid, roleid) 345 + err = utils.ExecuteQueryAll(&roleuserlist, datasql2, companyid, roleid)
344 if err != nil { 346 if err != nil {
345 - log.Error("获取用户id失败:%s", err)  
346 - return roleuserlist, protocol.NewErrWithMessage("1")  
347 - }  
348 - if len(ucid) == 0 {  
349 - return roleuserlist, nil  
350 - }  
351 - err = utils.ExecuteQueryAll(&roleuserlist, datasql2, strings.Join(ucid, ","))  
352 - if err != nil {  
353 - log.Error("获取用户时间失败;%s", err) 347 + log.Error("获取用户数据失败;%s", err)
354 } 348 }
  349 +
355 return roleuserlist, nil 350 return roleuserlist, nil
356 } 351 }