作者 yangfu

机会审核消息修改

@@ -158,3 +158,24 @@ func (this *MessageController) MsgCompanyNotice() { @@ -158,3 +158,24 @@ func (this *MessageController) MsgCompanyNotice() {
158 header := controllers.GetRequestHeader(this.Ctx) 158 header := controllers.GetRequestHeader(this.Ctx)
159 msg = protocol.NewReturnResponse(message.MsgCompanyNotice(header, request)) 159 msg = protocol.NewReturnResponse(message.MsgCompanyNotice(header, request))
160 } 160 }
  161 +
  162 +//MsgChanceApprove 机会审核消息
  163 +//@router /msgChanceApprove [post]
  164 +func (this *MessageController) MsgChanceApprove() {
  165 + var msg *protocol.ResponseMessage
  166 + defer func() {
  167 + this.Resp(msg)
  168 + }()
  169 + var request *protocol.MsgChanceApproveRequest
  170 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  171 + log.Error(err)
  172 + msg = protocol.BadRequestParam(1)
  173 + return
  174 + }
  175 + if b, m := this.Valid(request); !b {
  176 + msg = m
  177 + return
  178 + }
  179 + header := controllers.GetRequestHeader(this.Ctx)
  180 + msg = protocol.NewReturnResponse(message.MsgChanceApprove(header, request))
  181 +}
1 package utils 1 package utils
2 2
3 import ( 3 import (
  4 + "encoding/json"
4 "errors" 5 "errors"
5 "fmt" 6 "fmt"
  7 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
6 "reflect" 8 "reflect"
7 "strings" 9 "strings"
8 ) 10 )
@@ -74,3 +76,12 @@ func IsNil(i interface{}) bool { @@ -74,3 +76,12 @@ func IsNil(i interface{}) bool {
74 } 76 }
75 return false 77 return false
76 } 78 }
  79 +
  80 +func JsonUnmarshal(jsonData string, v interface{}) {
  81 + if len(jsonData) == 0 {
  82 + return
  83 + }
  84 + if e := json.Unmarshal([]byte(jsonData), v); e != nil {
  85 + log.Error("json.unmarshal error data:", jsonData, e)
  86 + }
  87 +}
@@ -173,3 +173,27 @@ func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pag @@ -173,3 +173,27 @@ func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pag
173 } 173 }
174 return 174 return
175 } 175 }
  176 +
  177 +//获取机会消息
  178 +func GetChanceMsg(uid, cid int64, lastId int64, pageSize int, msgType int, v interface{}) (total int, err error) {
  179 + sql := `select a.*,b.images,b.speechs,b.videos from (
  180 +select a.*,b.source_content,b.enable_status,b.user_id chance_user_id from (
  181 +select id,company_id,receive_user_id,message,source_id,create_time,is_read
  182 +from user_msg where receive_user_id=? and source_type=1 and (?=0 or id>?) and msg_type=?
  183 +)a left outer join chance b on a.source_id = b.id
  184 +)a left outer join chance_data b on a.source_id =b.chance_id
  185 +order by a.create_time desc
  186 +LIMIT ?`
  187 +
  188 + sqlCount := `select count(0)
  189 +from user_msg where receive_user_id=? and source_type=1 and msg_type=? `
  190 + if err = utils.ExecuteQueryOne(&total, sqlCount, uid, msgType); err != nil {
  191 + return
  192 + }
  193 + if v != nil {
  194 + if err = utils.ExecuteQueryAll(v, sql, uid, lastId, lastId, msgType, pageSize); err != nil {
  195 + return
  196 + }
  197 + }
  198 + return
  199 +}
@@ -2,6 +2,7 @@ package protocol @@ -2,6 +2,7 @@ package protocol
2 2
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
  5 + "time"
5 ) 6 )
6 7
7 var errmessge ErrorMap = map[int]string{ 8 var errmessge ErrorMap = map[int]string{
@@ -47,10 +48,13 @@ var errmessge ErrorMap = map[int]string{ @@ -47,10 +48,13 @@ var errmessge ErrorMap = map[int]string{
47 } 48 }
48 49
49 const ( 50 const (
50 - MsgTypeBulletin = 1 //公告  
51 - MsgTypeCommend = 2 //表彰  
52 - MsgTypeInteraction = 4 //互动消息  
53 - MsgTypeAudit = 8 //机会审核 51 + MsgTypeBulletin = 1 //公告
  52 + MsgTypeCommend = 2 //表彰
  53 + MsgTypeInteraction = 4 //互动消息
  54 + MsgTypeAudit = 8 //机会审核
  55 + MsgTypeAuditBy = 16 //机会被审核消息
  56 + MsgTypeComment = 32 //评论
  57 + MsgTypeThumbUp = 64 //点赞
54 ) 58 )
55 59
56 var ( 60 var (
@@ -192,6 +196,35 @@ type MsgCompanyNoticeResponse struct { @@ -192,6 +196,35 @@ type MsgCompanyNoticeResponse struct {
192 Total int `json:"total"` 196 Total int `json:"total"`
193 } 197 }
194 198
  199 +/*MsgChanceApprove 机会审核消息*/
  200 +type MsgChanceApproveRequest struct {
  201 + LastId int64 `json:"lastId"`
  202 + PageSize int `json:"pageSize" valid:"Required"`
  203 +}
  204 +type MsgChanceApproveResponse struct {
  205 + List []CommonListItem `json:"list"`
  206 + Total int `json:"total"`
  207 +}
  208 +
  209 +//我的审核机会列表
  210 +type MsgChanceApproveItemOrm struct {
  211 + ChanceUserId int64 `orm:"column(chance_user_id)"`
  212 + SourceContent string `orm:"column(source_content)"`
  213 + ChanceEnableStatus int `orm:"column(enable_status)"`
  214 + Images string `orm:"column(images)"`
  215 + Voices string `orm:"column(speechs)"`
  216 + Videos string `orm:"column(videos)"`
  217 + //ReviewStatus int `orm:"column(review_status)"`
  218 +
  219 + Id int64 `orm:"column(id)"` //消息id
  220 + ReceiveUserId int64 `orm:"column(receive_user_id)"`
  221 + CreateTime time.Time `orm:"column(create_at)"`
  222 + Message string `orm:"column(message)"`
  223 + IsRead int64 `orm:"column(isRead)"`
  224 + ChanceId int64 `orm:"column(source_id)"` // 机会id
  225 + //EnableStatus int `orm:"column(enable_status)"`
  226 +}
  227 +
195 /*Announcement H5公告详情*/ 228 /*Announcement H5公告详情*/
196 type AnnouncementRequest struct { 229 type AnnouncementRequest struct {
197 Id int `json:"id" valid:"Required"` 230 Id int `json:"id" valid:"Required"`
@@ -84,6 +84,56 @@ func SendApproveMsgByFormat(receiverId int64, name string, companyId int64, chan @@ -84,6 +84,56 @@ func SendApproveMsgByFormat(receiverId int64, name string, companyId int64, chan
84 return 84 return
85 } 85 }
86 86
  87 +//发送被审核消息
  88 +func SendApprovedMsg(receiverId int64, name string, companyId int64, chanceId int64, chanceTypeId int, reviewStatus int, msgType int) (err error) {
  89 + var (
  90 + chanceType *models.ChanceType
  91 + format string
  92 + )
  93 + switch reviewStatus {
  94 + case protocol.ReviewStatusAuditging:
  95 + format = MessageApproving
  96 + break
  97 + case protocol.ReviewStatusReturn:
  98 + format = MessageApproveReject
  99 + break
  100 + case protocol.ReviewStatusPass:
  101 + format = MessageApproveSuccess
  102 + break
  103 + default:
  104 + format = MessageApproving
  105 + break
  106 + }
  107 + if chanceType, err = models.GetChanceTypeById(chanceTypeId); err != nil {
  108 + return
  109 + }
  110 + format = fmt.Sprintf(format, chanceType.Name)
  111 + return SendMsg(receiverId, name, companyId, chanceId, protocol.SourceTypeChance, format, msgType)
  112 +}
  113 +
  114 +//发送消息
  115 +func SendMsg(receiverId int64, name string, companyId int64, sourceId int64, sourceType int, message string, msgType int) (err error) {
  116 + var (
  117 + userMsg *models.UserMsg
  118 + )
  119 + userMsg = &models.UserMsg{
  120 + Id: idgen.Next(),
  121 + CompanyId: companyId,
  122 + ReceiveUserId: receiverId,
  123 + MsgType: msgType,
  124 + Message: message,
  125 + SourceId: sourceId,
  126 + SourceType: sourceType,
  127 + IsPublic: 0,
  128 + CreateAt: time.Now(),
  129 + }
  130 + if _, err = models.AddUserMsg(userMsg); err != nil {
  131 + return
  132 + }
  133 + logMsg(userMsg, name)
  134 + return
  135 +}
  136 +
87 //打印消息日志 137 //打印消息日志
88 func logMsg(msg *models.UserMsg, name string) { 138 func logMsg(msg *models.UserMsg, name string) {
89 log.Info(fmt.Sprintf("发送消息 消息类型:%v Receiver:%v(%v) Message:%v SourceId:%v SourceType:%v", 139 log.Info(fmt.Sprintf("发送消息 消息类型:%v Receiver:%v(%v) Message:%v SourceId:%v SourceType:%v",
@@ -10,6 +10,7 @@ import ( @@ -10,6 +10,7 @@ import (
10 "opp/internal/utils" 10 "opp/internal/utils"
11 "opp/models" 11 "opp/models"
12 "opp/protocol" 12 "opp/protocol"
  13 + "opp/services/agg"
13 "time" 14 "time"
14 ) 15 )
15 16
@@ -182,6 +183,46 @@ func MsgCompanyNotice(header *protocol.RequestHeader, request *protocol.MsgCompa @@ -182,6 +183,46 @@ func MsgCompanyNotice(header *protocol.RequestHeader, request *protocol.MsgCompa
182 return 183 return
183 } 184 }
184 185
  186 +//消息中心-机会审核消息
  187 +func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanceApproveRequest) (rsp *protocol.MsgChanceApproveResponse, err error) {
  188 + var (
  189 + myChances []protocol.MsgChanceApproveItemOrm
  190 + total int
  191 + provider *protocol.BaseUserInfo
  192 + )
  193 + if total, err = models.GetChanceMsg(header.UserId, header.CompanyId, request.LastId, request.PageSize, protocol.MsgTypeAudit, &myChances); err != nil {
  194 + if err == orm.ErrNoRows {
  195 + err = nil
  196 + return
  197 + }
  198 + log.Error(err)
  199 + return
  200 + }
  201 + if provider, err = agg.GetUserBaseInfo(header.UserId, header.CompanyId); err != nil {
  202 + log.Error(err)
  203 + return
  204 + }
  205 + rsp = &protocol.MsgChanceApproveResponse{Total: total}
  206 + for i := 0; i < len(myChances); i++ {
  207 + chance := myChances[i]
  208 + commItem := protocol.CommonListItem{}
  209 + item := protocol.ChanceItem{
  210 + Id: chance.Id,
  211 + Provider: provider,
  212 + //CreateTime: chance.CreateTime.Unix() * 1000,
  213 + }
  214 + utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
  215 + utils.JsonUnmarshal(chance.Images, &item.Pictures)
  216 + utils.JsonUnmarshal(chance.Voices, &item.Speechs)
  217 + utils.JsonUnmarshal(chance.Videos, &item.Videos)
  218 + {
  219 + commItem.Chance = item
  220 + }
  221 + rsp.List = append(rsp.List, commItem)
  222 + }
  223 + return
  224 +}
  225 +
185 //H5公告详情 226 //H5公告详情
186 func H5Announcement(header *protocol.RequestHeader, request *protocol.AnnouncementRequest) (rsp *protocol.AnnouncementResponse, err error) { 227 func H5Announcement(header *protocol.RequestHeader, request *protocol.AnnouncementRequest) (rsp *protocol.AnnouncementResponse, err error) {
187 var ( 228 var (