...
|
...
|
@@ -3,7 +3,6 @@ package bulletin |
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
orm2 "github.com/astaxie/beego/orm"
|
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
...
|
...
|
@@ -12,6 +11,8 @@ import ( |
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
orm2 "github.com/astaxie/beego/orm"
|
|
|
)
|
|
|
|
|
|
//发布公告
|
...
|
...
|
@@ -182,11 +183,12 @@ func BulletinList(uid, companyId int64, request *protocol.BulletinListRequest) ( |
|
|
for i := range list {
|
|
|
bulletin := list[i]
|
|
|
item := &protocol.BulletinItem{
|
|
|
Id: bulletin.Id,
|
|
|
Type: bulletin.Type,
|
|
|
Title: bulletin.Title,
|
|
|
Status: int8(bulletin.Status),
|
|
|
CreateAt: bulletin.CreateAt.Format("2006-01-02 15:04:05"),
|
|
|
Id: bulletin.Id,
|
|
|
Type: bulletin.Type,
|
|
|
Title: bulletin.Title,
|
|
|
QuestionSwitch: bulletin.QuestionSwitch,
|
|
|
Status: int8(bulletin.Status),
|
|
|
CreateAt: bulletin.CreateAt.Format("2006-01-02 15:04:05"),
|
|
|
}
|
|
|
if e := json.Unmarshal([]byte(bulletin.Receiver), &item.Receiver); e != nil {
|
|
|
log.Error(e.Error())
|
...
|
...
|
@@ -256,6 +258,9 @@ func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest) |
|
|
AllowClose: int(bulletin.AllowClose),
|
|
|
//AllowCondition: int(bulletin.AllowCondition),
|
|
|
Cover: protocol.Cover(bulletin.Cover),
|
|
|
Question: protocol.Question{
|
|
|
Content: []protocol.QuestionContent{},
|
|
|
},
|
|
|
}
|
|
|
if bulletin.QuestionSwitch == 1 {
|
|
|
if question, err = models.GetBulletinQuestionByBulletinId(bulletin.Id); err != nil {
|
...
|
...
|
@@ -324,26 +329,48 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
|
|
}
|
|
|
|
|
|
if bulletin.QuestionSwitch == 1 {
|
|
|
if bulletinQuestion, err = models.GetBulletinQuestionByBulletinId(bulletin.Id); err != nil {
|
|
|
bulletinQuestion, err = models.GetBulletinQuestionByBulletinId(bulletin.Id)
|
|
|
if err != nil && err != orm2.ErrNoRows {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
if bulletinQuestion.BulletinId != bulletin.Id {
|
|
|
err = protocol.NewErrWithMessage("1")
|
|
|
log.Error("UpdateBulletin:BulletinId not equal:(%v!=%v)", bulletinQuestion.BulletinId, bulletin.Id)
|
|
|
return
|
|
|
}
|
|
|
if questionContent, err = json.Marshal(request.Question.Content); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
if err == nil {
|
|
|
//更新
|
|
|
if bulletinQuestion.BulletinId != bulletin.Id {
|
|
|
err = protocol.NewErrWithMessage("1")
|
|
|
log.Error("UpdateBulletin:BulletinId not equal:(%v!=%v)", bulletinQuestion.BulletinId, bulletin.Id)
|
|
|
return
|
|
|
}
|
|
|
if questionContent, err = json.Marshal(request.Question.Content); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
bulletinQuestion.Title = request.Title
|
|
|
bulletinQuestion.Content = string(questionContent)
|
|
|
bulletinQuestion.Type = int8(request.Question.Type)
|
|
|
bulletinQuestion.UpdateAt = time.Now()
|
|
|
if err = models.UpdateBulletinQuestionById(bulletinQuestion); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
bulletinQuestion.Content = string(questionContent)
|
|
|
bulletinQuestion.Type = int8(request.Question.Type)
|
|
|
bulletinQuestion.UpdateAt = time.Now()
|
|
|
if err = models.UpdateBulletinQuestionById(bulletinQuestion); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
if err == orm2.ErrNoRows {
|
|
|
//添加
|
|
|
bulletinQuestion = &models.BulletinQuestion{
|
|
|
BulletinId: bulletin.Id,
|
|
|
Type: int8(request.Question.Type),
|
|
|
Title: request.Title,
|
|
|
Content: string(questionContent),
|
|
|
CreateAt: time.Now(),
|
|
|
UpdateAt: time.Now(),
|
|
|
}
|
|
|
_, err = models.AddBulletinQuestion(bulletinQuestion)
|
|
|
if err != nil {
|
|
|
log.Error("添加问题失败:%s", err)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
return
|
|
|
}
|
...
|
...
|
|