feat: integrate OA activation workflows and business migration
This commit is contained in:
@@ -19,17 +19,26 @@ var (
|
||||
)
|
||||
|
||||
type Activation struct {
|
||||
BusierID uint64
|
||||
CreatedAt *time.Time
|
||||
RegisteredPlayers *int64
|
||||
Channels []ChannelKey
|
||||
MetricsAvailable bool
|
||||
ID uint64
|
||||
PromoteID *uint64
|
||||
PlatformName, PromoteAccount, BusierAccount, ApplicantOA, Status, AccumAmount string
|
||||
BindAt, UnbindAt, ReachAt *time.Time
|
||||
}
|
||||
|
||||
func (a *Activation) EndAt() *time.Time {
|
||||
if a.Status == "reached" && a.ReachAt != nil {
|
||||
return a.ReachAt
|
||||
// 达标仍处于绑定关系内,流水和注册统计持续到实际解绑。
|
||||
func (a *Activation) EndAt() *time.Time { return a.UnbindAt }
|
||||
|
||||
// 换绑即结束原关系,即使 OA 定时扫描还没执行,也不能读取新归属期间的流水。
|
||||
func (a *Activation) EndOnTransfer(at time.Time) {
|
||||
if a.BindAt != nil && !at.Before(*a.BindAt) && (a.UnbindAt == nil || at.Before(*a.UnbindAt)) {
|
||||
a.UnbindAt = &at
|
||||
a.Status = "unbound"
|
||||
}
|
||||
return a.UnbindAt
|
||||
}
|
||||
|
||||
type ActivationAccount struct {
|
||||
@@ -41,6 +50,7 @@ type ActivationScope struct {
|
||||
Accounts []ActivationAccount
|
||||
}
|
||||
type ActivationFilter struct {
|
||||
IDCardDedup bool
|
||||
PlatformNames, Statuses []string
|
||||
PromoteAccount, BusierAccount string
|
||||
}
|
||||
@@ -50,12 +60,13 @@ type ActivationPage struct {
|
||||
Available bool
|
||||
}
|
||||
type ActivationSpendQuery struct {
|
||||
Channels []ChannelKey
|
||||
PlatformName string
|
||||
PromoteID uint64
|
||||
Start int64
|
||||
End *int64
|
||||
}
|
||||
type ActivationSpendItem struct{ GameName, Amount string }
|
||||
type ActivationSpendItem struct{ PlatformName, GameName, Amount string }
|
||||
type ActivationSpendDetail struct {
|
||||
Activation *Activation
|
||||
Items []*ActivationSpendItem
|
||||
@@ -70,12 +81,13 @@ type ActivationRepo interface {
|
||||
}
|
||||
|
||||
type ActivationUsecase struct {
|
||||
repo ActivationRepo
|
||||
accounts *AccountUsecase
|
||||
repo ActivationRepo
|
||||
accounts *AccountUsecase
|
||||
preferences *UserPreferenceUsecase
|
||||
}
|
||||
|
||||
func NewActivationUsecase(repo ActivationRepo, accounts *AccountUsecase) *ActivationUsecase {
|
||||
return &ActivationUsecase{repo: repo, accounts: accounts}
|
||||
func NewActivationUsecase(repo ActivationRepo, accounts *AccountUsecase, preferences *UserPreferenceUsecase) *ActivationUsecase {
|
||||
return &ActivationUsecase{repo: repo, accounts: accounts, preferences: preferences}
|
||||
}
|
||||
|
||||
func (uc *ActivationUsecase) scope(ctx context.Context) (ActivationScope, error) {
|
||||
@@ -126,6 +138,11 @@ func (uc *ActivationUsecase) List(ctx context.Context, filter ActivationFilter,
|
||||
for i, status := range filter.Statuses {
|
||||
filter.Statuses[i] = NormalizeActivationStatus(status)
|
||||
}
|
||||
pref, err := uc.preferences.Current(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
filter.IDCardDedup = pref.IDCardDedup
|
||||
return uc.repo.List(ctx, scope, filter, options...)
|
||||
}
|
||||
|
||||
@@ -160,7 +177,7 @@ func (uc *ActivationUsecase) SpendDetail(ctx context.Context, id uint64) (*Activ
|
||||
if strings.TrimSpace(activation.PlatformName) == "" || activation.PromoteID == nil || *activation.PromoteID == 0 {
|
||||
return detail, nil
|
||||
}
|
||||
query := ActivationSpendQuery{PlatformName: activation.PlatformName, PromoteID: *activation.PromoteID, Start: activation.BindAt.Unix()}
|
||||
query := ActivationSpendQuery{Channels: activation.Channels, PlatformName: activation.PlatformName, PromoteID: *activation.PromoteID, Start: activation.BindAt.Unix()}
|
||||
if end := activation.EndAt(); end != nil {
|
||||
n := end.Unix()
|
||||
query.End = &n
|
||||
@@ -185,13 +202,13 @@ func (uc *ActivationUsecase) SpendDetail(ctx context.Context, id uint64) (*Activ
|
||||
|
||||
func NormalizeActivationStatus(status string) string {
|
||||
status = strings.TrimSpace(status)
|
||||
if code, ok := map[string]string{"待审核": "pending", "进行中": "in_progress", "已达标": "reached", "已驳回": "rejected", "已解绑": "unbound"}[status]; ok {
|
||||
if code, ok := map[string]string{"待审核": "pending", "审核中": "pending", "进行中": "in_progress", "已达标": "reached", "已驳回": "rejected", "已解绑": "unbound"}[status]; ok {
|
||||
return code
|
||||
}
|
||||
return status
|
||||
}
|
||||
func ActivationStatusLabel(status string) string {
|
||||
if label, ok := map[string]string{"pending": "待审核", "in_progress": "进行中", "reached": "已达标", "rejected": "已驳回", "unbound": "已解绑"}[status]; ok {
|
||||
if label, ok := map[string]string{"pending": "审核中", "in_progress": "进行中", "reached": "已达标", "rejected": "已驳回", "unbound": "已解绑"}[status]; ok {
|
||||
return label
|
||||
}
|
||||
return status
|
||||
|
||||
Reference in New Issue
Block a user