package usercenterser import ( "context" "hkdj-web-server/app/api/proto" "hkdj-web-server/pub/common/log" "hkdj-web-server/pub/common/srvdef" "hkdj-web-server/pub/models/playletchapterunlockmod" "hkdj-web-server/pub/models/playletcollectmod" "hkdj-web-server/pub/models/playletwatchhistorymod" "hkdj-web-server/pub/models/playletwatchprogressmod" "go.mongodb.org/mongo-driver/bson" ) // Data 查询app个人中心数据 func Data(ctx context.Context, userId int64) (*proto.UserCenterDataResp, *srvdef.SrvErr) { if userId <= 0 { return nil, srvdef.New(srvdef.InvalidToken, "请先登录", "请先登录") } watchCount, err := playletwatchhistorymod.CountPlayletWatchHistory(ctx, bson.M{ playletwatchhistorymod.FN.PlayletWatchHistory.UserId: userId, }) if err != nil { log.Error("统计个人中心观看数量失败", log.Any("用户ID", userId), log.E(err)) return nil, err } collectCount, err := playletcollectmod.CountPlayletCollect(ctx, bson.M{ playletcollectmod.FN.PlayletCollect.UserId: userId, }) if err != nil { log.Error("统计个人中心收藏数量失败", log.Any("用户ID", userId), log.E(err)) return nil, err } chasingCount, err := playletwatchprogressmod.CountPlayletWatchProgress(ctx, bson.M{ playletwatchprogressmod.FN.PlayletWatchProgress.UserId: userId, playletwatchprogressmod.FN.PlayletWatchProgress.IsChasing: true, }) if err != nil { log.Error("统计个人中心追剧中数量失败", log.Any("用户ID", userId), log.E(err)) return nil, err } boughtChapterCount, err := playletchapterunlockmod.CountPlayletChapterUnlock(ctx, bson.M{ playletchapterunlockmod.FN.PlayletChapterUnlock.UserId: userId, }) if err != nil { log.Error("统计个人中心已购剧集数量失败", log.Any("用户ID", userId), log.E(err)) return nil, err } return &proto.UserCenterDataResp{ WatchCount: watchCount, CollectCount: collectCount, ChasingCount: chasingCount, BoughtChapterCount: boughtChapterCount, }, nil }