让分销站能按自身能力下调收号比例扩大利润,同时把主站回收比例作为硬边界,避免分站把比例加得比主站更高。 Co-authored-by: Cursor <cursoragent@cursor.com>
90 lines
2.4 KiB
Go
90 lines
2.4 KiB
Go
package listing
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
)
|
|
|
|
func (s *Service) Create(ctx context.Context, ownerID uint64, req CreateRequest, siteCode ...string) (*ListingDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
if !req.AgreedVirtualAssetSale || !req.AgreedSellerAgreement {
|
|
return nil, ErrAgreementRequired
|
|
}
|
|
effectiveSiteCode := ""
|
|
if len(siteCode) > 0 {
|
|
effectiveSiteCode = strings.TrimSpace(siteCode[0])
|
|
}
|
|
delta, onDistribution := s.repo.ResolveReceiveRatioDelta(ctx, 0, effectiveSiteCode)
|
|
if err := s.applyMainSiteReceivePricing(ctx, &req, delta, onDistribution); err != nil {
|
|
return nil, err
|
|
}
|
|
rules, err := s.publishRules(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := validateRequest(req, rules); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := validateRequiredOnlineTime(req); err != nil {
|
|
return nil, err
|
|
}
|
|
cooldown, err := s.publishCooldown(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
reviewRequired, err := s.reviewRequired(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.Create(ctx, ownerID, req, reviewRequired, cooldown, effectiveSiteCode)
|
|
}
|
|
|
|
func (s *Service) Update(ctx context.Context, ownerID uint64, id uint64, req UpdateRequest, siteCode ...string) (*ListingDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
effectiveSiteCode := ""
|
|
if len(siteCode) > 0 {
|
|
effectiveSiteCode = strings.TrimSpace(siteCode[0])
|
|
}
|
|
delta, onDistribution := s.repo.ResolveReceiveRatioDelta(ctx, id, effectiveSiteCode)
|
|
if err := s.applyMainSiteReceivePricing(ctx, &req, delta, onDistribution); err != nil {
|
|
return nil, err
|
|
}
|
|
rules, err := s.publishRules(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := validateRequest(req, rules); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := validateRequiredOnlineTime(req); err != nil {
|
|
return nil, err
|
|
}
|
|
reviewRequired, err := s.reviewRequired(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.Update(ctx, ownerID, id, req, reviewRequired)
|
|
}
|
|
|
|
func (s *Service) SubmitReview(ctx context.Context, ownerID uint64, id uint64) (*ListingDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
reviewRequired, err := s.reviewRequired(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.SubmitReview(ctx, ownerID, id, reviewRequired)
|
|
}
|
|
|
|
func (s *Service) Offline(ctx context.Context, ownerID uint64, id uint64) (*ListingDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.Offline(ctx, ownerID, id)
|
|
}
|