62 lines
1.9 KiB
Go
62 lines
1.9 KiB
Go
package usercenterser
|
|
|
|
import (
|
|
"context"
|
|
"videoweb/app/api/proto"
|
|
"videoweb/pub/common/log"
|
|
"videoweb/pub/common/srvdef"
|
|
"videoweb/pub/models/playletchapterunlockmod"
|
|
"videoweb/pub/models/playletcollectmod"
|
|
"videoweb/pub/models/playletwatchhistorymod"
|
|
"videoweb/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
|
|
}
|