From 4fc3732b94510ae172069f95f3d18fe3327865ab Mon Sep 17 00:00:00 2001 From: Leufolium Date: Thu, 18 Apr 2024 05:59:11 +0800 Subject: [PATCH] by Robin at 20240418 --- api/proto/zonemoment/proto/zonemoment_op.go | 9 ++--- app/mix/dao/mongo.go | 25 ++++++++++--- app/mix/service/apiservice.go | 40 ++++++++++++++++++--- app/mix/service/logic/zonemoment.go | 4 +-- dbstruct/account.go | 7 ++++ 5 files changed, 69 insertions(+), 16 deletions(-) diff --git a/api/proto/zonemoment/proto/zonemoment_op.go b/api/proto/zonemoment/proto/zonemoment_op.go index 835de296..045cf548 100644 --- a/api/proto/zonemoment/proto/zonemoment_op.go +++ b/api/proto/zonemoment/proto/zonemoment_op.go @@ -92,8 +92,9 @@ type OpListByMidResp struct { } // op 按zids查询 -type OpListByZidsReq struct { +type OpListByZidsOrMidReq struct { base.BaseRequest + Uid *int64 `json:"mid"` // mid Zids []int64 `json:"zids"` // zids MType *int64 `json:"m_type"` // 媒体类型 CType *int64 `json:"c_type"` // 付费模式 @@ -103,15 +104,15 @@ type OpListByZidsReq struct { Limit int `json:"limit"` } -type OpListByZidsData struct { +type OpListByZidsOrMidData struct { List []*dbstruct.ZoneMoment `json:"list"` Offset int `json:"offset"` More int `json:"more"` } -type OpListByZidsResp struct { +type OpListByZidsOrMidResp struct { base.BaseResponse - Data *OpListByZidsData `json:"data"` + Data *OpListByZidsOrMidData `json:"data"` } // op 列表-zid查询 diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index 09c8bd82..ff547033 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -4057,16 +4057,31 @@ func (m *Mongo) GetZoneMomentById(ctx *gin.Context, id int64) (*dbstruct.ZoneMom return zonemoment, err } -func (m *Mongo) GetZoneMomentListByZids(ctx *gin.Context, req *zonemomentproto.OpListByZidsReq) ([]*dbstruct.ZoneMoment, error) { +func (m *Mongo) GetZoneMomentListByZidsOrMid(ctx *gin.Context, req *zonemomentproto.OpListByZidsOrMidReq) ([]*dbstruct.ZoneMoment, error) { list := make([]*dbstruct.ZoneMoment, 0) col := m.getColZoneMoment() + query := qmgo.M{ - "zid": qmgo.M{ - "$in": req.Zids, - }, - "status": consts.ZoneMoment_Public, "del_flag": 0, } + if req.Uid != nil { + query["$or"] = []qmgo.M{ + { + "zid": qmgo.M{ + "$in": req.Zids, + }, + "status": consts.ZoneMoment_Public, + }, + { + "mid": util.DerefInt64(req.Uid), + }, + } + } else { + query["zid"] = qmgo.M{ + "$in": req.Zids, + } + query["status"] = consts.ZoneMoment_Public + } if req.MType != nil { query["m_type"] = util.DerefInt64(req.MType) } diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 858ea94a..68218f25 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -2269,13 +2269,27 @@ func (s *Service) ApiGetZoneListByVisitorMid(ctx *gin.Context, req *zoneproto.Ap zids = append(zids, zidZu.GetZid()) } + // 查询已解锁的空间 list, err := _DefaultZone.OpListByZids(ctx, zids) if err != nil { - logger.Error("OpListGetZoneList fail, req: %v, err: %v", util.ToJson(req), err) + logger.Error("GetZoneListByZids fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeZoneSrvFail return } + // 查询自己的空间 + ownedList, err := _DefaultZone.OpListByMid(ctx, &zoneproto.OpListByMidReq{ + Uid: goproto.Int64(req.BaseRequest.Mid), + }) + if err != nil { + logger.Error("GetZoneListByMid fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneSrvFail + return + } + if len(ownedList) > 0 { + list = append(ownedList, list...) + } + // 填充必要信息 volist, err = s.utilFillZonesWithApiVOInfo(ctx, list, req.BaseRequest.Mid, zidZuMap) if err != nil { @@ -2583,17 +2597,33 @@ func (s *Service) ApiGetZoneMomentListByVisitorMid(ctx *gin.Context, req *zonemo zids = append(zids, zidZu.GetZid()) } - // 2.根据关注的zids查询得到这一轮的动态基底 - list, err := _DefaultZoneMoment.OpListByZids(ctx, &zonemomentproto.OpListByZidsReq{ + // 2.查询该用户的角色 + account, err := _DefaultAccount.OpListByMid(ctx, &accountproto.OpListByMidReq{ + Mid: goproto.Int64(req.BaseRequest.Mid), + }) + if err != nil { + logger.Error("_DefaultAccount OpListByMid fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeAccountSrvFail + return + } + + // 3.组装查询条件,如果是主播,则Mid查询生效 + queryReq := &zonemomentproto.OpListByZidsOrMidReq{ Zids: zids, MType: req.MType, CtUpperBound: req.CtUpperBound, CtLowerBound: req.CtLowerBound, Offset: req.Offset, Limit: req.Limit, - }) + } + if account.GetRole() == consts.Streamer { + queryReq.Uid = goproto.Int64(req.BaseRequest.Mid) + } + + // 2.根据关注的zids及其mid查询得到这一轮的动态基底 + list, err := _DefaultZoneMoment.OpListByZidsOrMid(ctx, queryReq) if err != nil { - logger.Error("ApiGetZoneMomentList fail, req: %v, err: %v", util.ToJson(req), err) + logger.Error("ApiGetZoneMomentListByZidsOrMid fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeZoneMomentSrvFail return } diff --git a/app/mix/service/logic/zonemoment.go b/app/mix/service/logic/zonemoment.go index ed23fb84..6a6bd3a4 100644 --- a/app/mix/service/logic/zonemoment.go +++ b/app/mix/service/logic/zonemoment.go @@ -81,8 +81,8 @@ func (p *ZoneMoment) GetById(ctx *gin.Context, id int64) (*dbstruct.ZoneMoment, return zonemoment, nil } -func (p *ZoneMoment) OpListByZids(ctx *gin.Context, req *zonemomentproto.OpListByZidsReq) ([]*dbstruct.ZoneMoment, error) { - list, err := p.store.GetZoneMomentListByZids(ctx, req) +func (p *ZoneMoment) OpListByZidsOrMid(ctx *gin.Context, req *zonemomentproto.OpListByZidsOrMidReq) ([]*dbstruct.ZoneMoment, error) { + list, err := p.store.GetZoneMomentListByZidsOrMid(ctx, req) if err != nil { logger.Error("GetZoneMomentListByZids fail, err: %v", err) return make([]*dbstruct.ZoneMoment, 0), err diff --git a/dbstruct/account.go b/dbstruct/account.go index e8f31c26..e2962070 100644 --- a/dbstruct/account.go +++ b/dbstruct/account.go @@ -31,3 +31,10 @@ type Account struct { Ut *int64 `json:"ut" bson:"ut"` // 更新时间 DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记,0-否,1-是 } + +func (p *Account) GetRole() int64 { + if p == nil || p.Role == nil { + return -1 + } + return *p.Role +}