作者 yangfu

机会审核消息修改

... ... @@ -158,3 +158,24 @@ func (this *MessageController) MsgCompanyNotice() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(message.MsgCompanyNotice(header, request))
}
//MsgChanceApprove 机会审核消息
//@router /msgChanceApprove [post]
func (this *MessageController) MsgChanceApprove() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.MsgChanceApproveRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(message.MsgChanceApprove(header, request))
}
... ...
package utils
import (
"encoding/json"
"errors"
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"reflect"
"strings"
)
... ... @@ -74,3 +76,12 @@ func IsNil(i interface{}) bool {
}
return false
}
func JsonUnmarshal(jsonData string, v interface{}) {
if len(jsonData) == 0 {
return
}
if e := json.Unmarshal([]byte(jsonData), v); e != nil {
log.Error("json.unmarshal error data:", jsonData, e)
}
}
... ...
... ... @@ -173,3 +173,27 @@ func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pag
}
return
}
//获取机会消息
func GetChanceMsg(uid, cid int64, lastId int64, pageSize int, msgType int, v interface{}) (total int, err error) {
sql := `select a.*,b.images,b.speechs,b.videos from (
select a.*,b.source_content,b.enable_status,b.user_id chance_user_id from (
select id,company_id,receive_user_id,message,source_id,create_time,is_read
from user_msg where receive_user_id=? and source_type=1 and (?=0 or id>?) and msg_type=?
)a left outer join chance b on a.source_id = b.id
)a left outer join chance_data b on a.source_id =b.chance_id
order by a.create_time desc
LIMIT ?`
sqlCount := `select count(0)
from user_msg where receive_user_id=? and source_type=1 and msg_type=? `
if err = utils.ExecuteQueryOne(&total, sqlCount, uid, msgType); err != nil {
return
}
if v != nil {
if err = utils.ExecuteQueryAll(v, sql, uid, lastId, lastId, msgType, pageSize); err != nil {
return
}
}
return
}
... ...
... ... @@ -2,6 +2,7 @@ package protocol
import (
"encoding/json"
"time"
)
var errmessge ErrorMap = map[int]string{
... ... @@ -47,10 +48,13 @@ var errmessge ErrorMap = map[int]string{
}
const (
MsgTypeBulletin = 1 //公告
MsgTypeCommend = 2 //表彰
MsgTypeInteraction = 4 //互动消息
MsgTypeAudit = 8 //机会审核
MsgTypeBulletin = 1 //公告
MsgTypeCommend = 2 //表彰
MsgTypeInteraction = 4 //互动消息
MsgTypeAudit = 8 //机会审核
MsgTypeAuditBy = 16 //机会被审核消息
MsgTypeComment = 32 //评论
MsgTypeThumbUp = 64 //点赞
)
var (
... ... @@ -192,6 +196,35 @@ type MsgCompanyNoticeResponse struct {
Total int `json:"total"`
}
/*MsgChanceApprove 机会审核消息*/
type MsgChanceApproveRequest struct {
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
}
type MsgChanceApproveResponse struct {
List []CommonListItem `json:"list"`
Total int `json:"total"`
}
//我的审核机会列表
type MsgChanceApproveItemOrm struct {
ChanceUserId int64 `orm:"column(chance_user_id)"`
SourceContent string `orm:"column(source_content)"`
ChanceEnableStatus int `orm:"column(enable_status)"`
Images string `orm:"column(images)"`
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
//ReviewStatus int `orm:"column(review_status)"`
Id int64 `orm:"column(id)"` //消息id
ReceiveUserId int64 `orm:"column(receive_user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
Message string `orm:"column(message)"`
IsRead int64 `orm:"column(isRead)"`
ChanceId int64 `orm:"column(source_id)"` // 机会id
//EnableStatus int `orm:"column(enable_status)"`
}
/*Announcement H5公告详情*/
type AnnouncementRequest struct {
Id int `json:"id" valid:"Required"`
... ...
... ... @@ -84,6 +84,56 @@ func SendApproveMsgByFormat(receiverId int64, name string, companyId int64, chan
return
}
//发送被审核消息
func SendApprovedMsg(receiverId int64, name string, companyId int64, chanceId int64, chanceTypeId int, reviewStatus int, msgType int) (err error) {
var (
chanceType *models.ChanceType
format string
)
switch reviewStatus {
case protocol.ReviewStatusAuditging:
format = MessageApproving
break
case protocol.ReviewStatusReturn:
format = MessageApproveReject
break
case protocol.ReviewStatusPass:
format = MessageApproveSuccess
break
default:
format = MessageApproving
break
}
if chanceType, err = models.GetChanceTypeById(chanceTypeId); err != nil {
return
}
format = fmt.Sprintf(format, chanceType.Name)
return SendMsg(receiverId, name, companyId, chanceId, protocol.SourceTypeChance, format, msgType)
}
//发送消息
func SendMsg(receiverId int64, name string, companyId int64, sourceId int64, sourceType int, message string, msgType int) (err error) {
var (
userMsg *models.UserMsg
)
userMsg = &models.UserMsg{
Id: idgen.Next(),
CompanyId: companyId,
ReceiveUserId: receiverId,
MsgType: msgType,
Message: message,
SourceId: sourceId,
SourceType: sourceType,
IsPublic: 0,
CreateAt: time.Now(),
}
if _, err = models.AddUserMsg(userMsg); err != nil {
return
}
logMsg(userMsg, name)
return
}
//打印消息日志
func logMsg(msg *models.UserMsg, name string) {
log.Info(fmt.Sprintf("发送消息 消息类型:%v Receiver:%v(%v) Message:%v SourceId:%v SourceType:%v",
... ...
... ... @@ -10,6 +10,7 @@ import (
"opp/internal/utils"
"opp/models"
"opp/protocol"
"opp/services/agg"
"time"
)
... ... @@ -182,6 +183,46 @@ func MsgCompanyNotice(header *protocol.RequestHeader, request *protocol.MsgCompa
return
}
//消息中心-机会审核消息
func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanceApproveRequest) (rsp *protocol.MsgChanceApproveResponse, err error) {
var (
myChances []protocol.MsgChanceApproveItemOrm
total int
provider *protocol.BaseUserInfo
)
if total, err = models.GetChanceMsg(header.UserId, header.CompanyId, request.LastId, request.PageSize, protocol.MsgTypeAudit, &myChances); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
if provider, err = agg.GetUserBaseInfo(header.UserId, header.CompanyId); err != nil {
log.Error(err)
return
}
rsp = &protocol.MsgChanceApproveResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
commItem := protocol.CommonListItem{}
item := protocol.ChanceItem{
Id: chance.Id,
Provider: provider,
//CreateTime: chance.CreateTime.Unix() * 1000,
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
utils.JsonUnmarshal(chance.Voices, &item.Speechs)
utils.JsonUnmarshal(chance.Videos, &item.Videos)
{
commItem.Chance = item
}
rsp.List = append(rsp.List, commItem)
}
return
}
//H5公告详情
func H5Announcement(header *protocol.RequestHeader, request *protocol.AnnouncementRequest) (rsp *protocol.AnnouncementResponse, err error) {
var (
... ...