作者 yangfu

增加 评论 点赞 消息中心

@@ -12,7 +12,7 @@ type ChanceController struct { @@ -12,7 +12,7 @@ type ChanceController struct {
12 controllers.BaseController 12 controllers.BaseController
13 } 13 }
14 14
15 -//IComment 15 +//IComment 我来评论
16 // @router /iComment [post] 16 // @router /iComment [post]
17 func (this *ChanceController) IComment() { 17 func (this *ChanceController) IComment() {
18 var msg *protocol.ResponseMessage 18 var msg *protocol.ResponseMessage
@@ -54,7 +54,7 @@ func (this *ChanceController) IComments() { @@ -54,7 +54,7 @@ func (this *ChanceController) IComments() {
54 msg = protocol.NewReturnResponse(chance.IComments(header, request)) 54 msg = protocol.NewReturnResponse(chance.IComments(header, request))
55 } 55 }
56 56
57 -//Comments 57 +//Comments 评论列表
58 // @router /comments [post] 58 // @router /comments [post]
59 func (this *ChanceController) Comments() { 59 func (this *ChanceController) Comments() {
60 var msg *protocol.ResponseMessage 60 var msg *protocol.ResponseMessage
@@ -139,7 +139,7 @@ func (this *ChanceController) CommentDetailsMulti() { @@ -139,7 +139,7 @@ func (this *ChanceController) CommentDetailsMulti() {
139 msg = protocol.NewReturnResponse(chance.CommentDetailsMulti(header, request)) 139 msg = protocol.NewReturnResponse(chance.CommentDetailsMulti(header, request))
140 } 140 }
141 141
142 -//SympathyAction 142 +//SympathyAction 机会点赞/收藏
143 //@router /sympathyAction [post] 143 //@router /sympathyAction [post]
144 func (this *ChanceController) SympathyAction() { 144 func (this *ChanceController) SympathyAction() {
145 var msg *protocol.ResponseMessage 145 var msg *protocol.ResponseMessage
@@ -12,7 +12,7 @@ type MessageController struct { @@ -12,7 +12,7 @@ type MessageController struct {
12 controllers.BaseController 12 controllers.BaseController
13 } 13 }
14 14
15 -//MessageCenter 15 +//MessageCenter 消息中心
16 // @router /messageCenter [post] 16 // @router /messageCenter [post]
17 func (this *MessageController) MessageCenter() { 17 func (this *MessageController) MessageCenter() {
18 var msg *protocol.ResponseMessage 18 var msg *protocol.ResponseMessage
@@ -40,6 +40,8 @@ const ( @@ -40,6 +40,8 @@ const (
40 SqlUserMsgUnRead = "select * from user_msg where source_id=? and company_id=? and receive_user_id=? and msg_type=? and is_read=0 order by create_at desc" //特定未读消息 40 SqlUserMsgUnRead = "select * from user_msg where source_id=? and company_id=? and receive_user_id=? and msg_type=? and is_read=0 order by create_at desc" //特定未读消息
41 //用户消息 - 按 1.源id 2.接收者id 3.消息类型 41 //用户消息 - 按 1.源id 2.接收者id 3.消息类型
42 SqlUserMsg = "select * from user_msg where source_id=? and receive_user_id=? and msg_type=? " //特定未读消息 42 SqlUserMsg = "select * from user_msg where source_id=? and receive_user_id=? and msg_type=? " //特定未读消息
  43 + //删除消息
  44 + SqlDeleteUserMsg = "delete from user_msg where source_id=? and source_type=? and receive_user_id=? and msg_type=? " //特定未读消息
43 ) 45 )
44 46
45 func (t *UserMsg) TableName() string { 47 func (t *UserMsg) TableName() string {
@@ -115,7 +117,7 @@ GROUP BY msg_type` @@ -115,7 +117,7 @@ GROUP BY msg_type`
115 func UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) { 117 func UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) {
116 o := orm.NewOrm() 118 o := orm.NewOrm()
117 sql := `update user_msg set is_read = 1 119 sql := `update user_msg set is_read = 1
118 - where receive_user_id = ? and company_id=? and is_public=1 ` 120 + where receive_user_id = ? and company_id=? `
119 if msgType > 0 { 121 if msgType > 0 {
120 sql += fmt.Sprintf(" and (msg_type & %v)>0", msgType) 122 sql += fmt.Sprintf(" and (msg_type & %v)>0", msgType)
121 } 123 }
@@ -69,10 +69,10 @@ type FavoriteResponse struct { @@ -69,10 +69,10 @@ type FavoriteResponse struct {
69 69
70 /*SympathyAction 点赞,收藏*/ 70 /*SympathyAction 点赞,收藏*/
71 type SympathyActionRequest struct { 71 type SympathyActionRequest struct {
72 - MarkType int `json:"mark_type" valid:"Required"` // 1.赞 2.收藏  
73 - SourceType int `json:"source_type" valid:"Required"` //protocol.SourceType //机会 评论  
74 - Id int64 `json:"id" valid:"Required"`  
75 - SympathyType int `json:"sympathy_type"` //1:标记 0:取消标记 72 + MarkType int `json:"markType" valid:"Required"` // 1.赞 2.收藏
  73 + SourceType int `json:"sourceType" valid:"Required"` //protocol.SourceType //1.机会 2.评论
  74 + Id int64 `json:"id" valid:"Required"` //机会编号 / 评论编号
  75 + SympathyType int `json:"sympathyType"` //1:标记 0:取消标记
76 } 76 }
77 type SympathyActionResponse struct { 77 type SympathyActionResponse struct {
78 } 78 }
@@ -347,21 +347,21 @@ type ChanceTotalItem struct { @@ -347,21 +347,21 @@ type ChanceTotalItem struct {
347 347
348 //机会列表 通用项 348 //机会列表 通用项
349 type CommonListItem struct { 349 type CommonListItem struct {
350 - Chance ChanceItem `json:"chance,omitempty"` //机会详情  
351 - ChanceData interface{} `json:"chanceData,omitempty"` //机会数据(是否收藏/点赞 浏览数 点赞总数 评论数)ChanceData  
352 - Approve interface{} `json:"approve,omitempty"` //审核人 审核信息(时间) Approve  
353 - ApproveData interface{} `json:"approveData,omitempty"` //审核数据(公开状态 评分) ApproveData  
354 - Message interface{} `json:"message,omitempty"` //消息  
355 - Comment interface{} `json:"comment,omitempty"` //评论  
356 - ChanceStatus int `json:"chanceStatus"` //0:正常 1.删除 2.关闭  
357 - ReviewStatus int `json:"reviewStatus"` //审核状态  
358 - 350 + Chance ChanceItem `json:"chance,omitempty"` //机会详情
  351 + ChanceData interface{} `json:"statisticData,omitempty"` //机会数据(是否收藏/点赞 浏览数 点赞总数 评论数)ChanceData
  352 + Approve interface{} `json:"approve,omitempty"` //审核人 审核信息(时间) Approve
  353 + ApproveData interface{} `json:"approveData,omitempty"` //审核数据(公开状态 评分) ApproveData
  354 + Message interface{} `json:"message,omitempty"` //消息
  355 + Comment interface{} `json:"comment,omitempty"` //评论
359 //我审核的-通过 356 //我审核的-通过
360 Score interface{} `json:"score,omitempty"` 357 Score interface{} `json:"score,omitempty"`
361 358
362 //模板 359 //模板
363 ChanceType interface{} `json:"chanceType,omitempty"` //机会类型 360 ChanceType interface{} `json:"chanceType,omitempty"` //机会类型
364 ChanceTemplate interface{} `json:"template,omitempty"` //机会模板 361 ChanceTemplate interface{} `json:"template,omitempty"` //机会模板
  362 +
  363 + ChanceStatus int `json:"chanceStatus"` //0:正常 1.删除 2.关闭
  364 + ReviewStatus int `json:"reviewStatus"` //审核状态
365 } 365 }
366 type ChanceItem struct { 366 type ChanceItem struct {
367 Id int64 `json:"id"` 367 Id int64 `json:"id"`
@@ -375,8 +375,8 @@ type ChanceItem struct { @@ -375,8 +375,8 @@ type ChanceItem struct {
375 type ChanceData struct { 375 type ChanceData struct {
376 ThumbsUpTotal int `json:"thumbsupTotal"` //点赞总数 376 ThumbsUpTotal int `json:"thumbsupTotal"` //点赞总数
377 CommentTotal int `json:"commentTotal"` //评论总数 377 CommentTotal int `json:"commentTotal"` //评论总数
378 - PageViewTotal int `json:"pageView"` //评论总数 378 + PageViewTotal int `json:"pageViewTotal"` //评论总数
379 379
380 - IsThumbsUp bool `json:"thumbsup"` //是否点赞 1 点赞, 0 没有点赞  
381 - IsCollect bool `json:"isCollect"` //是否收藏 1 是 0 否 380 + IsThumbsUp bool `json:"isThumbsUp"` //是否点赞 1 点赞, 0 没有点赞
  381 + IsCollect bool `json:"isCollect"` //是否收藏 1 是 0 否
382 } 382 }
@@ -9,7 +9,7 @@ const ( @@ -9,7 +9,7 @@ const (
9 /*IComment */ 9 /*IComment */
10 type ICommentRequest struct { 10 type ICommentRequest struct {
11 Content string `json:"content" valid:"Required"` 11 Content string `json:"content" valid:"Required"`
12 - SourceType int `json:"type" valid:"Required"` 12 + SourceType int `json:"type" valid:"Required"` //1.机会 2:评论
13 Id int64 `json:"id" valid:"Required"` 13 Id int64 `json:"id" valid:"Required"`
14 } 14 }
15 type ICommentResponse struct { 15 type ICommentResponse struct {
@@ -42,20 +42,21 @@ type CommentsRequest struct { @@ -42,20 +42,21 @@ type CommentsRequest struct {
42 SourceType int 42 SourceType int
43 } 43 }
44 type CommentsResponse struct { 44 type CommentsResponse struct {
45 - Total int `json:"total"`  
46 Comments []*Comments `json:"comments"` 45 Comments []*Comments `json:"comments"`
  46 + Total int `json:"total"`
47 } 47 }
48 48
49 /*评论列表*/ 49 /*评论列表*/
50 type Comments struct { 50 type Comments struct {
51 - Id int64 `json:"id"`  
52 - Provider *BaseUserInfo `json:"provider"`  
53 - Content string `json:"content"`  
54 - ViewTotal int `json:"pageView"`  
55 - CommentTotal int `json:"commentTotal"`  
56 - ZanTotal int `json:"zanTotal"`  
57 - CreateTime int64 `json:"createTime"`  
58 - IsZan int `json:"is_zan"` //0:未点赞 1:点赞 51 + Id int64 `json:"id"`
  52 + CreateTime int64 `json:"createTime"`
  53 + Content string `json:"content"`
  54 + Provider *BaseUserInfo `json:"provider"`
  55 +
  56 + ViewTotal int `json:"pageViewTotal"`
  57 + CommentTotal int `json:"commentTotal"`
  58 + ZanTotal int `json:"thumbsupTotal"`
  59 + IsZan int `json:"isThumbsUp"` //0:未点赞 1:点赞
59 } 60 }
60 61
61 /*CommentDetailsMulti */ 62 /*CommentDetailsMulti */
@@ -45,6 +45,9 @@ var errmessge ErrorMap = map[int]string{ @@ -45,6 +45,9 @@ var errmessge ErrorMap = map[int]string{
45 45
46 //模板相关 46 //模板相关
47 5301: "机会模板不存在", 47 5301: "机会模板不存在",
  48 +
  49 + //消息相关
  50 + 5401: "消息不存在",
48 } 51 }
49 52
50 const ( 53 const (
@@ -61,6 +64,9 @@ var ( @@ -61,6 +64,9 @@ var (
61 MessageApproving = "提交了一条%v机会消息,需要您审核" 64 MessageApproving = "提交了一条%v机会消息,需要您审核"
62 MessageApproveSuccess = "审核通过你提交的%v机会" 65 MessageApproveSuccess = "审核通过你提交的%v机会"
63 MessageApproveReject = "退回您了提交的%v机会" 66 MessageApproveReject = "退回您了提交的%v机会"
  67 +
  68 + MessageZanChance = "点赞了您发布的机会"
  69 + MessageZanComment = "点赞了您发布的评论"
64 ) 70 )
65 71
66 /*MessageCenter */ 72 /*MessageCenter */
@@ -2,8 +2,10 @@ package agg @@ -2,8 +2,10 @@ package agg
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "github.com/astaxie/beego/orm"
5 "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen" 6 "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
6 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  8 + "opp/internal/utils"
7 "opp/models" 9 "opp/models"
8 "opp/protocol" 10 "opp/protocol"
9 "time" 11 "time"
@@ -134,6 +136,16 @@ func SendMsg(receiverId int64, name string, companyId int64, sourceId int64, sou @@ -134,6 +136,16 @@ func SendMsg(receiverId int64, name string, companyId int64, sourceId int64, sou
134 return 136 return
135 } 137 }
136 138
  139 +//删除已发送的消息
  140 +func DeleteSendedMsg(sourceId int64, sourceType int, receiverId int64, msgType int) (err error) {
  141 + o := orm.NewOrm()
  142 + log.Info(fmt.Sprintf("删除消息 接收者:%v 来源编号:%v 来源类型:%v 消息类型:%v", receiverId, sourceId, sourceType, msgType))
  143 + if err = utils.ExecuteSQLWithOrmer(o, models.SqlDeleteUserMsg, sourceId, sourceType, receiverId, msgType); err != nil {
  144 + log.Error(err)
  145 + }
  146 + return
  147 +}
  148 +
137 //打印消息日志 149 //打印消息日志
138 func logMsg(msg *models.UserMsg, name string) { 150 func logMsg(msg *models.UserMsg, name string) {
139 log.Info(fmt.Sprintf("发送消息 消息类型:%v Receiver:%v(%v) Message:%v SourceId:%v SourceType:%v", 151 log.Info(fmt.Sprintf("发送消息 消息类型:%v Receiver:%v(%v) Message:%v SourceId:%v SourceType:%v",
@@ -65,6 +65,7 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc @@ -65,6 +65,7 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc
65 chanceType int 65 chanceType int
66 incre int = 1 66 incre int = 1
67 table string = "comment" 67 table string = "comment"
  68 + message string = protocol.MessageZanComment
68 ) 69 )
69 rsp = &protocol.SympathyActionResponse{} 70 rsp = &protocol.SympathyActionResponse{}
70 if chanceFavoirte, err = models.GetChanceFavorite(header.Uid, header.CompanyId, request.Id, request.SourceType); err != nil && err != orm.ErrNoRows { 71 if chanceFavoirte, err = models.GetChanceFavorite(header.Uid, header.CompanyId, request.Id, request.SourceType); err != nil && err != orm.ErrNoRows {
@@ -72,6 +73,7 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc @@ -72,6 +73,7 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc
72 return 73 return
73 } 74 }
74 if request.SourceType == protocol.SourceTypeChance { 75 if request.SourceType == protocol.SourceTypeChance {
  76 + message = protocol.MessageZanChance
75 if chance, err = models.GetChanceById(request.Id); err != nil { 77 if chance, err = models.GetChanceById(request.Id); err != nil {
76 log.Error("机会不存在", err) 78 log.Error("机会不存在", err)
77 return 79 return
@@ -134,6 +136,11 @@ END: @@ -134,6 +136,11 @@ END:
134 } 136 }
135 if request.SympathyType == protocol.UnMarkFlag { 137 if request.SympathyType == protocol.UnMarkFlag {
136 incre = -1 138 incre = -1
  139 + //删除点赞消息
  140 + agg.DeleteSendedMsg(chance.Id, protocol.SourceTypeChance, chance.UserId, protocol.MsgTypeThumbUp)
  141 + } else {
  142 + //发送点赞消息
  143 + agg.SendMsg(chance.UserId, fmt.Sprintf("%v", chance.UserId), chance.CompanyId, chance.Id, 1, message, protocol.MsgTypeThumbUp)
137 } 144 }
138 if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSql(table, "zan_total", incre, request.Id)) { 145 if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSql(table, "zan_total", incre, request.Id)) {
139 // 146 //
@@ -998,6 +1005,7 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail @@ -998,6 +1005,7 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail
998 approveProcess *protocol.ChanceApproveProcessResponse 1005 approveProcess *protocol.ChanceApproveProcessResponse
999 //chanceType *models.ChanceType 1006 //chanceType *models.ChanceType
1000 //tempalte *models.AuditTemplate 1007 //tempalte *models.AuditTemplate
  1008 + table string = "chance"
1001 ) 1009 )
1002 rsp = &protocol.ChanceDetailResponse{} 1010 rsp = &protocol.ChanceDetailResponse{}
1003 if chance, err = models.GetChanceById(request.Id); err != nil { 1011 if chance, err = models.GetChanceById(request.Id); err != nil {
@@ -1024,6 +1032,11 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail @@ -1024,6 +1032,11 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail
1024 err = protocol.NewErrWithMessage(5101) 1032 err = protocol.NewErrWithMessage(5101)
1025 return 1033 return
1026 } 1034 }
  1035 + if chance.ReviewStatus == protocol.ReviewStatusPass {
  1036 + if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSql(table, "view_total", 1, request.Id)) {
  1037 + //
  1038 + }
  1039 + }
1027 //用户信息 1040 //用户信息
1028 if provider, err = agg.GetUserBaseInfo(chance.UserId, header.CompanyId); err != nil { 1041 if provider, err = agg.GetUserBaseInfo(chance.UserId, header.CompanyId); err != nil {
1029 log.Error(err) 1042 log.Error(err)
@@ -60,7 +60,7 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest) @@ -60,7 +60,7 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest)
60 rsp = &protocol.ICommentResponse{ 60 rsp = &protocol.ICommentResponse{
61 Id: newComment.Id, 61 Id: newComment.Id,
62 Content: newComment.Content, 62 Content: newComment.Content,
63 - CreateTime: newComment.CreateAt.Unix(), 63 + CreateTime: newComment.CreateAt.Unix() * 1000,
64 Provider: baseUserInfo, 64 Provider: baseUserInfo,
65 } 65 }
66 return 66 return
@@ -128,7 +128,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest) @@ -128,7 +128,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest)
128 Id: comment.Id, 128 Id: comment.Id,
129 Provider: baseUserInfo, 129 Provider: baseUserInfo,
130 Content: comment.Content, 130 Content: comment.Content,
131 - CreateTime: comment.CreateAt.Unix(), 131 + CreateTime: comment.CreateAt.Unix() * 1000,
132 ViewTotal: comment.ViewTotal, 132 ViewTotal: comment.ViewTotal,
133 ZanTotal: comment.ZanTotal, 133 ZanTotal: comment.ZanTotal,
134 CommentTotal: comment.CommentTotal, 134 CommentTotal: comment.CommentTotal,
@@ -23,8 +23,18 @@ func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCent @@ -23,8 +23,18 @@ func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCent
23 23
24 //标记已读 24 //标记已读
25 func MsgCenterRead(header *protocol.RequestHeader, request *protocol.MsgCenterReadRequest) (rsp *protocol.MsgCenterReadResponse, err error) { 25 func MsgCenterRead(header *protocol.RequestHeader, request *protocol.MsgCenterReadRequest) (rsp *protocol.MsgCenterReadResponse, err error) {
26 - var ()  
27 - //rsp =&protocol.MsgCenterReadResponse{} 26 + var (
  27 + msg *models.UserMsg
  28 + )
  29 + rsp = &protocol.MsgCenterReadResponse{}
  30 + if msg, err = models.GetUserMsgById(request.MsgId); err != nil {
  31 + log.Error(err)
  32 + err = protocol.NewErrWithMessage(5401)
  33 + return
  34 + }
  35 + if msg.IsRead == 1 {
  36 + return
  37 + }
28 err = models.UpdateUserMsgSetRead(header.Uid, header.CompanyId, request.MsgType, request.MsgId) 38 err = models.UpdateUserMsgSetRead(header.Uid, header.CompanyId, request.MsgType, request.MsgId)
29 if err != nil { 39 if err != nil {
30 log.Error(err) 40 log.Error(err)
@@ -35,6 +45,7 @@ func MsgCenterRead(header *protocol.RequestHeader, request *protocol.MsgCenterRe @@ -35,6 +45,7 @@ func MsgCenterRead(header *protocol.RequestHeader, request *protocol.MsgCenterRe
35 //标记全部已读 45 //标记全部已读
36 func MsgCenterAllRead(header *protocol.RequestHeader, request *protocol.MsgCenterAllReadRequest) (rsp *protocol.MsgCenterAllReadResponse, err error) { 46 func MsgCenterAllRead(header *protocol.RequestHeader, request *protocol.MsgCenterAllReadRequest) (rsp *protocol.MsgCenterAllReadResponse, err error) {
37 var () 47 var ()
  48 + rsp = &protocol.MsgCenterAllReadResponse{}
38 err = models.UpdateUserMsgSetRead(header.Uid, header.CompanyId, request.MsgType, 0) 49 err = models.UpdateUserMsgSetRead(header.Uid, header.CompanyId, request.MsgType, 0)
39 if err != nil { 50 if err != nil {
40 log.Error(err) 51 log.Error(err)
@@ -299,7 +310,10 @@ func H5Announcement(header *protocol.RequestHeader, request *protocol.Announceme @@ -299,7 +310,10 @@ func H5Announcement(header *protocol.RequestHeader, request *protocol.Announceme
299 return 310 return
300 } 311 }
301 if userMsg.IsRead == 0 { //判断是否可以置为 已读 312 if userMsg.IsRead == 0 { //判断是否可以置为 已读
302 - if bulletin.AllowClose == 2 && bulletin != nil && bulletin.Id != 0 { 313 + //if bulletin.AllowClose == 2 && bulletin != nil && bulletin.Id != 0 {
  314 + // setRead = true
  315 + //}
  316 + if bulletin.AllowClose == 0 {
303 setRead = true 317 setRead = true
304 } 318 }
305 } 319 }