feat: 客户端接口数据模型基础准备
- 新增资产状态、订单来源、操作人类型、实名链接类型常量 - 8个模型新增字段(asset_status/generation/source/retail_price等) - 数据库迁移000082:7张表15+字段,含存量retail_price回填 - BUG-1修复:代理零售价渠道隔离,cost_price分配锁定 - BUG-2修复:一次性佣金仅客户端订单触发 - BUG-4修复:充值回调Store操作纳入事务 - 新增资产手动停用接口(PATCH /iot-cards/:id/deactivate、/devices/:id/deactivate) - Carrier管理新增实名链接配置 - 后台订单generation写时快照 - BatchUpdatePricing支持retail_price调价目标 - 清理全部H5旧接口和个人客户旧登录方法
This commit is contained in:
@@ -133,44 +133,57 @@ func (s *Service) validatePackages(ctx context.Context, packageIDs []uint, serie
|
||||
}
|
||||
|
||||
if sellerShopID > 0 {
|
||||
// 代理渠道:检查卖家代理的 allocation.shelf_status,不检查 package.shelf_status
|
||||
if err := s.validateAgentShelfStatus(ctx, sellerShopID, pkgID); err != nil {
|
||||
return nil, 0, err
|
||||
// 代理渠道:检查上架状态并获取分配记录,使用零售价
|
||||
allocation, allocErr := s.validateAgentAllocation(ctx, sellerShopID, pkgID)
|
||||
if allocErr != nil {
|
||||
return nil, 0, allocErr
|
||||
}
|
||||
// 零售价低于成本价时视为不可购买,防止亏损售卖
|
||||
if allocation.RetailPrice < allocation.CostPrice {
|
||||
return nil, 0, errors.New(errors.CodeInvalidParam, "套餐价格配置异常,暂不可购买")
|
||||
}
|
||||
totalPrice += allocation.RetailPrice
|
||||
} else {
|
||||
// 平台自营渠道:检查 package.shelf_status
|
||||
if pkg.ShelfStatus != constants.ShelfStatusOn {
|
||||
return nil, 0, errors.New(errors.CodeInvalidParam, "套餐已下架")
|
||||
}
|
||||
totalPrice += pkg.SuggestedRetailPrice
|
||||
}
|
||||
|
||||
packages = append(packages, pkg)
|
||||
totalPrice += pkg.SuggestedRetailPrice
|
||||
}
|
||||
|
||||
return packages, totalPrice, nil
|
||||
}
|
||||
|
||||
// validateAgentShelfStatus 校验卖家代理的分配记录上架状态
|
||||
func (s *Service) validateAgentShelfStatus(ctx context.Context, sellerShopID, packageID uint) error {
|
||||
// 使用不带数据权限过滤的查询,避免 buyer ctx 的权限限制干扰系统级校验
|
||||
// validateAgentAllocation 校验卖家代理的分配记录上架状态,并返回分配记录
|
||||
func (s *Service) validateAgentAllocation(ctx context.Context, sellerShopID, packageID uint) (*model.ShopPackageAllocation, error) {
|
||||
allocation, err := s.packageAllocationStore.GetByShopAndPackageForSystem(ctx, sellerShopID, packageID)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return errors.New(errors.CodeInvalidParam, "套餐已下架")
|
||||
return nil, errors.New(errors.CodeInvalidParam, "套餐已下架")
|
||||
}
|
||||
return errors.Wrap(errors.CodeInternalError, err, "查询套餐分配记录失败")
|
||||
return nil, errors.Wrap(errors.CodeInternalError, err, "查询套餐分配记录失败")
|
||||
}
|
||||
|
||||
if allocation.ShelfStatus != constants.ShelfStatusOn {
|
||||
return errors.New(errors.CodeInvalidParam, "套餐已下架")
|
||||
return nil, errors.New(errors.CodeInvalidParam, "套餐已下架")
|
||||
}
|
||||
|
||||
return nil
|
||||
return allocation, nil
|
||||
}
|
||||
|
||||
func (s *Service) GetPurchasePrice(ctx context.Context, pkg *model.Package, buyerType string) int64 {
|
||||
return pkg.SuggestedRetailPrice
|
||||
// GetPurchasePrice 获取购买价格
|
||||
// 代理渠道(sellerShopID > 0)返回 allocation.RetailPrice,平台渠道返回 Package.SuggestedRetailPrice
|
||||
func (s *Service) GetPurchasePrice(ctx context.Context, pkg *model.Package, sellerShopID uint) (int64, error) {
|
||||
if sellerShopID > 0 {
|
||||
allocation, err := s.packageAllocationStore.GetByShopAndPackageForSystem(ctx, sellerShopID, pkg.ID)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(errors.CodeInternalError, err, "查询套餐分配记录失败")
|
||||
}
|
||||
return allocation.RetailPrice, nil
|
||||
}
|
||||
return pkg.SuggestedRetailPrice, nil
|
||||
}
|
||||
|
||||
// ValidateAdminOfflineCardPurchase 后台 offline 订单专用卡验证
|
||||
|
||||
Reference in New Issue
Block a user