实现套餐生效条件覆盖与购买快照

This commit is contained in:
2026-07-22 20:51:12 +09:00
parent c7f8b4c702
commit 9818537239
30 changed files with 1092 additions and 149 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
packagepkg "github.com/break/junhong_cmp_fiber/internal/service/package"
"github.com/break/junhong_cmp_fiber/internal/store"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
@@ -185,12 +186,18 @@ func (s *Service) buildGrantResponse(ctx context.Context, allocation *model.Shop
continue
}
packages = append(packages, dto.ShopSeriesGrantPackageItem{
PackageID: pa.PackageID,
PackageName: pkg.PackageName,
PackageCode: pkg.PackageCode,
CostPrice: pa.CostPrice,
ShelfStatus: pa.ShelfStatus,
Status: pa.Status,
PackageID: pa.PackageID,
PackageName: pkg.PackageName,
PackageCode: pkg.PackageCode,
CostPrice: pa.CostPrice,
ShelfStatus: pa.ShelfStatus,
Status: pa.Status,
DefaultExpiryBase: pkg.ExpiryBase,
DefaultExpiryBaseName: packagepkg.ExpiryBaseName(pkg.ExpiryBase),
ExpiryBaseOverride: pa.ExpiryBaseOverride,
ExpiryBaseOverrideName: packagepkg.ExpiryBaseOverrideName(pa.ExpiryBaseOverride),
EffectiveExpiryBase: packagepkg.EffectiveExpiryBase(pkg, pa),
EffectiveExpiryBaseName: packagepkg.ExpiryBaseName(packagepkg.EffectiveExpiryBase(pkg, pa)),
})
}
resp.Packages = packages
@@ -201,6 +208,10 @@ func (s *Service) buildGrantResponse(ctx context.Context, allocation *model.Shop
// Create 创建系列授权
// POST /api/admin/shop-series-grants
func (s *Service) Create(ctx context.Context, req *dto.CreateShopSeriesGrantRequest) (*dto.ShopSeriesGrantResponse, error) {
expiryBaseOverride, err := packagepkg.ValidateExpiryBaseOverride(req.ExpiryBaseOverride, req.ExpiryBaseOverrideSet)
if err != nil {
return nil, err
}
operatorID := middleware.GetUserIDFromContext(ctx)
operatorShopID := middleware.GetShopIDFromContext(ctx)
operatorType := middleware.GetUserTypeFromContext(ctx)
@@ -339,15 +350,16 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateShopSeriesGrantRequ
}
}
pkgAlloc := &model.ShopPackageAllocation{
ShopID: req.ShopID,
PackageID: item.PackageID,
AllocatorShopID: allocatorShopID,
CostPrice: item.CostPrice,
RetailPrice: pkg.SuggestedRetailPrice,
ShopID: req.ShopID,
PackageID: item.PackageID,
AllocatorShopID: allocatorShopID,
CostPrice: item.CostPrice,
RetailPrice: pkg.SuggestedRetailPrice,
RetailPriceConfigStatus: pkg.PriceConfigStatus,
SeriesAllocationID: &allocation.ID,
Status: constants.StatusEnabled,
ShelfStatus: constants.ShelfStatusOn,
SeriesAllocationID: &allocation.ID,
ExpiryBaseOverride: expiryBaseOverride,
Status: constants.StatusEnabled,
ShelfStatus: constants.ShelfStatusOn,
}
pkgAlloc.Creator = operatorID
pkgAlloc.Updater = operatorID
@@ -600,6 +612,10 @@ func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdateShopSeries
// ManagePackages 管理授权套餐(新增/更新/删除)
// PUT /api/admin/shop-series-grants/:id/packages
func (s *Service) ManagePackages(ctx context.Context, id uint, req *dto.ManageGrantPackagesRequest) (*dto.ShopSeriesGrantResponse, error) {
expiryBaseOverride, err := packagepkg.ValidateExpiryBaseOverride(req.ExpiryBaseOverride, req.ExpiryBaseOverrideSet)
if err != nil {
return nil, err
}
operatorID := middleware.GetUserIDFromContext(ctx)
operatorShopID := middleware.GetShopIDFromContext(ctx)
@@ -677,15 +693,16 @@ func (s *Service) ManagePackages(ctx context.Context, id uint, req *dto.ManageGr
}
}
pkgAlloc := &model.ShopPackageAllocation{
ShopID: allocation.ShopID,
PackageID: item.PackageID,
AllocatorShopID: allocation.AllocatorShopID,
CostPrice: item.CostPrice,
RetailPrice: pkg.SuggestedRetailPrice,
ShopID: allocation.ShopID,
PackageID: item.PackageID,
AllocatorShopID: allocation.AllocatorShopID,
CostPrice: item.CostPrice,
RetailPrice: pkg.SuggestedRetailPrice,
RetailPriceConfigStatus: pkg.PriceConfigStatus,
SeriesAllocationID: &allocation.ID,
Status: constants.StatusEnabled,
ShelfStatus: constants.ShelfStatusOn,
SeriesAllocationID: &allocation.ID,
ExpiryBaseOverride: expiryBaseOverride,
Status: constants.StatusEnabled,
ShelfStatus: constants.ShelfStatusOn,
}
pkgAlloc.Creator = operatorID
pkgAlloc.Updater = operatorID