This commit is contained in:
@@ -741,6 +741,22 @@ func (s *Service) batchGetAllocationsForShop(ctx context.Context, shopID uint, p
|
||||
}
|
||||
|
||||
func (s *Service) toResponseWithAllocation(_ context.Context, pkg *model.Package, allocationMap map[uint]*model.ShopPackageAllocation, seriesAllocationMap map[uint]*model.ShopSeriesAllocation, seriesConfigMap map[uint]*model.OneTimeCommissionConfig) *dto.PackageResponse {
|
||||
var allocation *model.ShopPackageAllocation
|
||||
if allocationMap != nil {
|
||||
allocation = allocationMap[pkg.ID]
|
||||
}
|
||||
resp := BuildResponseForAllocation(pkg, allocation)
|
||||
|
||||
// 填充返佣信息(仅代理用户可见)
|
||||
if pkg.SeriesID > 0 && seriesAllocationMap != nil && seriesConfigMap != nil {
|
||||
s.fillCommissionInfo(resp, pkg.SeriesID, seriesAllocationMap, seriesConfigMap)
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
// BuildResponseForAllocation 构建套餐列表字段,并按店铺授权覆盖价格和上架状态。
|
||||
func BuildResponseForAllocation(pkg *model.Package, allocation *model.ShopPackageAllocation) *dto.PackageResponse {
|
||||
var seriesID *uint
|
||||
if pkg.SeriesID > 0 {
|
||||
seriesID = &pkg.SeriesID
|
||||
@@ -778,29 +794,21 @@ func (s *Service) toResponseWithAllocation(_ context.Context, pkg *model.Package
|
||||
}
|
||||
initPackageExpiryBaseFields(resp, pkg)
|
||||
|
||||
if allocationMap != nil {
|
||||
if allocation, ok := allocationMap[pkg.ID]; ok {
|
||||
resp.CostPrice = allocation.CostPrice
|
||||
resp.RetailPrice = packageprice.AllocationRawRetailPrice(allocation)
|
||||
retailPriceConfigStatus := allocation.RetailPriceConfigStatus
|
||||
resp.RetailPriceConfigStatus = &retailPriceConfigStatus
|
||||
effectiveRetailPrice := packageprice.AllocationEffectiveRetailPrice(allocation)
|
||||
resp.EffectiveRetailPrice = &effectiveRetailPrice
|
||||
profitMargin := effectiveRetailPrice - allocation.CostPrice
|
||||
resp.ProfitMargin = &profitMargin
|
||||
applyAllocationExpiryBase(resp, pkg, allocation)
|
||||
resp.ShelfStatus = allocation.ShelfStatus
|
||||
}
|
||||
if allocation != nil {
|
||||
resp.CostPrice = allocation.CostPrice
|
||||
resp.RetailPrice = packageprice.AllocationRawRetailPrice(allocation)
|
||||
retailPriceConfigStatus := allocation.RetailPriceConfigStatus
|
||||
resp.RetailPriceConfigStatus = &retailPriceConfigStatus
|
||||
effectiveRetailPrice := packageprice.AllocationEffectiveRetailPrice(allocation)
|
||||
resp.EffectiveRetailPrice = &effectiveRetailPrice
|
||||
profitMargin := effectiveRetailPrice - allocation.CostPrice
|
||||
resp.ProfitMargin = &profitMargin
|
||||
applyAllocationExpiryBase(resp, pkg, allocation)
|
||||
resp.ShelfStatus = allocation.ShelfStatus
|
||||
} else {
|
||||
effectiveRetailPrice := packageprice.PackageEffectiveRetailPrice(pkg)
|
||||
resp.EffectiveRetailPrice = &effectiveRetailPrice
|
||||
}
|
||||
|
||||
// 填充返佣信息(仅代理用户可见)
|
||||
if pkg.SeriesID > 0 && seriesAllocationMap != nil && seriesConfigMap != nil {
|
||||
s.fillCommissionInfo(resp, pkg.SeriesID, seriesAllocationMap, seriesConfigMap)
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user