- 数据库与数据模型:新增 migration 000081,支持用户专属邀请码、被邀请人绑定与实名时间戳;新增邀请返利配置表与结算明细表 - 业务与结算逻辑:实现首月 60%、次月 30%、往后 15% 阶梯返利算法;买卖双向独立寻源并根据订单平台利润 50% 单边基准核算;与终态订单结算和钱包可用余额强幂等联动 - 分销站点支持:支持主站与加盟分站独立配置返利比例;跨站交易按照收号端与售卖端独立出资,资金互不侵蚀 - 前端交互与入口: - 新增专属短链注册落地页 /i/:code,自动带入并锁定邀请码,引导实名认证 - 个人中心与移动端新增邀请返利看板(专属码、推广链接、统计面板、好友记录与返利流水明细) - 管理后台新增邀请返利管理(比例配置、邀请关系与返利流水审计) - 验证方式: - 通过 repository_test.go 单元测试(阶梯区间、实名激活、跨站多方分流验证) - 通过 npm run format、npm run check 与 scripts/check.sh 全量门禁校验
110 lines
3.1 KiB
Go
110 lines
3.1 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)
|
|
}
|