117 lines
3.3 KiB
Go
117 lines
3.3 KiB
Go
package invitation
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type Service struct {
|
|
repo *Repository
|
|
}
|
|
|
|
func NewService(repo *Repository) *Service {
|
|
return &Service{repo: repo}
|
|
}
|
|
|
|
func (s *Service) Repo() *Repository {
|
|
return s.repo
|
|
}
|
|
|
|
func (s *Service) GetInviteCodeInfo(ctx context.Context, code string) (*InviteCodeInfoDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.GetInviteCodeInfo(ctx, code)
|
|
}
|
|
|
|
func (s *Service) BindInvitation(ctx context.Context, inviteeID uint64, code string, siteID uint64, siteCode ...string) error {
|
|
if s.repo == nil {
|
|
return ErrDependencyUnavailable
|
|
}
|
|
return s.repo.BindInvitation(ctx, inviteeID, code, siteID, siteCode...)
|
|
}
|
|
|
|
func (s *Service) OnUserRealnameVerified(ctx context.Context, userID uint64) error {
|
|
if s.repo == nil {
|
|
return ErrDependencyUnavailable
|
|
}
|
|
return s.repo.OnUserRealnameVerified(ctx, userID)
|
|
}
|
|
|
|
func (s *Service) GetUserSummary(ctx context.Context, userID uint64, siteID uint64) (*UserInvitationSummaryDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.GetUserSummary(ctx, userID, siteID)
|
|
}
|
|
|
|
func (s *Service) ListMyInvitedUsers(ctx context.Context, userID uint64, page, pageSize int) ([]InvitedUserRecordDTO, int64, error) {
|
|
if s.repo == nil {
|
|
return nil, 0, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.ListMyInvitedUsers(ctx, userID, page, pageSize)
|
|
}
|
|
|
|
func (s *Service) ListMyRebates(ctx context.Context, userID uint64, page, pageSize int) ([]RebateLedgerDTO, int64, error) {
|
|
if s.repo == nil {
|
|
return nil, 0, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.ListMyRebates(ctx, userID, page, pageSize)
|
|
}
|
|
|
|
func (s *Service) GetRebateConfig(ctx context.Context, siteID uint64) (*ConfigDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
cfg, err := s.repo.GetRebateConfig(ctx, siteID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &ConfigDTO{
|
|
DistributionSiteID: cfg.DistributionSiteID,
|
|
FirstMonthRate: cfg.FirstMonthRate,
|
|
SecondMonthRate: cfg.SecondMonthRate,
|
|
SubsequentRate: cfg.SubsequentRate,
|
|
Enabled: cfg.Enabled,
|
|
UpdatedAt: cfg.UpdatedAt,
|
|
}, nil
|
|
}
|
|
|
|
func (s *Service) UpdateRebateConfig(ctx context.Context, siteID uint64, req UpdateConfigRequest) (*ConfigDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
cfg, err := s.repo.UpdateRebateConfig(ctx, siteID, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &ConfigDTO{
|
|
DistributionSiteID: cfg.DistributionSiteID,
|
|
FirstMonthRate: cfg.FirstMonthRate,
|
|
SecondMonthRate: cfg.SecondMonthRate,
|
|
SubsequentRate: cfg.SubsequentRate,
|
|
Enabled: cfg.Enabled,
|
|
UpdatedAt: cfg.UpdatedAt,
|
|
}, nil
|
|
}
|
|
|
|
func (s *Service) ListAdminInvitations(ctx context.Context, query AdminInvitationQuery) ([]map[string]any, int64, error) {
|
|
if s.repo == nil {
|
|
return nil, 0, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.ListAdminInvitations(ctx, query)
|
|
}
|
|
|
|
func (s *Service) ListAdminRebateLedgers(ctx context.Context, query AdminRebateLedgerQuery) ([]map[string]any, int64, error) {
|
|
if s.repo == nil {
|
|
return nil, 0, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.ListAdminRebateLedgers(ctx, query)
|
|
}
|
|
|
|
func (s *Service) AdminRebateSummary(ctx context.Context, query AdminRebateLedgerQuery) (*AdminRebateSummaryDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.AdminRebateSummary(ctx, query)
|
|
}
|