Files
web_huakui_server/app/service/usercenterser/user_center.go
T
rootandClaude Opus 4.7 85c0071fd8 feat: 从黄果 NET hgdjnet-server 9bfbafe 导入 HKDJ 官网后端
来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83
项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet
测试目录 /server/hkdj_net,App/Web API 30331/30332

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-10-16 11:20:04 +08:00

62 lines
2.0 KiB
Go

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
}