diff --git a/api/consts/option.go b/api/consts/option.go index b34b0a08..dbbd057b 100644 --- a/api/consts/option.go +++ b/api/consts/option.go @@ -11,10 +11,9 @@ const ( ) const ( - AccountPunishment_BlockFromCreatingMoment = 0 // 禁止发贴 - AccountPunishment_BlockFromCreatingFreeZoneMoment = 0 // 禁止发免费空间贴 - AccountPunishment_BlockFromCreatingIronfanVisibleZoneMoment = 0 // 禁止发铁粉空间贴 - AccountPunishment_BlockFromCreatingSuperfanVisibleZoneMoment = 0 // 禁止发超粉空间贴 + AccountPunishment_BlockFromCreatingMoment = 0 // 禁止发贴 + AccountPunishment_BlockFromCreatingFreeZoneMoment = 0 // 禁止发免费空间贴 + AccountPunishment_BlockFromCreatingPaidZoneMoment = 0 // 禁止发付费空间贴 ) const ( diff --git a/api/consts/status.go b/api/consts/status.go index 2491ecbc..253740e6 100644 --- a/api/consts/status.go +++ b/api/consts/status.go @@ -157,6 +157,12 @@ const ( IsSuperfanshipUnlocked_Yes = 1 //是 ) +// 铁粉是否可以免费看 +const ( + IsIronfanVisible_No = 0 //否 + IsIronfanVisible_Yes = 1 //是 +) + // 是否解锁动态 const ( IsZoneMomentUnlocked_No = 0 //否 @@ -170,7 +176,7 @@ const ( MomentManuallyReview_Rejected = 2 //已复审拒绝 ) -// 私密动态表audit_status状态 +// 私密动态表status const ( ZoneMoment_Auditing = 0 //机审中 ZoneMoment_ManuallyReviewing = 1 //人工复审中 @@ -178,11 +184,10 @@ const ( ZoneMoment_Private = 3 //自见 ) -// 私密动态表status状态 +// 私密动态表c_type const ( - ZoneMoment_Free = 0 //免费 - ZoneMoment_IronfanVisible = 1 //铁粉可见 - ZoneMoment_SuperfanVisible = 2 //超粉可见 + ZoneMomentCType_Free = 0 //免费 + ZoneMomentCType_Paid = 1 //付费 ) // 私密动态人工复审 diff --git a/api/proto/zonemoment/proto/not_null_def_api.go b/api/proto/zonemoment/proto/not_null_def_api.go index 4ccfa2c3..f36d3cf4 100644 --- a/api/proto/zonemoment/proto/not_null_def_api.go +++ b/api/proto/zonemoment/proto/not_null_def_api.go @@ -16,15 +16,11 @@ func (p *ApiCreateReq) ProvideNotNullValue() (params []*validator.JsonParam) { params = append(params, validator.NewStructPtrParam("请确认创建动态的媒体!", p.MediaComp)) switch util.DerefInt64(p.ZoneMoment.CType) { - case consts.ZoneMoment_IronfanVisible: + case consts.ZoneMomentCType_Paid: params = append(params, validator.NewInt64PtrParam("请确认创建动态的文字可见范围!", p.ZoneMoment.TextVisibleRange)) params = append(params, validator.NewInt64PtrParam("请确认创建动态的媒体可见范围!", p.ZoneMoment.MediaVisibleRange)) params = append(params, validator.NewInt64PtrParam("请确认创建动态的价格!", p.ZoneMoment.Price)) - case consts.ZoneMoment_SuperfanVisible: - params = append(params, validator.NewInt64PtrParam("请确认创建动态的文字可见范围!", p.ZoneMoment.TextVisibleRange)) - params = append(params, validator.NewInt64PtrParam("请确认创建动态的媒体可见范围!", p.ZoneMoment.MediaVisibleRange)) } - return } diff --git a/api/proto/zonemoment/proto/zonemoment_api.go b/api/proto/zonemoment/proto/zonemoment_api.go index 7c524d25..2c6f625d 100644 --- a/api/proto/zonemoment/proto/zonemoment_api.go +++ b/api/proto/zonemoment/proto/zonemoment_api.go @@ -47,7 +47,7 @@ type ApiUpdateResp struct { Data *ApiUpdateData `json:"data"` } -// op 列表 +// op 列表-访客 type ApiListByVisitorMidReq struct { base.BaseRequest CtUpperBound *int64 `json:"ct_upper_bound"` //创建时间上界,闭区间 @@ -67,6 +67,26 @@ type ApiListByVisitorMidResp struct { Data *ApiListByVisitorMidData `json:"data"` } +// op 列表-创建人 +type ApiListByCreaterMidReq struct { + base.BaseRequest + CtUpperBound *int64 `json:"ct_upper_bound"` //创建时间上界,闭区间 + CtLowerBound *int64 `json:"ct_lower_bound"` //创建时间下界,开区间,可为0 + Offset int `json:"offset"` + Limit int `json:"limit"` +} + +type ApiListByCreaterMidData struct { + List []*ApiZoneMomentVO `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` +} + +type ApiListByCreaterMidResp struct { + base.BaseResponse + Data *ApiListByCreaterMidData `json:"data"` +} + // op 点赞 type ApiZoneMomentThumbsUpReq struct { base.BaseRequest diff --git a/api/proto/zonemoment/proto/zonemoment_op.go b/api/proto/zonemoment/proto/zonemoment_op.go index 02472bb3..99376826 100644 --- a/api/proto/zonemoment/proto/zonemoment_op.go +++ b/api/proto/zonemoment/proto/zonemoment_op.go @@ -68,6 +68,26 @@ type OpListResp struct { Data *OpListData `json:"data"` } +// op 列表 +type OpListByMidReq struct { + base.BaseRequest + CtUpperBound *int64 `json:"ct_upper_bound"` //创建时间上界,闭区间 + CtLowerBound *int64 `json:"ct_lower_bound"` //创建时间下界,开区间,可为0 + Offset int `json:"offset"` + Limit int `json:"limit"` +} + +type OpListByMidData struct { + List []*dbstruct.ZoneMoment `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` +} + +type OpListByMidResp struct { + base.BaseResponse + Data *OpListByMidData `json:"data"` +} + // op 按zids查询 type OpListByZidsReq struct { base.BaseRequest diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index d6063947..4d321433 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -214,10 +214,12 @@ func Init(r *gin.Engine) { // 私密圈动态 apiZoneMomentGroup := r.Group("/api/zone_moment", PrepareToC()) - apiZoneMomentGroup.POST("create", middleware.JSONParamValidator(zonemomentproto.OpCreateReq{}), middleware.JwtAuthenticator(), ApiCreateZoneMoment) - apiZoneMomentGroup.POST("update", middleware.JSONParamValidator(zonemomentproto.OpUpdateReq{}), middleware.JwtAuthenticator(), ApiUpdateZoneMoment) - apiZoneMomentGroup.POST("delete", middleware.JSONParamValidator(zonemomentproto.OpDeleteReq{}), middleware.JwtAuthenticator(), ApiDeleteZoneMoment) - apiZoneMomentGroup.POST("list_by_visitor_mid", middleware.JSONParamValidator(zonemomentproto.OpListReq{}), middleware.JwtAuthenticator(), ApiGetZoneMomentListByVisitorMid) + apiZoneMomentGroup.POST("create", middleware.JSONParamValidator(zonemomentproto.ApiCreateReq{}), middleware.JwtAuthenticator(), ApiCreateZoneMoment) + apiZoneMomentGroup.POST("update", middleware.JSONParamValidator(zonemomentproto.ApiUpdateReq{}), middleware.JwtAuthenticator(), ApiUpdateZoneMoment) + apiZoneMomentGroup.POST("delete", middleware.JSONParamValidator(zonemomentproto.ApiDeleteReq{}), middleware.JwtAuthenticator(), ApiDeleteZoneMoment) + apiZoneMomentGroup.POST("list_by_visitor_mid", middleware.JSONParamValidator(zonemomentproto.ApiListByVisitorMidReq{}), middleware.JwtAuthenticator(), ApiGetZoneMomentListByVisitorMid) + apiZoneMomentGroup.POST("list_by_creater_mid", middleware.JSONParamValidator(zonemomentproto.ApiListByCreaterMidReq{}), middleware.JwtAuthenticator(), ApiGetZoneMomentListByCreaterMid) + apiZoneMomentGroup.POST("thumbs_up", middleware.JSONParamValidator(zonemomentproto.ApiZoneMomentThumbsUpReq{}), middleware.JwtAuthenticator(), ApiZoneMomentThumbsUpMoment) // =============================== 以下是服务,只允许内网调用 =============================== diff --git a/app/mix/controller/zonemoment_api.go b/app/mix/controller/zonemoment_api.go index 9814f81f..b1c70545 100644 --- a/app/mix/controller/zonemoment_api.go +++ b/app/mix/controller/zonemoment_api.go @@ -60,7 +60,7 @@ func ApiGetZoneMomentListByVisitorMid(ctx *gin.Context) { req.Limit = consts.DefaultPageSize } - list, ec := service.DefaultService.ApiGetZoneMomentList(ctx, req) + list, ec := service.DefaultService.ApiGetZoneMomentListByVisitorMid(ctx, req) if ec != errcode.ErrCodeZoneMomentSrvOk { logger.Error("ApiGetZoneMomentList fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) @@ -77,6 +77,31 @@ func ApiGetZoneMomentListByVisitorMid(ctx *gin.Context) { ReplyOk(ctx, data) } +func ApiGetZoneMomentListByCreaterMid(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*zonemomentproto.ApiListByCreaterMidReq) + + //设置默认页长 + if req.Limit == 0 { + req.Limit = consts.DefaultPageSize + } + + list, ec := service.DefaultService.ApiGetZoneMomentListByCreaterMid(ctx, req) + if ec != errcode.ErrCodeZoneMomentSrvOk { + logger.Error("ApiGetZoneMomentList fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + data := &zonemomentproto.ApiListByCreaterMidData{ + List: list, + Offset: req.Offset + len(list), + } + if len(list) >= req.Limit { + data.More = 1 + } + ReplyOk(ctx, data) +} + func ApiZoneMomentThumbsUpMoment(ctx *gin.Context) { req := ctx.MustGet("client_req").(*zonemomentproto.ApiZoneMomentThumbsUpReq) ec := service.DefaultService.ApiZoneMomentThumbsUpMoment(ctx, req) diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index 681c537c..86d14489 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -3909,8 +3909,33 @@ func (m *Mongo) GetZoneMomentListByZids(ctx *gin.Context, req *zonemomentproto.O "zid": qmgo.M{ "$in": req.Zids, }, - "audit_status": consts.ZoneMoment_Public, - "del_flag": 0, + "status": consts.ZoneMoment_Public, + "del_flag": 0, + } + ctClause := qmgo.M{} + if req.CtLowerBound != nil { + ctClause["$gt"] = util.DerefInt64(req.CtLowerBound) + } + if req.CtUpperBound != nil { + ctClause["$lte"] = util.DerefInt64(req.CtUpperBound) + } + if len(ctClause) != 0 { + query["ct"] = ctClause + } + err := col.Find(ctx, query).Sort("-ct").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) + if err == qmgo.ErrNoSuchDocuments { + err = nil + return list, err + } + return list, err +} + +func (m *Mongo) GetZoneMomentListByMid(ctx *gin.Context, req *zonemomentproto.OpListByMidReq) ([]*dbstruct.ZoneMoment, error) { + list := make([]*dbstruct.ZoneMoment, 0) + col := m.getColZoneMoment() + query := qmgo.M{ + "mid": req.GetBaseRequest().Mid, + "del_flag": 0, } ctClause := qmgo.M{} if req.CtLowerBound != nil { diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index fbbc6642..d8d9ca91 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -2203,7 +2203,7 @@ func (s *Service) ApiDeleteZoneMoment(ctx *gin.Context, id int64) (ec errcode.Er return } -func (s *Service) ApiGetZoneMomentList(ctx *gin.Context, req *zonemomentproto.ApiListByVisitorMidReq) (volist []*zonemomentproto.ApiZoneMomentVO, ec errcode.ErrCode) { +func (s *Service) ApiGetZoneMomentListByVisitorMid(ctx *gin.Context, req *zonemomentproto.ApiListByVisitorMidReq) (volist []*zonemomentproto.ApiZoneMomentVO, ec errcode.ErrCode) { ec = errcode.ErrCodeZoneMomentSrvOk // 1.查询访客关注的空间 @@ -2287,6 +2287,44 @@ func (s *Service) ApiGetZoneMomentList(ctx *gin.Context, req *zonemomentproto.Ap return } +func (s *Service) ApiGetZoneMomentListByCreaterMid(ctx *gin.Context, req *zonemomentproto.ApiListByCreaterMidReq) (volist []*zonemomentproto.ApiZoneMomentVO, ec errcode.ErrCode) { + ec = errcode.ErrCodeZoneMomentSrvOk + + // 1.根据关注的zids查询得到这一轮的动态基底 + list, err := _DefaultZoneMoment.OpListByMid(ctx, &zonemomentproto.OpListByMidReq{ + CtUpperBound: req.CtUpperBound, + CtLowerBound: req.CtLowerBound, + Offset: req.Offset, + Limit: req.Limit, + }) + if err != nil { + logger.Error("ApiGetZoneMomentList fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneMomentSrvFail + return + } + + // 2.通过mid获取主播信息map + streamerExtMap, err := s.utilGetStreamerExtMapByMids(ctx, []int64{req.GetBaseRequest().Mid}, consts.InterfaceType_Api) + if err != nil { + logger.Error("utilGetStreamerExtMapByMids fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeStreamerSrvFail + return + } + streamerExt := streamerExtMap[req.GetBaseRequest().Mid] + + // 3.填充所有信息 + for _, zonemoment := range list { + vo := &zonemomentproto.ApiZoneMomentVO{ + ZoneMoment: zonemoment, + } + // 主播信息 + vo.CopyStreamerExt(streamerExt) + volist = append(volist, vo) + } + + return +} + func (s *Service) ApiZoneMomentThumbsUpMoment(ctx *gin.Context, req *zonemomentproto.ApiZoneMomentThumbsUpReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeZoneMomentSrvOk diff --git a/app/mix/service/apiservice_business_validation.go b/app/mix/service/apiservice_business_validation.go index ce9b8dbe..b0298036 100644 --- a/app/mix/service/apiservice_business_validation.go +++ b/app/mix/service/apiservice_business_validation.go @@ -549,12 +549,10 @@ func (s *Service) ApiCreateZoneMomentBusinessValidate(ctx *gin.Context, req *zon pType := int64(0) switch util.DerefInt64(req.ZoneMoment.CType) { - case consts.ZoneMoment_Free: + case consts.ZoneMomentCType_Free: pType = consts.AccountPunishment_BlockFromCreatingFreeZoneMoment - case consts.ZoneMoment_IronfanVisible: - pType = consts.AccountPunishment_BlockFromCreatingIronfanVisibleZoneMoment - case consts.ZoneMoment_SuperfanVisible: - pType = consts.AccountPunishment_BlockFromCreatingSuperfanVisibleZoneMoment + case consts.ZoneMomentCType_Paid: + pType = consts.AccountPunishment_BlockFromCreatingPaidZoneMoment } resultList := businessvalidator.NewAuthBusinessValidator(ctx, req). diff --git a/app/mix/service/business_validator/auth.go b/app/mix/service/business_validator/auth.go index 333b82e3..d1b6ffb9 100644 --- a/app/mix/service/business_validator/auth.go +++ b/app/mix/service/business_validator/auth.go @@ -302,23 +302,24 @@ func (l *AuthBusinessValidator) EnsureMomentCreateTimesNotReachedDailyUpperbound func (l *AuthBusinessValidator) EnsureAmongZoneMomentsPaidItemsLessThanFreeItems(fun func(*gin.Context, int64, int64) (int64, error), mid int64) *AuthBusinessValidator { l.oplist = append(l.oplist, func() { - // 动态数 - freeCount, err1 := fun(l.ctx, mid, consts.ZoneMoment_Free) + // 免费动态数 + freeCount, err1 := fun(l.ctx, mid, consts.ZoneMomentCType_Free) if err1 != nil { logger.Error("Query free zone moment count failed, err: %v", err1) l.ec = errcode.ErrCodeZoneMomentSrvFail return } - productCount, err2 := fun(l.ctx, mid, consts.ZoneMoment_Free) + // 付费动态数 + paidCount, err2 := fun(l.ctx, mid, consts.ZoneMomentCType_Paid) if err2 != nil { - logger.Error("Query product zone moment count failed, err: %v", err2) + logger.Error("Query paid zone moment count failed, err: %v", err2) l.ec = errcode.ErrCodeZoneMomentSrvFail return } - if productCount >= freeCount { - logger.Error("the product zone moment create times of this mid has reached its upperbound") + if paidCount >= freeCount { + logger.Error("the paid zone moment create times of this mid has reached its upperbound") l.ec = errcode.ErrCodePaidZoneMomentCreateTimesReachedUpperbound return } diff --git a/app/mix/service/logic/zonemoment.go b/app/mix/service/logic/zonemoment.go index 08858e58..b5d1dc03 100644 --- a/app/mix/service/logic/zonemoment.go +++ b/app/mix/service/logic/zonemoment.go @@ -80,6 +80,15 @@ func (p *ZoneMoment) OpListByZids(ctx *gin.Context, req *zonemomentproto.OpListB return list, nil } +func (p *ZoneMoment) OpListByMid(ctx *gin.Context, req *zonemomentproto.OpListByMidReq) ([]*dbstruct.ZoneMoment, error) { + list, err := p.store.GetZoneMomentListByMid(ctx, req) + if err != nil { + logger.Error("GetZoneMomentListByMid fail, err: %v", err) + return make([]*dbstruct.ZoneMoment, 0), err + } + return list, nil +} + func (p *ZoneMoment) OpZoneMomentThumbsUp(ctx *gin.Context, req *zonemomentproto.OpZoneMomentThumbsUpReq) (err error) { //更新Moment中的点赞个数 err = p.store.ThumbsUpZoneMoment(ctx, req) diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index 75768eb1..a20df5f1 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -988,23 +988,18 @@ func (s *Service) utilEncryptInaccessibleZoneMoment(vo *zonemomentproto.ApiZoneM // 填充动态是否解锁 func (s *Service) utilFillIsZoneMomentUnlocked(vo *zonemomentproto.ApiZoneMomentVO) { switch util.DerefInt64(vo.ZoneMoment.Status) { - case consts.ZoneMoment_Free: + case consts.ZoneMomentCType_Free: vo.SetIsZoneMomentUnlocked(consts.IsZoneMomentUnlocked_Yes) - case consts.ZoneMoment_IronfanVisible: - if vo.IsSuperfanshipUnlocked == consts.IsIronfanshipUnlocked_Yes || vo.IsIronfanshipUnlocked == consts.IsIronfanshipUnlocked_Yes { + case consts.ZoneMomentCType_Paid: + if vo.IsSuperfanshipUnlocked == consts.IsIronfanshipUnlocked_Yes { + vo.SetIsZoneMomentUnlocked(consts.IsZoneMomentUnlocked_Yes) + } else if util.DerefInt64(vo.IsIronfanVisible) == consts.IsIronfanVisible_Yes && vo.IsIronfanshipUnlocked == consts.IsIronfanshipUnlocked_Yes { vo.SetIsZoneMomentUnlocked(consts.IsZoneMomentUnlocked_Yes) } else { // 是否已购买该条动态 vo.SetIsZoneMomentUnlocked(consts.IsZoneMomentUnlocked_No) s.utilEncryptInaccessibleZoneMoment(vo) } - case consts.ZoneMoment_SuperfanVisible: - if vo.IsSuperfanshipUnlocked == consts.IsIronfanshipUnlocked_Yes { - vo.SetIsZoneMomentUnlocked(consts.IsZoneMomentUnlocked_Yes) - } else { - vo.SetIsZoneMomentUnlocked(consts.IsZoneMomentUnlocked_No) - s.utilEncryptInaccessibleZoneMoment(vo) - } } } diff --git a/dbstruct/zonemoment.go b/dbstruct/zonemoment.go index a7772933..aa2ff14e 100644 --- a/dbstruct/zonemoment.go +++ b/dbstruct/zonemoment.go @@ -6,10 +6,11 @@ type ZoneMoment struct { Id *int64 `json:"id" bson:"_id"` // 私密圈动态表id Mid *int64 `json:"mid" bson:"mid"` // 用户表id Zid *int64 `json:"zid" bson:"zid"` // 所属空间id - CType *int64 `json:"c_type" bson:"c_type"` // 动态付费类型,0-免费贴,1-铁粉贴,2-超粉贴 + CType *int64 `json:"c_type" bson:"c_type"` // 动态付费类型,0-免费贴,1-付费贴 + IsIronfanVisible *int64 `json:"is_ironfan_visible" bson:"is_ironfan_visible"` // 铁粉是否可以免费看 Text *string `json:"text" bson:"text"` // 动态文字内容 MediaComp *MediaComponent `json:"media_comp" bson:"media_comp"` // 动态媒体内容 - MType *int64 `json:"m_type"` // 媒体类型,见: MediaType* + MType *int64 `json:"m_type" bson:"m_type"` // 媒体类型,见: MediaType* TextVisibleRange *int64 `json:"text_visible_range" bson:"text_visible_range"` // 动态文字可见范围,单位行 MediaVisibleRange *int64 `json:"media_visible_range" bson:"media_visible_range"` // 动态媒体可见范围,单位媒体个数 TextAmount *int64 `json:"text_amount" bson:"text_amount"` // 动态文字总行