七月迭代短暂完结,还有很多后端的关键东西没有弄,这是一版赶时间做的东西
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m26s

This commit is contained in:
2026-07-25 17:06:58 +08:00
parent ad9f613dd6
commit 73f5125d3d
249 changed files with 17137 additions and 877 deletions

View File

@@ -701,6 +701,9 @@ func (s *ActivationService) InvalidatePackagesForRefund(ctx context.Context, ass
if orderID == 0 {
return errors.New(errors.CodeInvalidParam, "无效的订单ID")
}
if assetType != constants.AssetTypeIotCard && assetType != constants.AssetTypeDevice {
return errors.New(errors.CodeInvalidParam, "无效的资产类型")
}
validStatuses := []int{
constants.PackageUsageStatusPending,
@@ -708,21 +711,9 @@ func (s *ActivationService) InvalidatePackagesForRefund(ctx context.Context, ass
constants.PackageUsageStatusDepleted,
}
newAssetQuery := func() (*gorm.DB, error) {
query := s.db.WithContext(ctx).Model(&model.PackageUsage{})
switch assetType {
case "iot_card":
return query.Where("iot_card_id = ?", assetID), nil
case "device":
return query.Where("device_id = ?", assetID), nil
default:
return nil, errors.New(errors.CodeInvalidParam, "无效的资产类型")
}
}
baseQuery, err := newAssetQuery()
if err != nil {
return err
}
// 换货会把套餐使用记录迁移到新资产,但原订单与套餐使用记录的关联保持不变。
// 因此退款必须以订单和套餐使用记录为权威定位键,不能再用旧资产 ID 缩小查询范围。
baseQuery := s.db.WithContext(ctx).Model(&model.PackageUsage{})
var targets []model.PackageUsage
if packageUsageID != nil && *packageUsageID > 0 {
@@ -772,11 +763,7 @@ func (s *ActivationService) InvalidatePackagesForRefund(ctx context.Context, ass
if len(mainUsageIDs) > 0 {
var addons []model.PackageUsage
addonQuery, queryErr := newAssetQuery()
if queryErr != nil {
return queryErr
}
if err := addonQuery.
if err := s.db.WithContext(ctx).Model(&model.PackageUsage{}).
Where("master_usage_id IN ?", mainUsageIDs).
Where("status IN ?", validStatuses).
Find(&addons).Error; err != nil {