From 52624ac5920a988cbbf5c2b75a9bc029dc8b2d56 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Fri, 12 Apr 2024 06:40:30 +0800 Subject: [PATCH 1/2] by Robin at 20240411 --- api/proto/account/proto/account_api.go | 15 +++++ api/proto/streamer/proto/streamer_vo_api.go | 12 +++- api/proto/streamer/proto/streamer_vo_op.go | 10 ++++ api/proto/zone/proto/zone_api.go | 19 ++++++ api/proto/zonemoment/proto/moment_vo_api.go | 1 + app/mix/controller/init.go | 2 + app/mix/controller/zone_api.go | 35 +++++++++++ app/mix/service/apiservice.go | 66 +++++++++++++++++++++ app/mix/service/utilservice.go | 14 +++++ 9 files changed, 173 insertions(+), 1 deletion(-) diff --git a/api/proto/account/proto/account_api.go b/api/proto/account/proto/account_api.go index ea430d3e..ddebcbb9 100644 --- a/api/proto/account/proto/account_api.go +++ b/api/proto/account/proto/account_api.go @@ -174,6 +174,21 @@ type ApiListOthersByMidsResp struct { Data *ApiListOthersByMidsData `json:"data"` } +// api 列表-查询他人 +type ApiListOthersByUserIdReq struct { + base.BaseRequest + UserId *int64 `json:"mid"` //单个查询 +} + +type ApiListOthersByUserIdData struct { + Account *ApiListOthersVO `json:"account"` +} + +type ApiListOthersByUserIdResp struct { + base.BaseResponse + Data *ApiListOthersByUserIdResp `json:"data"` +} + // api 经验增长 type ApiExpIncReq struct { base.BaseRequest diff --git a/api/proto/streamer/proto/streamer_vo_api.go b/api/proto/streamer/proto/streamer_vo_api.go index 6093ae91..50cc1b2d 100644 --- a/api/proto/streamer/proto/streamer_vo_api.go +++ b/api/proto/streamer/proto/streamer_vo_api.go @@ -42,7 +42,9 @@ type ApiListExtVO struct { WechatContact *string `json:"wechat_contact"` WechatCoinPrice *int64 `json:"wechat_coin_price"` - Zones []*dbstruct.Zone `json:"zones" bson:"zones"` + Zones []*dbstruct.Zone `json:"zones" bson:"zones"` + IsActiveWithinAWeek *int64 `json:"is_active_within_a_week"` // 7日内空间是否活跃 + TimeElapsedSinceTheLastZonesUpdate *int64 `json:"time_elapsed_since_the_last_zones_update"` // 空间最后活跃时间距离现在时间跨度 } func (vo *ApiListExtVO) GetMid() int64 { @@ -116,3 +118,11 @@ func (vo *ApiListExtVO) CopyZones(zones []*dbstruct.Zone) { vo.Zones = zones } } + +func (vo *ApiListExtVO) SetIsActiveWithinAWeek(is_active_within_a_week int64) { + vo.IsActiveWithinAWeek = goproto.Int64(is_active_within_a_week) +} + +func (vo *ApiListExtVO) SetDaysElapsedSinceTheLastZonesUpdate(days_elapsed_since_the_last_zones_update int64) { + vo.TimeElapsedSinceTheLastZonesUpdate = goproto.Int64(days_elapsed_since_the_last_zones_update) +} diff --git a/api/proto/streamer/proto/streamer_vo_op.go b/api/proto/streamer/proto/streamer_vo_op.go index e3ab2de8..730d1d4c 100644 --- a/api/proto/streamer/proto/streamer_vo_op.go +++ b/api/proto/streamer/proto/streamer_vo_op.go @@ -15,6 +15,8 @@ type StreamerExtVO interface { CopyPlatforms(platforms *[]*streamerlinkproto.StreamerLinkVO) CopyUserVas(userVas *dbstruct.UserVasInfo) CopyZones(zones []*dbstruct.Zone) + SetIsActiveWithinAWeek(is_active_within_a_week int64) + SetDaysElapsedSinceTheLastZonesUpdate(days_elapsed_since_the_last_zones_update int64) } // 查询VO类 @@ -122,3 +124,11 @@ func (vo *OpListExtVO) CopyUserVas(userVas *dbstruct.UserVasInfo) { func (vo *OpListExtVO) CopyZones(zones []*dbstruct.Zone) { } + +func (vo *OpListExtVO) SetIsActiveWithinAWeek(is_active_within_a_week int64) { + +} + +func (vo *OpListExtVO) SetDaysElapsedSinceTheLastZonesUpdate(days_elapsed_since_the_last_zones_update int64) { + +} diff --git a/api/proto/zone/proto/zone_api.go b/api/proto/zone/proto/zone_api.go index 846d0728..d85694c0 100644 --- a/api/proto/zone/proto/zone_api.go +++ b/api/proto/zone/proto/zone_api.go @@ -138,3 +138,22 @@ type OpListByMidResp struct { base.BaseResponse Data *OpListByMidData `json:"data"` } + +// op 列表 +type ApiListByUserIdFromOutsideReq struct { + base.BaseRequest + UserId int64 `json:"user_id"` + Offset int `json:"offset"` + Limit int `json:"limit"` +} + +type ApiListByUserIdFromOutsideData struct { + List []*ApiZoneVO `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` +} + +type ApiListByUserIdFromOutsideResp struct { + base.BaseResponse + Data *ApiListByUserIdFromOutsideData `json:"data"` +} diff --git a/api/proto/zonemoment/proto/moment_vo_api.go b/api/proto/zonemoment/proto/moment_vo_api.go index 39fdc35d..13ee252a 100644 --- a/api/proto/zonemoment/proto/moment_vo_api.go +++ b/api/proto/zonemoment/proto/moment_vo_api.go @@ -14,6 +14,7 @@ type ApiZoneMomentVO struct { IsSuperfanshipUnlocked int64 `json:"is_superfanship_unlocked"` IsZoneMomentUnlocked int64 `json:"is_zone_moment_unlocked"` Expenditure int64 `json:"expenditure"` + IronfanshipPrice int64 `json:"ironfanship_price"` } func (vo *ApiZoneMomentVO) CopyZoneMoment(zonemoment *dbstruct.ZoneMoment) { diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index e86ddf44..76ec0312 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -85,6 +85,7 @@ func Init(r *gin.Engine) { //apiAccountGroup.POST("list_by_user_id", middleware.JSONParamValidator(accountproto.ApiListByUserIdReq{}), middleware.JwtAuthenticator(), ApiGetAccountListByUserId) apiAccountGroup.POST("list_others_by_mid", middleware.JSONParamValidator(accountproto.ApiListOthersByMidReq{}), middleware.JwtAuthenticator(), ApiGetAccountListForOthersByMid) apiAccountGroup.POST("list_others_by_mids", middleware.JSONParamValidator(accountproto.ApiListOthersByMidsReq{}), middleware.JwtAuthenticator(), ApiGetAccountListForOthersByMids) + apiAccountGroup.POST("list_others_by_user_id", middleware.JSONParamValidator(accountproto.ApiListOthersByUserIdReq{}), middleware.JwtAuthenticator(), ApiGetAccountListForOthersByUserId) apiAccountGroup.POST("exp_inc", middleware.JSONParamValidator(accountproto.ApiExpIncReq{}), middleware.JwtAuthenticator(), ApiAccountExpInc) apiAccountGroup.POST("cancel", middleware.JSONParamValidator(accountproto.ApiCancelReq{}), middleware.JwtAuthenticator(), ApiCancelAccount) apiAccountGroup.POST("abort_cancellation", middleware.JSONParamValidator(accountproto.ApiAbortCancellationReq{}), middleware.JwtAuthenticator(), ApiAbortAccountCancellation) @@ -216,6 +217,7 @@ func Init(r *gin.Engine) { apiZoneGroup.POST("list", middleware.JSONParamValidator(zoneproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetZoneList) apiZoneGroup.POST("list_by_mid", middleware.JSONParamValidator(zoneproto.ApiListByMidReq{}), middleware.JwtAuthenticator(), ApiGetZoneListByMid) apiZoneGroup.POST("list_by_visitor_mid", middleware.JSONParamValidator(zoneproto.ApiListByVisitorMidReq{}), middleware.JwtAuthenticator(), ApiGetZoneListByVisitorMid) + apiZoneGroup.POST("list_by_user_id_from_outside", middleware.JSONParamValidator(zoneproto.ApiListByUserIdFromOutsideReq{}), ApiGetZoneListByUserIdFromOutside) // 私密圈动态 apiZoneMomentGroup := r.Group("/api/zone_moment", PrepareToC()) diff --git a/app/mix/controller/zone_api.go b/app/mix/controller/zone_api.go index 103f55f1..42b1f76b 100644 --- a/app/mix/controller/zone_api.go +++ b/app/mix/controller/zone_api.go @@ -142,3 +142,38 @@ func ApiGetZoneListByMid(ctx *gin.Context) { } ReplyOk(ctx, data) } + +func ApiGetZoneListByUserIdFromOutside(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*zoneproto.ApiListByUserIdFromOutsideReq) + + //设置默认页长 + if req.Limit == 0 { + req.Limit = consts.DefaultPageSize + } + + list, ec := service.DefaultService.ApiGetZoneListByUserIdFromOutside(ctx, req) + if ec != errcode.ErrCodeZoneSrvOk { + logger.Error("ApiGetZoneListByUserIdFromOutside fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + objectMediaNum := 5 // 单个空间服务总共5个媒体类 + mediaFillableList := make([]mediafiller.MediaFillable, len(list)*objectMediaNum) + for i, vo := range list { + mediaFillableList[objectMediaNum*i+0] = vo.Previews + mediaFillableList[objectMediaNum*i+1] = vo.StreamerExt.Cover + mediaFillableList[objectMediaNum*i+2] = vo.StreamerExt.Shorts + mediaFillableList[objectMediaNum*i+3] = vo.StreamerExt.Album + mediaFillableList[objectMediaNum*i+4] = vo.StreamerExt.Avatar + } + mediafiller.FillList(ctx, mediaFillableList) + + data := &zoneproto.ApiListByMidData{ + List: list, + Offset: req.Offset + len(list), + } + if len(list) >= req.Limit { + data.More = 1 + } + ReplyOk(ctx, data) +} diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index b35de175..ca3c0dff 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -517,6 +517,22 @@ func (s *Service) ApiGetAccountListForOthersByMids(ctx *gin.Context, req *accoun return } +func (s *Service) ApiGetAccountListForOthersByUserId(ctx *gin.Context, req *accountproto.ApiListOthersByUserIdReq) (vo *accountproto.ApiListOthersVO, ec errcode.ErrCode) { + ec = errcode.ErrCodeAccountSrvOk + account, err := _DefaultAccount.OpListByUserId(ctx, &accountproto.OpListByUserIdReq{ + UserId: req.UserId, + }) + if err != nil { + logger.Error("OpListByUserId fail, err: %v", err) + ec = errcode.ErrCodeAccountSrvFail + return + } + + vo = &accountproto.ApiListOthersVO{} + vo.CopyAccount(account) + return +} + func (s *Service) ApiAccountExpInc(ctx *gin.Context, req *accountproto.ApiExpIncReq) (result *accountproto.ApiExpIncData, ec errcode.ErrCode) { ec = errcode.ErrCodeAccountSrvOk @@ -2206,6 +2222,56 @@ func (s *Service) ApiGetZoneListByVisitorMid(ctx *gin.Context, req *zoneproto.Ap return } +func (s *Service) ApiGetZoneListByUserIdFromOutside(ctx *gin.Context, req *zoneproto.ApiListByUserIdFromOutsideReq) (volist []*zoneproto.ApiZoneVO, ec errcode.ErrCode) { + ec = errcode.ErrCodeZoneSrvOk + + volist = make([]*zoneproto.ApiZoneVO, 0) + + account, err := _DefaultAccount.OpListByUserId(ctx, &accountproto.OpListByUserIdReq{ + UserId: goproto.Int64(req.UserId), + }) + if err != nil { + logger.Error("_DefaultAccount OpListByUserId fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeAccountSrvFail + return + } + if account == nil { + return + } + + list, err := _DefaultZone.OpListByMid(ctx, &zoneproto.OpListByMidReq{ + BaseRequest: req.BaseRequest, + Uid: account.Mid, + Offset: req.Offset, + Limit: req.Limit, + }) + if err != nil { + logger.Error("OpListGetZoneList fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneSrvFail + return + } + + mid := util.DerefInt64(account.Mid) + streamerExtMap, err := s.utilGetStreamerExtMapByMids(ctx, []int64{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[mid].(*streamerproto.ApiListExtVO) + + // 填充必要信息 + for _, zone := range list { + vo := &zoneproto.ApiZoneVO{ + Zone: zone, + StreamerExt: streamerExt, + } + volist = append(volist, vo) + } + + return +} + // ZoneMoment func (s *Service) ApiCreateZoneMoment(ctx *gin.Context, req *zonemomentproto.ApiCreateReq) (ec errcode.ErrCode, acctPunEndTime string) { ec = errcode.ErrCodeZoneMomentSrvOk diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index ce73b42d..769951f4 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -761,6 +761,19 @@ func (s *Service) utilGetStreamerExtMapByMids(ctx *gin.Context, mids []int64, op streamerExt.CopyPlatforms(&streamerlinkvolist) streamerExt.CopyUserVas(userVas) streamerExt.CopyZones(zonesMap[mid]) + // 计算空间更新时间距离现在时间跨度 + nowTime := time.Now() + for _, zone := range zonesMap[mid] { + lastZoneMomentCreateDay := util.GetDayStartTimeStamp(time.Unix(util.DerefInt64(zone.LastZoneMomentCt), 0)) + today := util.GetDayStartTimeStamp(nowTime) + daysElapsedSinceTheLastZonesUpdate := (today - lastZoneMomentCreateDay) / int64(86400) // 24 * 60 * 60 = 86400秒 + streamerExt.SetDaysElapsedSinceTheLastZonesUpdate(daysElapsedSinceTheLastZonesUpdate) + if daysElapsedSinceTheLastZonesUpdate <= 7 { + streamerExt.SetIsActiveWithinAWeek(consts.ZoneIsActiveWithinAWeek_Yes) + } else { + streamerExt.SetIsActiveWithinAWeek(consts.ZoneIsActiveWithinAWeek_No) + } + } streamerExtMap[mid] = streamerExt } @@ -1426,6 +1439,7 @@ func (s *Service) utilGetApiMomentVOListByIds(ctx *gin.Context, visitorMid int64 func (s *Service) utilFillZonesWithApiVOInfo(ctx *gin.Context, list []*dbstruct.Zone, visitorMid int64) (volist []*zoneproto.ApiZoneVO, err error) { // 1.获取mids,并填充空间基底 + volist = make([]*zoneproto.ApiZoneVO, 0) mids := make([]int64, 0) midSet := make(map[int64]*dbstruct.Zone) for _, zone := range list { From c7d931b10e84b811c5e67bdb878703f7c0c4165e Mon Sep 17 00:00:00 2001 From: Leufolium Date: Fri, 12 Apr 2024 06:40:43 +0800 Subject: [PATCH 2/2] by Robin at 20240411 --- app/mix/controller/account_api.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/mix/controller/account_api.go b/app/mix/controller/account_api.go index dba306fb..64605dcd 100644 --- a/app/mix/controller/account_api.go +++ b/app/mix/controller/account_api.go @@ -220,6 +220,26 @@ func ApiGetAccountListForOthersByMids(ctx *gin.Context) { ReplyOk(ctx, data) } +func ApiGetAccountListForOthersByUserId(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*accountproto.ApiListOthersByUserIdReq) + + account, ec := service.DefaultService.ApiGetAccountListForOthersByUserId(ctx, req) + if ec != errcode.ErrCodeAccountSrvOk { + logger.Error("ApiGetAccountListOthersByUserId fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + //填充媒体 + mediafiller.FillEntity(ctx, account.Avatar) + + data := &accountproto.ApiListOthersByUserIdData{ + Account: account, + } + + ReplyOk(ctx, data) +} + func ApiAccountExpInc(ctx *gin.Context) { req := ctx.MustGet("client_req").(*accountproto.ApiExpIncReq) result, ec := service.DefaultService.ApiAccountExpInc(ctx, req)