作者 yangfu

增加 评论 点赞 消息中心

... ... @@ -12,7 +12,7 @@ type ChanceController struct {
controllers.BaseController
}
//IComment
//IComment 我来评论
// @router /iComment [post]
func (this *ChanceController) IComment() {
var msg *protocol.ResponseMessage
... ... @@ -54,7 +54,7 @@ func (this *ChanceController) IComments() {
msg = protocol.NewReturnResponse(chance.IComments(header, request))
}
//Comments
//Comments 评论列表
// @router /comments [post]
func (this *ChanceController) Comments() {
var msg *protocol.ResponseMessage
... ... @@ -139,7 +139,7 @@ func (this *ChanceController) CommentDetailsMulti() {
msg = protocol.NewReturnResponse(chance.CommentDetailsMulti(header, request))
}
//SympathyAction
//SympathyAction 机会点赞/收藏
//@router /sympathyAction [post]
func (this *ChanceController) SympathyAction() {
var msg *protocol.ResponseMessage
... ...
... ... @@ -12,7 +12,7 @@ type MessageController struct {
controllers.BaseController
}
//MessageCenter
//MessageCenter 消息中心
// @router /messageCenter [post]
func (this *MessageController) MessageCenter() {
var msg *protocol.ResponseMessage
... ...
... ... @@ -40,6 +40,8 @@ const (
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" //特定未读消息
//用户消息 - 按 1.源id 2.接收者id 3.消息类型
SqlUserMsg = "select * from user_msg where source_id=? and receive_user_id=? and msg_type=? " //特定未读消息
//删除消息
SqlDeleteUserMsg = "delete from user_msg where source_id=? and source_type=? and receive_user_id=? and msg_type=? " //特定未读消息
)
func (t *UserMsg) TableName() string {
... ... @@ -115,7 +117,7 @@ GROUP BY msg_type`
func UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) {
o := orm.NewOrm()
sql := `update user_msg set is_read = 1
where receive_user_id = ? and company_id=? and is_public=1 `
where receive_user_id = ? and company_id=? `
if msgType > 0 {
sql += fmt.Sprintf(" and (msg_type & %v)>0", msgType)
}
... ...
... ... @@ -69,10 +69,10 @@ type FavoriteResponse struct {
/*SympathyAction 点赞,收藏*/
type SympathyActionRequest struct {
MarkType int `json:"mark_type" valid:"Required"` // 1.赞 2.收藏
SourceType int `json:"source_type" valid:"Required"` //protocol.SourceType //机会 评论
Id int64 `json:"id" valid:"Required"`
SympathyType int `json:"sympathy_type"` //1:标记 0:取消标记
MarkType int `json:"markType" valid:"Required"` // 1.赞 2.收藏
SourceType int `json:"sourceType" valid:"Required"` //protocol.SourceType //1.机会 2.评论
Id int64 `json:"id" valid:"Required"` //机会编号 / 评论编号
SympathyType int `json:"sympathyType"` //1:标记 0:取消标记
}
type SympathyActionResponse struct {
}
... ... @@ -347,21 +347,21 @@ type ChanceTotalItem struct {
//机会列表 通用项
type CommonListItem struct {
Chance ChanceItem `json:"chance,omitempty"` //机会详情
ChanceData interface{} `json:"chanceData,omitempty"` //机会数据(是否收藏/点赞 浏览数 点赞总数 评论数)ChanceData
Approve interface{} `json:"approve,omitempty"` //审核人 审核信息(时间) Approve
ApproveData interface{} `json:"approveData,omitempty"` //审核数据(公开状态 评分) ApproveData
Message interface{} `json:"message,omitempty"` //消息
Comment interface{} `json:"comment,omitempty"` //评论
ChanceStatus int `json:"chanceStatus"` //0:正常 1.删除 2.关闭
ReviewStatus int `json:"reviewStatus"` //审核状态
Chance ChanceItem `json:"chance,omitempty"` //机会详情
ChanceData interface{} `json:"statisticData,omitempty"` //机会数据(是否收藏/点赞 浏览数 点赞总数 评论数)ChanceData
Approve interface{} `json:"approve,omitempty"` //审核人 审核信息(时间) Approve
ApproveData interface{} `json:"approveData,omitempty"` //审核数据(公开状态 评分) ApproveData
Message interface{} `json:"message,omitempty"` //消息
Comment interface{} `json:"comment,omitempty"` //评论
//我审核的-通过
Score interface{} `json:"score,omitempty"`
//模板
ChanceType interface{} `json:"chanceType,omitempty"` //机会类型
ChanceTemplate interface{} `json:"template,omitempty"` //机会模板
ChanceStatus int `json:"chanceStatus"` //0:正常 1.删除 2.关闭
ReviewStatus int `json:"reviewStatus"` //审核状态
}
type ChanceItem struct {
Id int64 `json:"id"`
... ... @@ -375,8 +375,8 @@ type ChanceItem struct {
type ChanceData struct {
ThumbsUpTotal int `json:"thumbsupTotal"` //点赞总数
CommentTotal int `json:"commentTotal"` //评论总数
PageViewTotal int `json:"pageView"` //评论总数
PageViewTotal int `json:"pageViewTotal"` //评论总数
IsThumbsUp bool `json:"thumbsup"` //是否点赞 1 点赞, 0 没有点赞
IsCollect bool `json:"isCollect"` //是否收藏 1 是 0 否
IsThumbsUp bool `json:"isThumbsUp"` //是否点赞 1 点赞, 0 没有点赞
IsCollect bool `json:"isCollect"` //是否收藏 1 是 0 否
}
... ...
... ... @@ -9,7 +9,7 @@ const (
/*IComment */
type ICommentRequest struct {
Content string `json:"content" valid:"Required"`
SourceType int `json:"type" valid:"Required"`
SourceType int `json:"type" valid:"Required"` //1.机会 2:评论
Id int64 `json:"id" valid:"Required"`
}
type ICommentResponse struct {
... ... @@ -42,20 +42,21 @@ type CommentsRequest struct {
SourceType int
}
type CommentsResponse struct {
Total int `json:"total"`
Comments []*Comments `json:"comments"`
Total int `json:"total"`
}
/*评论列表*/
type Comments struct {
Id int64 `json:"id"`
Provider *BaseUserInfo `json:"provider"`
Content string `json:"content"`
ViewTotal int `json:"pageView"`
CommentTotal int `json:"commentTotal"`
ZanTotal int `json:"zanTotal"`
CreateTime int64 `json:"createTime"`
IsZan int `json:"is_zan"` //0:未点赞 1:点赞
Id int64 `json:"id"`
CreateTime int64 `json:"createTime"`
Content string `json:"content"`
Provider *BaseUserInfo `json:"provider"`
ViewTotal int `json:"pageViewTotal"`
CommentTotal int `json:"commentTotal"`
ZanTotal int `json:"thumbsupTotal"`
IsZan int `json:"isThumbsUp"` //0:未点赞 1:点赞
}
/*CommentDetailsMulti */
... ...
... ... @@ -45,6 +45,9 @@ var errmessge ErrorMap = map[int]string{
//模板相关
5301: "机会模板不存在",
//消息相关
5401: "消息不存在",
}
const (
... ... @@ -61,6 +64,9 @@ var (
MessageApproving = "提交了一条%v机会消息,需要您审核"
MessageApproveSuccess = "审核通过你提交的%v机会"
MessageApproveReject = "退回您了提交的%v机会"
MessageZanChance = "点赞了您发布的机会"
MessageZanComment = "点赞了您发布的评论"
)
/*MessageCenter */
... ...
... ... @@ -2,8 +2,10 @@ package agg
import (
"fmt"
"github.com/astaxie/beego/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/utils"
"opp/models"
"opp/protocol"
"time"
... ... @@ -134,6 +136,16 @@ func SendMsg(receiverId int64, name string, companyId int64, sourceId int64, sou
return
}
//删除已发送的消息
func DeleteSendedMsg(sourceId int64, sourceType int, receiverId int64, msgType int) (err error) {
o := orm.NewOrm()
log.Info(fmt.Sprintf("删除消息 接收者:%v 来源编号:%v 来源类型:%v 消息类型:%v", receiverId, sourceId, sourceType, msgType))
if err = utils.ExecuteSQLWithOrmer(o, models.SqlDeleteUserMsg, sourceId, sourceType, receiverId, msgType); err != nil {
log.Error(err)
}
return
}
//打印消息日志
func logMsg(msg *models.UserMsg, name string) {
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
chanceType int
incre int = 1
table string = "comment"
message string = protocol.MessageZanComment
)
rsp = &protocol.SympathyActionResponse{}
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
return
}
if request.SourceType == protocol.SourceTypeChance {
message = protocol.MessageZanChance
if chance, err = models.GetChanceById(request.Id); err != nil {
log.Error("机会不存在", err)
return
... ... @@ -134,6 +136,11 @@ END:
}
if request.SympathyType == protocol.UnMarkFlag {
incre = -1
//删除点赞消息
agg.DeleteSendedMsg(chance.Id, protocol.SourceTypeChance, chance.UserId, protocol.MsgTypeThumbUp)
} else {
//发送点赞消息
agg.SendMsg(chance.UserId, fmt.Sprintf("%v", chance.UserId), chance.CompanyId, chance.Id, 1, message, protocol.MsgTypeThumbUp)
}
if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSql(table, "zan_total", incre, request.Id)) {
//
... ... @@ -998,6 +1005,7 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail
approveProcess *protocol.ChanceApproveProcessResponse
//chanceType *models.ChanceType
//tempalte *models.AuditTemplate
table string = "chance"
)
rsp = &protocol.ChanceDetailResponse{}
if chance, err = models.GetChanceById(request.Id); err != nil {
... ... @@ -1024,6 +1032,11 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail
err = protocol.NewErrWithMessage(5101)
return
}
if chance.ReviewStatus == protocol.ReviewStatusPass {
if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSql(table, "view_total", 1, request.Id)) {
//
}
}
//用户信息
if provider, err = agg.GetUserBaseInfo(chance.UserId, header.CompanyId); err != nil {
log.Error(err)
... ...
... ... @@ -60,7 +60,7 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest)
rsp = &protocol.ICommentResponse{
Id: newComment.Id,
Content: newComment.Content,
CreateTime: newComment.CreateAt.Unix(),
CreateTime: newComment.CreateAt.Unix() * 1000,
Provider: baseUserInfo,
}
return
... ... @@ -128,7 +128,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest)
Id: comment.Id,
Provider: baseUserInfo,
Content: comment.Content,
CreateTime: comment.CreateAt.Unix(),
CreateTime: comment.CreateAt.Unix() * 1000,
ViewTotal: comment.ViewTotal,
ZanTotal: comment.ZanTotal,
CommentTotal: comment.CommentTotal,
... ...
... ... @@ -23,8 +23,18 @@ func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCent
//标记已读
func MsgCenterRead(header *protocol.RequestHeader, request *protocol.MsgCenterReadRequest) (rsp *protocol.MsgCenterReadResponse, err error) {
var ()
//rsp =&protocol.MsgCenterReadResponse{}
var (
msg *models.UserMsg
)
rsp = &protocol.MsgCenterReadResponse{}
if msg, err = models.GetUserMsgById(request.MsgId); err != nil {
log.Error(err)
err = protocol.NewErrWithMessage(5401)
return
}
if msg.IsRead == 1 {
return
}
err = models.UpdateUserMsgSetRead(header.Uid, header.CompanyId, request.MsgType, request.MsgId)
if err != nil {
log.Error(err)
... ... @@ -35,6 +45,7 @@ func MsgCenterRead(header *protocol.RequestHeader, request *protocol.MsgCenterRe
//标记全部已读
func MsgCenterAllRead(header *protocol.RequestHeader, request *protocol.MsgCenterAllReadRequest) (rsp *protocol.MsgCenterAllReadResponse, err error) {
var ()
rsp = &protocol.MsgCenterAllReadResponse{}
err = models.UpdateUserMsgSetRead(header.Uid, header.CompanyId, request.MsgType, 0)
if err != nil {
log.Error(err)
... ... @@ -299,7 +310,10 @@ func H5Announcement(header *protocol.RequestHeader, request *protocol.Announceme
return
}
if userMsg.IsRead == 0 { //判断是否可以置为 已读
if bulletin.AllowClose == 2 && bulletin != nil && bulletin.Id != 0 {
//if bulletin.AllowClose == 2 && bulletin != nil && bulletin.Id != 0 {
// setRead = true
//}
if bulletin.AllowClose == 0 {
setRead = true
}
}
... ...