topfans/backend/services/taskService/provider/task_internal_provider.go

81 lines
2.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package provider
import (
"context"
"github.com/topfans/backend/pkg/logger"
pb "github.com/topfans/backend/pkg/proto/task"
"github.com/topfans/backend/services/taskService/service"
"go.uber.org/zap"
)
// TaskInternalProvider 实现 TaskInternalService 接口(内部 RPC
type TaskInternalProvider struct {
onboardingSvc service.OnboardingService
revenueSvc service.RevenueService
}
func NewTaskInternalProvider(
onboardingSvc service.OnboardingService,
revenueSvc service.RevenueService,
) *TaskInternalProvider {
return &TaskInternalProvider{
onboardingSvc: onboardingSvc,
revenueSvc: revenueSvc,
}
}
// InitUserTasks 创建用户的 onboarding status 和每日任务进度
// 由 userService 或其他服务在用户注册/新增粉丝身份时调用
func (p *TaskInternalProvider) InitUserTasks(ctx context.Context, req *pb.InitUserTasksRequest) (*pb.InitUserTasksResponse, error) {
logger.Logger.Info("TaskInternalProvider.InitUserTasks called",
zap.Int64("user_id", req.UserId),
zap.Int64("star_id", req.StarId))
err := p.onboardingSvc.InitUserTasks(ctx, req.UserId, req.StarId)
if err != nil {
logger.Logger.Error("TaskInternalProvider.InitUserTasks failed",
zap.Int64("user_id", req.UserId),
zap.Int64("star_id", req.StarId),
zap.Error(err))
return &pb.InitUserTasksResponse{
Success: false,
}, nil
}
logger.Logger.Info("TaskInternalProvider.InitUserTasks succeeded",
zap.Int64("user_id", req.UserId),
zap.Int64("star_id", req.StarId))
return &pb.InitUserTasksResponse{
Success: true,
}, nil
}
// OnExhibitionCompleted 当展位到期完成时由 galleryService 调用
// 创建展示收益记录(仅在 slot_owner_uid != occupier_uid 时)
func (p *TaskInternalProvider) OnExhibitionCompleted(ctx context.Context, req *pb.OnExhibitionCompletedRequest) (*pb.OnExhibitionCompletedResponse, error) {
logger.Logger.Info("TaskInternalProvider.OnExhibitionCompleted called",
zap.Int64("exhibition_id", req.ExhibitionId),
zap.Int64("asset_id", req.AssetId),
zap.Int64("slot_id", req.SlotId),
zap.Int64("occupier_uid", req.OccupierUid),
zap.Int64("occupier_star_id", req.OccupierStarId),
zap.Int64("slot_owner_uid", req.SlotOwnerUid),
zap.Int64("crystal_amount", req.CrystalAmount))
resp, err := p.revenueSvc.OnExhibitionCompleted(ctx, req)
if err != nil {
logger.Logger.Error("TaskInternalProvider.OnExhibitionCompleted failed",
zap.Int64("exhibition_id", req.ExhibitionId),
zap.Error(err))
return nil, err
}
logger.Logger.Info("TaskInternalProvider.OnExhibitionCompleted succeeded",
zap.Int64("exhibition_id", req.ExhibitionId),
zap.Int64("revenue_record_id", resp.RevenueRecordId))
return resp, nil
}