作者 yangfu

点赞列表

... ... @@ -72,10 +72,31 @@ func (this *ChanceController) Comments() {
return
}
header := controllers.GetRequestHeader(this.Ctx)
request.SourceType = protocol.SourceTypeChance
//request.SourceType = protocol.SourceTypeChance
msg = protocol.NewReturnResponse(chance.Comments(header, request))
}
//Thumbsups 点赞列表
// @router /thumbsups [post]
func (this *ChanceController) Thumbsups() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ThumbsupsRequest
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(chance.Thumbsups(header, request))
}
//Favorite
// @router /favorite [post]
func (this *ChanceController) Favorite() {
... ...
... ... @@ -200,3 +200,45 @@ func (this *MessageController) MsgChanceSubmit() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(message.MsgChanceSubmit(header, request))
}
//MsgChanceComment 消息中心-互动消息.评论
//@router /msgChanceComment [post]
func (this *MessageController) MsgChanceComment() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.MsgChanceCommentRequest
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.MsgChanceComment(header, request))
}
//MsgChanceThumbUp 消息中心-互动消息.点赞
//@router /msgChanceThumbUp [post]
func (this *MessageController) MsgChanceThumbUp() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.MsgChanceThumbUpRequest
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.MsgChanceThumbUp(header, request))
}
... ...
... ... @@ -81,12 +81,12 @@ func DeleteChanceFavorite(id int64) (err error) {
//按1.用户id 2.公司id 3.标记类型 4.机会类型编号 5.最后编号 6.页数
//获取用户点赞收藏机会
func GetChanceFavorites(userId, companyId int64, markFlag, chanceType int, lastId int64, pageSize int) (v []*ChanceFavorite, total int, err error) {
func GetChanceFavorites(userId, companyId int64, markFlag, sourceType int, lastId int64, pageSize int) (v []*ChanceFavorite, total int, err error) {
sql := mybeego.NewSqlExutor().Table("chance_favorite").Order("create_at desc")
sql.Where(fmt.Sprintf("user_id=%d", userId))
sql.Where(fmt.Sprintf("company_id=%d", companyId))
if chanceType > 0 {
sql.Where(fmt.Sprintf("chance_type=%d", chanceType))
if sourceType > 0 {
sql.Where(fmt.Sprintf("source_type=%d", sourceType))
}
if markFlag > 0 {
sql.Where(fmt.Sprintf("mark_flag&%d>0", markFlag))
... ...
... ... @@ -199,3 +199,29 @@ from user_msg where receive_user_id=? and source_type=1 and msg_type=? `
}
return
}
//获取机会评论消息
func GetChanceCommentMsg(uid, lastId int64, pageSize int, msgType int, v interface{}) (total int, err error) {
sql := `select a.*,b.content commented_content,b.create_at commented_time,b.user_id commented_user_id from (
select a.*,b.images,b.speechs,b.videos from (
select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status from (
select id,message content,source_type,source_id,create_at comment_time from user_msg
where receive_user_id =? and (?=0 or id>?) and msg_type=?
)a left outer join chance b on a.source_id = b.id and source_type=1
)a left outer join chance_data b on a.source_id = b.chance_id and source_type = 1
)a left outer join comment b on a.source_id = b.id and a.source_type=2
order by create_at 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
}
... ...
... ... @@ -308,10 +308,6 @@ type ChanceCommentItemOrm struct {
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
//ApproveData string `json:"approveData"` //审核数据
//TemplateId int `orm:"column(audit_template_id)"`
//ChanceTypeId int `orm:"column(chance_type_id)"`
CommentTotal int `orm:"column(comment_total)"`
ZanTotal int `orm:"column(zan_total)"`
ViewTotal int `orm:"column(view_total)"`
... ... @@ -425,6 +421,20 @@ type Form struct {
Required int8 `json:"required"`
}
//清楚未填写的表单数据
func ClearEmptyForm(inputFormList []*Form) (FormList []*Form) {
if len(inputFormList) == 0 {
return
}
for i := range inputFormList {
item := inputFormList[i]
if len(item.Value) > 0 {
FormList = append(FormList, item)
}
}
return
}
//语音
type Speech struct {
Path string `json:"path"`
... ... @@ -508,6 +518,7 @@ type CollectData struct {
//点赞数据
type ThumbUpData struct {
Id int64 `json:"id"`
Content string `json:"content"` //点赞内容
ThumbUpTime int64 `json:"thumbUpTime"` //收藏时间
}
... ...
... ... @@ -39,13 +39,25 @@ type CommentsRequest struct {
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
SourceId int64 `json:"id" valid:"Required"`
SourceType int
SourceType int `json:"sourceType" valid:"Required"` //1:机会 2:评论
}
type CommentsResponse struct {
Comments []*Comments `json:"comments"`
Total int `json:"total"`
}
/*Thumbsups 点赞列表*/
type ThumbsupsRequest struct {
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
SourceId int64 `json:"id" valid:"Required"`
SourceType int `json:"sourceType" valid:"Required"` //1:机会 2:评论
}
type ThumbsupsResponse struct {
Thumbups []*Thumbups `json:"thumbups"`
Total int `json:"total"`
}
/*评论列表*/
type Comments struct {
Id int64 `json:"id"`
... ... @@ -59,6 +71,12 @@ type Comments struct {
IsZan int `json:"isThumbsUp"` //0:未点赞 1:点赞
}
type Thumbups struct {
Id int64 `json:"id"`
CreateTime int64 `json:"createTime"`
Provider *BaseUserInfo `json:"provider"`
}
/*CommentDetailsMulti */
type CommentDetailsMultiRequest struct {
SourceId int64 `json:"cid"`
... ...
... ... @@ -42,6 +42,7 @@ var errmessge ErrorMap = map[int]string{
5203: "审批服务器操作失败",
5204: "评分或者公开状态不能为空",
5205: "机会未审核通过,不能修改评分或者公开状态",
5206: "未找到审批节点或者无权限",
//模板相关
5301: "机会模板不存在",
... ... @@ -223,6 +224,26 @@ type MsgChanceSubmitResponse struct {
Total int `json:"total"`
}
/*MsgChanceComment 消息中心-互动消息.评论*/
type MsgChanceCommentRequest struct {
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
}
type MsgChanceCommentResponse struct {
List []CommonListItem `json:"list"`
Total int `json:"total"`
}
/*MsgChanceThumbUp 息中心-互动消息.点赞*/
type MsgChanceThumbUpRequest struct {
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
}
type MsgChanceThumbUpResponse struct {
List []CommonListItem `json:"list"`
Total int `json:"total"`
}
//我的审核机会列表
type MsgChanceApproveItemOrm struct {
ChanceUserId int64 `orm:"column(chance_user_id)"`
... ...
... ... @@ -247,6 +247,14 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "Thumbsups",
Router: `/thumbsups`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:CommendController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:CommendController"],
beego.ControllerComments{
Method: "Company",
... ... @@ -321,6 +329,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgChanceComment",
Router: `/msgChanceComment`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgChanceSubmit",
Router: `/msgChanceSubmit`,
AllowHTTPMethods: []string{"post"},
... ... @@ -329,6 +345,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgChanceThumbUp",
Router: `/msgChanceThumbUp`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgCompanyNotice",
Router: `/msgCompanyNotice`,
AllowHTTPMethods: []string{"post"},
... ...
... ... @@ -298,7 +298,7 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
}
if process, err = models.GetAuditFlowProcessBy(request.ProcessId, header.UserId); err != nil {
log.Error(request.ProcessId, header.UserId, err)
err = protocol.NewErrWithMessage(5202)
err = protocol.NewErrWithMessage(5206)
return
}
if chance.ReviewStatus != protocol.ReviewStatusAuditging {
... ...
... ... @@ -2,6 +2,7 @@ package chance
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"
... ... @@ -19,6 +20,8 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest)
chance *models.Chance
updateTable interface{}
updateMap = make(map[string]interface{})
recevierId int64
sourceId int64
)
switch request.SourceType {
case protocol.SourceTypeChance:
... ... @@ -28,15 +31,22 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest)
}
updateTable = chance
updateMap["CommentTotal"] = chance.CommentTotal + 1
recevierId = chance.UserId
sourceId = chance.Id
break
case protocol.SourceTypeComment:
if comment, err = models.GetCommentById(request.Id); err != nil {
log.Error(err)
return
}
updateTable = comment
recevierId = comment.UserId
sourceId = comment.Id
updateMap["CommentTotal"] = comment.CommentTotal + 1
break
default:
err = fmt.Errorf("unknow source_type:%v", request.SourceType)
return
}
newComment := &models.Comment{
Id: idgen.Next(),
... ... @@ -46,8 +56,11 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest)
CreateAt: time.Now(),
SourceId: request.Id,
}
if _, err = models.AddComment(newComment); err != nil {
orm := orm.NewOrm()
orm.Begin()
if _, err = orm.Insert(newComment); err != nil {
log.Error(err)
orm.Rollback()
return
}
if baseUserInfo, err = agg.GetUserBaseInfo(header.Uid, header.CompanyId); err != nil {
... ... @@ -55,8 +68,18 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest)
return
}
if updateTable != nil {
utils.UpdateTableByMap(updateTable, updateMap)
if err = utils.UpdateTableByMapWithOrmer(orm, updateTable, updateMap); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
if err = agg.SendMsg(recevierId, "", header.CompanyId, sourceId, request.SourceType, request.Content, protocol.MsgTypeComment); err != nil {
log.Error(err)
orm.Rollback()
return
}
orm.Commit()
rsp = &protocol.ICommentResponse{
Id: newComment.Id,
Content: newComment.Content,
... ... @@ -141,6 +164,39 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest)
return
}
//点赞列表
func Thumbsups(header *protocol.RequestHeader, request *protocol.ThumbsupsRequest) (rsp *protocol.ThumbsupsResponse, err error) {
var (
favorites []*models.ChanceFavorite
total int
baseUserInfo *protocol.BaseUserInfo
)
rsp = &protocol.ThumbsupsResponse{}
if favorites, total, err = models.GetChanceFavorites(header.UserId, header.CompanyId, protocol.MarkFlagZan, request.SourceType, request.LastId, request.PageSize); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
return
}
for i := range favorites {
f := favorites[i]
if baseUserInfo, err = agg.GetUserBaseInfo(f.UserId, header.CompanyId); err != nil {
log.Error(err)
//return
continue
}
item := &protocol.Thumbups{
Id: f.Id,
Provider: baseUserInfo,
CreateTime: f.CreateAt.Unix() * 1000,
}
rsp.Thumbups = append(rsp.Thumbups, item)
}
rsp.Total = total
return
}
//评论详情-不带地下评论
func CommentDetailsSingle(header *protocol.RequestHeader, request *protocol.CommentDetailsSingleRequest) (rsp *protocol.CommentDetailsSingleResponse, err error) {
var (
... ...
... ... @@ -311,6 +311,134 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance
return
}
// 消息中心-互动消息.评论
func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanceCommentRequest) (rsp *protocol.MsgChanceCommentResponse, err error) {
var (
myChances []protocol.ChanceCommentItemOrm
total int
provider *protocol.BaseUserInfo
)
if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeComment, &myChances); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
rsp = &protocol.MsgChanceCommentResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
commItem := protocol.CommonListItem{}
if chance.SourceType == protocol.SourceTypeChance {
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
} else {
if provider, err = agg.GetUserBaseInfo(header.UserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
} else {
item := protocol.ChanceItem{
Id: chance.SourceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = protocol.ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
utils.JsonUnmarshal(chance.Voices, &item.Speechs)
utils.JsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
}
commItem.ReviewStatus = chance.ReviewStatus
}
if chance.SourceType == protocol.SourceTypeComment {
commItem.CommentedData = protocol.CommentData{
Id: chance.SourceId,
Content: chance.CommentedContent,
CommentTime: chance.CommentedTime.Unix() * 1000,
}
}
commItem.CommentData = protocol.CommentData{
Id: chance.CommentId,
CommentTime: chance.CommentTime.Unix() * 1000,
Content: chance.CommentContent,
}
commItem.SourceType = chance.SourceType
rsp.List = append(rsp.List, commItem)
}
return
}
//消息中心-互动消息.点赞
func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanceThumbUpRequest) (rsp *protocol.MsgChanceThumbUpResponse, err error) {
var (
myChances []protocol.ChanceCommentItemOrm
total int
provider *protocol.BaseUserInfo
)
if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeThumbUp, &myChances); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
rsp = &protocol.MsgChanceThumbUpResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
commItem := protocol.CommonListItem{}
if chance.SourceType == protocol.SourceTypeChance {
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
} else {
if provider, err = agg.GetUserBaseInfo(header.UserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
} else {
item := protocol.ChanceItem{
Id: chance.SourceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = protocol.ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
utils.JsonUnmarshal(chance.Voices, &item.Speechs)
utils.JsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
}
commItem.ReviewStatus = chance.ReviewStatus
}
if chance.SourceType == protocol.SourceTypeComment {
commItem.CommentedData = protocol.CommentData{
Id: chance.SourceId,
Content: chance.CommentedContent,
CommentTime: chance.CommentedTime.Unix() * 1000,
}
}
commItem.ThumbUpData = protocol.ThumbUpData{
Id: chance.CommentId,
ThumbUpTime: chance.CommentTime.Unix() * 1000,
Content: chance.CommentContent,
}
commItem.SourceType = chance.SourceType
rsp.List = append(rsp.List, commItem)
}
return
}
//H5公告详情
func H5Announcement(header *protocol.RequestHeader, request *protocol.AnnouncementRequest) (rsp *protocol.AnnouncementResponse, err error) {
var (
... ...