feat: 迁移游戏商务绑定审核流程和列表
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
package business
|
||||
|
||||
import (
|
||||
"context"
|
||||
"kra/internal/biz/business"
|
||||
"kra/internal/service/dto"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
type BindingUsecase interface {
|
||||
List(context.Context, business.BindingFilter, ...business.ListOption) ([]*business.Binding, int64, error)
|
||||
ForUser(context.Context, uint) ([]*business.Binding, error)
|
||||
Bind(context.Context, string, string, string) error
|
||||
Unbind(context.Context, business.PlatformKey) error
|
||||
}
|
||||
type BindingService struct{ uc BindingUsecase }
|
||||
|
||||
func NewBindingService(uc *business.BindingUsecase) *BindingService { return &BindingService{uc: uc} }
|
||||
|
||||
func localTime(t *time.Time) *string {
|
||||
if t == nil || t.IsZero() {
|
||||
return nil
|
||||
}
|
||||
s := t.Format("2006-01-02 15:04:05")
|
||||
return &s
|
||||
}
|
||||
func bindingResponse(b *business.Binding) *dto.BusinessBindingResponse {
|
||||
return &dto.BusinessBindingResponse{UserID: b.UserID, SourceDB: b.SourceDB, PlatformName: business.PlatformName(b.SourceDB), PlatformBusierID: b.BusierID,
|
||||
Account: b.Account, UserName: b.UserName, PromoteCount: b.PromoteCount, Status: b.Status, RejectReason: b.RejectReason, CreateTime: localTime(&b.CreatedAt), ReviewTime: localTime(b.ReviewTime), ReviewAccount: b.ReviewAccount}
|
||||
}
|
||||
|
||||
func normalizePlatforms(values []string) ([]string, error) {
|
||||
result := []string{}
|
||||
seen := map[string]bool{}
|
||||
for _, raw := range values {
|
||||
for _, value := range strings.Split(raw, ",") {
|
||||
if strings.TrimSpace(value) == "" {
|
||||
continue
|
||||
}
|
||||
value, err := business.NormalizePlatform(value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !seen[value] {
|
||||
seen[value] = true
|
||||
result = append(result, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
func (s *BindingService) List(ctx context.Context, req *dto.BusinessBindingQuery) (*dto.BusinessBindingPage, error) {
|
||||
if req == nil {
|
||||
return nil, business.ErrAccountInput
|
||||
}
|
||||
sources, err := normalizePlatforms(req.SourceDB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if req.Status != "" && req.Status != "0" && req.Status != "2" && req.Status != "3" {
|
||||
return nil, business.ErrAccountInput
|
||||
}
|
||||
page, size := req.Page, req.PageSize
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
if size < 1 {
|
||||
size = 10
|
||||
}
|
||||
if size > 500 {
|
||||
size = 500
|
||||
}
|
||||
if page > int(^uint(0)>>1)/size {
|
||||
return nil, business.ErrAccountInput
|
||||
}
|
||||
rows, total, err := s.uc.List(ctx, business.BindingFilter{SourceDBs: sources, Account: req.Account, Status: req.Status}, business.ListOffset((page-1)*size), business.ListLimit(size))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := &dto.BusinessBindingPage{Rows: make([]*dto.BusinessBindingResponse, 0, len(rows)), Total: total}
|
||||
for _, b := range rows {
|
||||
out.Rows = append(out.Rows, bindingResponse(b))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (s *BindingService) ForUser(ctx context.Context, id uint) ([]*dto.BusinessBindingResponse, error) {
|
||||
if id == 0 {
|
||||
return nil, business.ErrAccountInput
|
||||
}
|
||||
rows, err := s.uc.ForUser(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]*dto.BusinessBindingResponse, 0, len(rows))
|
||||
for _, b := range rows {
|
||||
out = append(out, bindingResponse(b))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (s *BindingService) Bind(ctx context.Context, req *dto.BusinessBindingRequest) error {
|
||||
if req == nil || strings.TrimSpace(req.Account) == "" || utf8.RuneCountInString(req.Account) > 30 || strings.TrimSpace(req.Password) == "" || utf8.RuneCountInString(req.Password) > 100 {
|
||||
return business.ErrAccountInput
|
||||
}
|
||||
source, err := business.NormalizePlatform(req.SourceDB)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.uc.Bind(ctx, source, req.Account, req.Password)
|
||||
}
|
||||
func (s *BindingService) Unbind(ctx context.Context, req *dto.BusinessBindingRequest) error {
|
||||
if req == nil || req.PlatformBusierID == 0 {
|
||||
return business.ErrAccountInput
|
||||
}
|
||||
source, err := business.NormalizePlatform(req.SourceDB)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.uc.Unbind(ctx, business.PlatformKey{SourceDB: source, BusierID: req.PlatformBusierID})
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package dto
|
||||
|
||||
type BusinessBindingQuery struct {
|
||||
Page int `form:"pageNum"`
|
||||
PageSize int `form:"pageSize"`
|
||||
SourceDB []string `form:"sourceDb"`
|
||||
Account string `form:"platformBusierAccount"`
|
||||
Status string `form:"status"`
|
||||
}
|
||||
type BusinessBindingRequest struct {
|
||||
SourceDB string `json:"sourceDb"`
|
||||
Account string `json:"account"`
|
||||
Password string `json:"password"`
|
||||
PlatformBusierID uint64 `json:"platformBusierId"`
|
||||
}
|
||||
type BusinessBindingResponse struct {
|
||||
UserID uint `json:"userId"`
|
||||
SourceDB string `json:"sourceDb"`
|
||||
PlatformName string `json:"platformName"`
|
||||
PlatformBusierID uint64 `json:"platformBusierId"`
|
||||
Account string `json:"platformBusierAccount"`
|
||||
UserName string `json:"bindUserName"`
|
||||
PromoteCount *int64 `json:"promoteCount"`
|
||||
Status string `json:"status"`
|
||||
RejectReason *string `json:"rejectReason"`
|
||||
CreateTime *string `json:"createTime"`
|
||||
ReviewTime *string `json:"reviewTime"`
|
||||
ReviewAccount *string `json:"reviewAccount"`
|
||||
}
|
||||
type BusinessBindingPage struct {
|
||||
Rows []*BusinessBindingResponse `json:"rows"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
var ProviderSet = wire.NewSet(
|
||||
businessservice.NewUserPreferenceService,
|
||||
businessservice.NewAccountService,
|
||||
businessservice.NewBindingService,
|
||||
systemservice.ProviderSet,
|
||||
paymentservice.ProviderSet,
|
||||
integrationservice.ProviderSet,
|
||||
|
||||
Reference in New Issue
Block a user