...
|
...
|
@@ -45,6 +45,7 @@ func BulletinRelease(uid, companyId int64, request *protocol.BulletinReleaseRequ |
|
|
CreateAt: time.Now(),
|
|
|
UpdateAt: time.Now(),
|
|
|
Status: status,
|
|
|
AllPeople: request.AllPeo,
|
|
|
}
|
|
|
|
|
|
orm := orm2.NewOrm()
|
...
|
...
|
@@ -85,7 +86,7 @@ func BulletinRelease(uid, companyId int64, request *protocol.BulletinReleaseRequ |
|
|
}
|
|
|
//TODO:发送公告消息
|
|
|
if request.IsPublish == 1 {
|
|
|
if err = sendBulletinUserMsg(orm, request.Receiver, companyId, int64(id), bulletin.Title); err != nil {
|
|
|
if err = sendBulletinUserMsg(orm, request.Receiver, companyId, int64(id), bulletin.Title, request.AllPeo); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
...
|
...
|
@@ -136,13 +137,23 @@ func getBulletinReceiverIds(orm orm2.Ormer, receivers []protocol.VisibleObject, |
|
|
}
|
|
|
|
|
|
//发送公告消息
|
|
|
func sendBulletinUserMsg(orm orm2.Ormer, receivers []protocol.VisibleObject, companyId int64, sourceId int64, message string) (err error) {
|
|
|
func sendBulletinUserMsg(orm orm2.Ormer, receivers []protocol.VisibleObject, companyId int64, sourceId int64, message string, allPeople int8) (err error) {
|
|
|
var (
|
|
|
ids []int64
|
|
|
sended = make(map[int64]int64)
|
|
|
)
|
|
|
if ids, err = getBulletinReceiverIds(orm, receivers, companyId, sourceId, message); err != nil {
|
|
|
return
|
|
|
if allPeople == 1 {
|
|
|
if userCompanys, e := models.GetUserCompanyAll(companyId); e == nil {
|
|
|
for i := range userCompanys {
|
|
|
ids = append(ids, userCompanys[i].Id)
|
|
|
}
|
|
|
} else {
|
|
|
log.Error("%v %v", companyId, e.Error())
|
|
|
}
|
|
|
} else {
|
|
|
if ids, err = getBulletinReceiverIds(orm, receivers, companyId, sourceId, message); err != nil {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
for i := range ids {
|
|
|
if _, ok := sended[ids[i]]; ok {
|
...
|
...
|
@@ -256,6 +267,7 @@ func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest) |
|
|
Title: bulletin.Title,
|
|
|
Content: bulletin.Content,
|
|
|
AllowClose: int(bulletin.AllowClose),
|
|
|
AllPeo: bulletin.AllPeople,
|
|
|
//AllowCondition: int(bulletin.AllowCondition),
|
|
|
Cover: protocol.Cover(bulletin.Cover),
|
|
|
Question: protocol.Question{
|
...
|
...
|
@@ -326,7 +338,11 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
|
|
bulletin.QuestionSwitch = int8(request.QuestionSwitch)
|
|
|
//bulletin.AllowCondition = int8(request.AllowCondition)
|
|
|
bulletin.AllowClose = int8(request.AllowClose)
|
|
|
bulletin.AllPeople = request.AllPeo
|
|
|
bulletin.UpdateAt = time.Now()
|
|
|
if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease {
|
|
|
bulletin.Status = protocol.BulletinRelease
|
|
|
}
|
|
|
if err = models.UpdateBulletinById(bulletin); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
...
|
...
|
@@ -377,6 +393,14 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
|
|
}
|
|
|
|
|
|
}
|
|
|
orm := orm2.NewOrm()
|
|
|
if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease {
|
|
|
if err = sendBulletinUserMsg(orm, request.Receiver, companyId, int64(bulletin.Id), bulletin.Title, request.AllPeo); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -419,7 +443,7 @@ func OperateBulletin(companyId int64, request *protocol.OperateBulletinRequest) |
|
|
}
|
|
|
if request.CmdType == protocol.BulletinRelease { //上架
|
|
|
status = protocol.BulletinRelease
|
|
|
if err = sendBulletinUserMsg(orm, receiver, companyId, int64(bulletin.Id), bulletin.Title); err != nil {
|
|
|
if err = sendBulletinUserMsg(orm, receiver, companyId, int64(bulletin.Id), bulletin.Title, bulletin.AllPeople); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
...
|
...
|
|