diff --git a/app/mix/controller/contact_customer_service_session_api.go b/app/mix/controller/contact_customer_service_session_api.go index 4eebc656..638e4657 100644 --- a/app/mix/controller/contact_customer_service_session_api.go +++ b/app/mix/controller/contact_customer_service_session_api.go @@ -40,3 +40,18 @@ func ApiGetContactCustomerServiceSessionListByMid(ctx *gin.Context) { } ReplyOk(ctx, data) } + +func ApiGetUnreadContactCustomerServiceCountByMid(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*contact_customer_service_sessionproto.ApiCountUnreadByMidReq) + unreadCount, ec := service.DefaultService.ApiGetUnreadContactCustomerServiceCountByMid(ctx, req) + if ec != errcode.ErrCodeContactCustomerServiceSessionSrvOk { + logger.Error("ApiGetUnreadContactCustomerServiceCountByMid fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + data := &contact_customer_service_sessionproto.ApiCountUnreadByMidData{ + UnreadCount: unreadCount, + } + ReplyOk(ctx, data) +} diff --git a/app/mix/controller/contact_customer_service_session_op.go b/app/mix/controller/contact_customer_service_session_op.go index 925c1873..0117e820 100644 --- a/app/mix/controller/contact_customer_service_session_op.go +++ b/app/mix/controller/contact_customer_service_session_op.go @@ -70,3 +70,18 @@ func OpGetContactCustomerServiceSessionList(ctx *gin.Context) { } ReplyOk(ctx, data) } + +func OpGetUnreadContactCustomerServiceCountByMid(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*contact_customer_service_sessionproto.OpCountUnreadByMidReq) + unreadCount, ec := service.DefaultService.OpGetUnreadContactCustomerServiceCountByMid(ctx, req) + if ec != errcode.ErrCodeContactCustomerServiceSessionSrvOk { + logger.Error("OpGetUnreadContactCustomerServiceCountByMid fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + data := &contact_customer_service_sessionproto.OpCountUnreadByMidData{ + UnreadCount: unreadCount, + } + ReplyOk(ctx, data) +} diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index cef2f0fb..9ee09aa4 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -207,6 +207,7 @@ func Init(r *gin.Engine) { apiContactCustomerServiceSessionGroup := r.Group("/api/contact_customer_service_session", PrepareToC()) apiContactCustomerServiceSessionGroup.POST("create", middleware.JSONParamValidator(contact_customer_service_sessionproto.ApiCreateReq{}), middleware.JwtAuthenticator(), ApiCreateContactCustomerServiceSession) apiContactCustomerServiceSessionGroup.POST("list_by_mid", middleware.JSONParamValidator(contact_customer_service_sessionproto.ApiListByMidReq{}), middleware.JwtAuthenticator(), ApiGetContactCustomerServiceSessionListByMid) + apiContactCustomerServiceSessionGroup.POST("get_unread_count_by_mid", middleware.JSONParamValidator(contact_customer_service_sessionproto.ApiCountUnreadByMidReq{}), middleware.JwtAuthenticator(), ApiGetUnreadContactCustomerServiceCountByMid) // 应用配置表 apiAppConfigGroup := r.Group("/api/app_config", PrepareToC()) @@ -507,6 +508,7 @@ func Init(r *gin.Engine) { opContactCustomerServiceSessionGroup.POST("create", middleware.JSONParamValidator(contact_customer_service_sessionproto.OpCreateReq{}), middleware.JwtAuthenticator(), OpCreateContactCustomerServiceSession) opContactCustomerServiceSessionGroup.POST("list_by_mid", middleware.JSONParamValidator(contact_customer_service_sessionproto.OpListByMidReq{}), middleware.JwtAuthenticator(), OpGetContactCustomerServiceSessionListByMid) opContactCustomerServiceSessionGroup.POST("list", middleware.JSONParamValidator(contact_customer_service_sessionproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetContactCustomerServiceSessionList) + opContactCustomerServiceSessionGroup.POST("get_unread_count", middleware.JSONParamValidator(contact_customer_service_sessionproto.OpCountUnreadByMidReq{}), middleware.JwtAuthenticator(), OpGetUnreadContactCustomerServiceCountByMid) // 图片审核任务 opImageAuditTaskGroup := r.Group("/op/image_audit_task", PrepareOp()) diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index a57f8bae..b0f05321 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -2090,7 +2090,7 @@ func (s *Service) ApiCreateContactCustomerService(ctx *gin.Context, req *contact ec = errcode.ErrCodeContactCustomerServiceCountRedisCacheInvalid return } - _, err = redis.GetRedisClient().Incr(consts.RedisContactCustomerServicePrefix + "sup_total_unread_count") + _, err = redis.GetRedisClient().Incr(consts.RedisContactCustomerServicePrefix + "from_sup_total_unread_count") if err != nil { logger.Error("Redis Incr fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeContactCustomerServiceCountRedisCacheInvalid @@ -2254,6 +2254,15 @@ func (s *Service) ApiGetContactCustomerServiceSessionListByMid(ctx *gin.Context, return } +func (s *Service) ApiGetUnreadContactCustomerServiceCountByMid(ctx *gin.Context, req *contact_customer_service_sessionproto.ApiCountUnreadByMidReq) (unreadCount int64, ec errcode.ErrCode) { + ec = errcode.ErrCodeContactCustomerServiceSessionSrvOk + + key := logic.GetCreateContactCustomerServiceCountIdForRedis(util.DerefInt64(req.SessionId), consts.ContactCustomerService_FromSupportor) + unreadCount, _ = redis.GetRedisClient().GetInt64(key) + + return +} + // Moment func (s *Service) ApiCreateMoment(ctx *gin.Context, req *momentproto.ApiCreateReq) (ec errcode.ErrCode, acctPunEndTime string) { ec = errcode.ErrCodeMomentSrvOk diff --git a/app/mix/service/service.go b/app/mix/service/service.go index cb71b989..5405c7d1 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -3160,7 +3160,7 @@ func (s *Service) OpUpdateContactCustomerServiceByIds(ctx *gin.Context, req *con } } // 去掉总量 - _, err = redis.GetRedisClient().DecrBy(consts.RedisContactCustomerServicePrefix+"sup_total_unread_count", int64(len(req.Ids))) + _, err = redis.GetRedisClient().DecrBy(consts.RedisContactCustomerServicePrefix+"from_sup_total_unread_count", int64(len(req.Ids))) if err != nil { logger.Error("Redis DecrBy fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeContactCustomerServiceCountRedisCacheInvalid @@ -3673,6 +3673,19 @@ func (s *Service) OpGetContactCustomerServiceSessionList(ctx *gin.Context, req * return } +func (s *Service) OpGetUnreadContactCustomerServiceCountByMid(ctx *gin.Context, req *contact_customer_service_sessionproto.OpCountUnreadByMidReq) (unreadCount int64, ec errcode.ErrCode) { + ec = errcode.ErrCodeContactCustomerServiceSessionSrvOk + + if req.SessionId != nil { + key := logic.GetCreateContactCustomerServiceCountIdForRedis(util.DerefInt64(req.SessionId), consts.ContactCustomerService_FromUser) + unreadCount, _ = redis.GetRedisClient().GetInt64(key) + } else { + unreadCount, _ = redis.GetRedisClient().GetInt64(consts.RedisContactCustomerServicePrefix + "from_sup_total_unread_count") + } + + return +} + // DailyStatement func (s *Service) OpGetDailyStatementList(ctx *gin.Context, req *daily_statementproto.OpListReq) (list []*dbstruct.DailyStatement, ec errcode.ErrCode) { ec = errcode.ErrCodeDailyStatementSrvOk