feat: 接入旧站管理端并完整迁移后台能力
This commit is contained in:
@@ -3,6 +3,8 @@ package listing
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"hfb_jysh/backend/internal/modules/qualityowner"
|
||||
)
|
||||
|
||||
func (s *Service) Create(ctx context.Context, ownerID uint64, req CreateRequest, siteCode ...string) (*ListingDTO, error) {
|
||||
@@ -16,6 +18,9 @@ func (s *Service) Create(ctx context.Context, ownerID uint64, req CreateRequest,
|
||||
if len(siteCode) > 0 {
|
||||
effectiveSiteCode = strings.TrimSpace(siteCode[0])
|
||||
}
|
||||
if err := s.applyPublishEntitlements(ctx, ownerID, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
delta, onDistribution := s.repo.resolveSiteReceiveCostDelta(ctx, 0, effectiveSiteCode)
|
||||
if err := s.applyMainSiteReceivePricing(ctx, &req, 0, delta, onDistribution); err != nil {
|
||||
return nil, err
|
||||
@@ -49,6 +54,9 @@ func (s *Service) Update(ctx context.Context, ownerID uint64, id uint64, req Upd
|
||||
if len(siteCode) > 0 {
|
||||
effectiveSiteCode = strings.TrimSpace(siteCode[0])
|
||||
}
|
||||
if err := s.applyPublishEntitlements(ctx, ownerID, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
delta, onDistribution := s.repo.resolveSiteReceiveCostDelta(ctx, id, effectiveSiteCode)
|
||||
if err := s.applyMainSiteReceivePricing(ctx, &req, 0, delta, onDistribution); err != nil {
|
||||
return nil, err
|
||||
@@ -70,6 +78,46 @@ func (s *Service) Update(ctx context.Context, ownerID uint64, id uint64, req Upd
|
||||
return s.repo.Update(ctx, ownerID, id, req, reviewRequired)
|
||||
}
|
||||
|
||||
func (s *Service) applyPublishEntitlements(ctx context.Context, ownerID uint64, req *CreateRequest) error {
|
||||
req.CompensationPlan = strings.TrimSpace(req.CompensationPlan)
|
||||
if req.CompensationPlan == "" {
|
||||
req.CompensationPlan = CompensationPlanNormal
|
||||
}
|
||||
if req.CompensationPlan != CompensationPlanNormal && req.CompensationPlan != CompensationPlanInsurance {
|
||||
return ErrInvalidInput
|
||||
}
|
||||
|
||||
isQualityOwner, err := s.repo.IsQualityOwner(ctx, ownerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if req.IsPremium && !isQualityOwner {
|
||||
return ErrPremiumOwnerRequired
|
||||
}
|
||||
req.OwnerIsQualityOwner = isQualityOwner
|
||||
|
||||
req.InsuranceFeeBps = 0
|
||||
if req.CompensationPlan != CompensationPlanInsurance {
|
||||
return nil
|
||||
}
|
||||
rules := qualityowner.DefaultRules()
|
||||
if s.config != nil {
|
||||
value, err := s.config.FindValue(ctx, qualityowner.ConfigKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rules, err = qualityowner.ParseConfigValue(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
req.InsuranceFeeBps = rules.InsuranceFeeBps
|
||||
if req.IsPremium && isQualityOwner {
|
||||
req.InsuranceFeeBps = rules.PremiumInsuranceFeeBps
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) SubmitReview(ctx context.Context, ownerID uint64, id uint64) (*ListingDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
|
||||
Reference in New Issue
Block a user