优化后台创建订单的代理套餐下架提示
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m59s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m59s
This commit is contained in:
@@ -133,12 +133,15 @@ func (s *Service) CreateAdminOrder(ctx context.Context, req *dto.CreateAdminOrde
|
|||||||
var orderType string
|
var orderType string
|
||||||
var iotCardID *uint
|
var iotCardID *uint
|
||||||
var deviceID *uint
|
var deviceID *uint
|
||||||
|
var resourceShopID *uint
|
||||||
if resolvedCard != nil {
|
if resolvedCard != nil {
|
||||||
orderType = model.OrderTypeSingleCard
|
orderType = model.OrderTypeSingleCard
|
||||||
iotCardID = &resolvedCard.ID
|
iotCardID = &resolvedCard.ID
|
||||||
|
resourceShopID = resolvedCard.ShopID
|
||||||
} else {
|
} else {
|
||||||
orderType = model.OrderTypeDevice
|
orderType = model.OrderTypeDevice
|
||||||
deviceID = &resolvedDevice.ID
|
deviceID = &resolvedDevice.ID
|
||||||
|
resourceShopID = resolvedDevice.ShopID
|
||||||
}
|
}
|
||||||
|
|
||||||
var validationResult *purchase_validation.PurchaseValidationResult
|
var validationResult *purchase_validation.PurchaseValidationResult
|
||||||
@@ -159,7 +162,7 @@ func (s *Service) CreateAdminOrder(ctx context.Context, req *dto.CreateAdminOrde
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, rewriteAdminAgentPackageOffShelfError(err, resourceShopID, req.PaymentMethod != model.PaymentMethodOffline)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validatePackageTypeMixFromPackages(validationResult.Packages); err != nil {
|
if err := validatePackageTypeMixFromPackages(validationResult.Packages); err != nil {
|
||||||
@@ -189,13 +192,10 @@ func (s *Service) CreateAdminOrder(ctx context.Context, req *dto.CreateAdminOrde
|
|||||||
userID := middleware.GetUserIDFromContext(ctx)
|
userID := middleware.GetUserIDFromContext(ctx)
|
||||||
|
|
||||||
// 提取资源所属店铺ID
|
// 提取资源所属店铺ID
|
||||||
var resourceShopID *uint
|
|
||||||
var seriesID *uint
|
var seriesID *uint
|
||||||
if validationResult.Card != nil {
|
if validationResult.Card != nil {
|
||||||
resourceShopID = validationResult.Card.ShopID
|
|
||||||
seriesID = validationResult.Card.SeriesID
|
seriesID = validationResult.Card.SeriesID
|
||||||
} else if validationResult.Device != nil {
|
} else if validationResult.Device != nil {
|
||||||
resourceShopID = validationResult.Device.ShopID
|
|
||||||
seriesID = validationResult.Device.SeriesID
|
seriesID = validationResult.Device.SeriesID
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ func (s *Service) CreateAdminOrder(ctx context.Context, req *dto.CreateAdminOrde
|
|||||||
}
|
}
|
||||||
itemUnitPriceMap, retailTotalAmount, err := s.buildRetailPriceMap(ctx, validationResult.Packages, sellerShopIDValue)
|
itemUnitPriceMap, retailTotalAmount, err := s.buildRetailPriceMap(ctx, validationResult.Packages, sellerShopIDValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, rewriteAdminAgentPackageOffShelfError(err, resourceShopID, sellerShopIDValue > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化订单字段
|
// 初始化订单字段
|
||||||
@@ -462,6 +462,23 @@ func (s *Service) CreateAdminOrder(ctx context.Context, req *dto.CreateAdminOrde
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func rewriteAdminAgentPackageOffShelfError(err error, resourceShopID *uint, shouldRewrite bool) error {
|
||||||
|
if err == nil || !shouldRewrite || resourceShopID == nil || *resourceShopID == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
appErr, ok := err.(*errors.AppError)
|
||||||
|
if !ok {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if appErr.Code == errors.CodeInvalidParam && appErr.Message == "套餐已下架" {
|
||||||
|
return errors.New(errors.CodeInvalidParam, "该代理已经下架该套餐,让代理上架该套餐后购买")
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// CreateH5Order H5 端订单创建(支持 wallet/wechat/alipay,支持待支付状态)
|
// CreateH5Order H5 端订单创建(支持 wallet/wechat/alipay,支持待支付状态)
|
||||||
// 保留原 Create() 方法的完整逻辑,H5 端行为不变
|
// 保留原 Create() 方法的完整逻辑,H5 端行为不变
|
||||||
// POST /api/h5/orders
|
// POST /api/h5/orders
|
||||||
|
|||||||
Reference in New Issue
Block a user