作者 yangfu

点赞人

@@ -105,9 +105,9 @@ func DeleteUserMsg(id int64) (err error) { @@ -105,9 +105,9 @@ func DeleteUserMsg(id int64) (err error) {
105 func GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error) { 105 func GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error) {
106 o := orm.NewOrm() 106 o := orm.NewOrm()
107 sql := `select COUNT(*) as total,msg_type from user_msg 107 sql := `select COUNT(*) as total,msg_type from user_msg
108 -where (msg_type & ?)>0 and receive_user_id = ? and is_public=1 and is_read=0 and company_id=? 108 +where (msg_type & ?)>0 and receive_user_id = ? and is_read=0 and company_id=?
109 GROUP BY msg_type` 109 GROUP BY msg_type`
110 - if _, err = o.Raw(sql, msgType, userId, companyId).QueryRows(v); err == nil { 110 + if err = utils.ExecuteQueryAllWithOrmer(o, v, sql, msgType, userId, companyId); err == nil {
111 return 111 return
112 } 112 }
113 return 113 return
@@ -15,9 +15,43 @@ import ( @@ -15,9 +15,43 @@ import (
15 ) 15 )
16 16
17 func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCenterRequest) (rsp *protocol.MessageCenterResponse, err error) { 17 func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCenterRequest) (rsp *protocol.MessageCenterResponse, err error) {
18 - var () 18 + var (
  19 + list []*protocol.MessageTotal
  20 + interactionCount int
  21 + )
19 rsp = &protocol.MessageCenterResponse{} 22 rsp = &protocol.MessageCenterResponse{}
  23 + if request.MsgType&protocol.MsgTypeInteraction > 0 {
  24 + if request.MsgType&protocol.MsgTypeThumbUp == 0 {
  25 + request.MsgType |= protocol.MsgTypeThumbUp
  26 + }
  27 + if request.MsgType&protocol.MsgTypeComment == 0 {
  28 + request.MsgType |= protocol.MsgTypeComment
  29 + }
  30 + if request.MsgType&protocol.MsgTypeAuditBy == 0 {
  31 + request.MsgType |= protocol.MsgTypeAuditBy
  32 + }
  33 + }
20 err = models.GetUserMsgTotals(header.UserId, header.CompanyId, request.MsgType, &rsp.Totals) 34 err = models.GetUserMsgTotals(header.UserId, header.CompanyId, request.MsgType, &rsp.Totals)
  35 + for i := range rsp.Totals {
  36 + item := rsp.Totals[i]
  37 + if item.MsgType == protocol.MsgTypeThumbUp {
  38 + interactionCount += item.MsgTotal
  39 + continue
  40 + }
  41 + if item.MsgType == protocol.MsgTypeComment {
  42 + interactionCount += item.MsgTotal
  43 + continue
  44 + }
  45 + if item.MsgType == protocol.MsgTypeAuditBy {
  46 + interactionCount += item.MsgTotal
  47 + continue
  48 + }
  49 + list = append(list, item)
  50 + }
  51 + if interactionCount > 0 {
  52 + list = append(list, &protocol.MessageTotal{MsgType: protocol.MsgTypeInteraction, MsgTotal: interactionCount})
  53 + }
  54 + rsp.Totals = list
21 return 55 return
22 } 56 }
23 57