重构: 将卡/设备的套餐系列绑定从分配ID改为系列ID
- 数据库: 重命名 series_allocation_id → series_id - Model: IotCard 和 Device 字段重命名 - DTO: 所有请求/响应字段统一为 series_id - Store: 方法重命名,新增 GetByShopAndSeries 查询 - Service: 业务逻辑优化,系列验证和权限验证分离 - 测试: 更新所有测试用例,新增 shop_series_allocation_store_test.go - 文档: 更新 API 文档说明参数变更 BREAKING CHANGE: API 参数从 series_allocation_id 改为 series_id
This commit is contained in:
@@ -374,7 +374,8 @@ func (s *Service) checkForceRechargeRequirement(ctx context.Context, resourceTyp
|
||||
Message: "无强充要求,可自由充值",
|
||||
}
|
||||
|
||||
var seriesAllocationID *uint
|
||||
var seriesID *uint
|
||||
var shopID *uint
|
||||
var accumulatedRecharge int64
|
||||
var firstCommissionPaid bool
|
||||
|
||||
@@ -387,7 +388,8 @@ func (s *Service) checkForceRechargeRequirement(ctx context.Context, resourceTyp
|
||||
}
|
||||
return nil, errors.Wrap(errors.CodeDatabaseError, err, "查询IoT卡失败")
|
||||
}
|
||||
seriesAllocationID = card.SeriesAllocationID
|
||||
seriesID = card.SeriesID
|
||||
shopID = card.ShopID
|
||||
accumulatedRecharge = card.AccumulatedRecharge
|
||||
firstCommissionPaid = card.FirstCommissionPaid
|
||||
} else if resourceType == "device" {
|
||||
@@ -398,7 +400,8 @@ func (s *Service) checkForceRechargeRequirement(ctx context.Context, resourceTyp
|
||||
}
|
||||
return nil, errors.Wrap(errors.CodeDatabaseError, err, "查询设备失败")
|
||||
}
|
||||
seriesAllocationID = device.SeriesAllocationID
|
||||
seriesID = device.SeriesID
|
||||
shopID = device.ShopID
|
||||
accumulatedRecharge = device.AccumulatedRecharge
|
||||
firstCommissionPaid = device.FirstCommissionPaid
|
||||
}
|
||||
@@ -406,13 +409,13 @@ func (s *Service) checkForceRechargeRequirement(ctx context.Context, resourceTyp
|
||||
result.CurrentAccumulated = accumulatedRecharge
|
||||
result.FirstCommissionPaid = firstCommissionPaid
|
||||
|
||||
// 2. 如果没有系列分配,无强充要求
|
||||
if seriesAllocationID == nil {
|
||||
// 2. 如果没有系列ID或店铺ID,无强充要求
|
||||
if seriesID == nil || shopID == nil {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// 3. 查询系列分配配置
|
||||
allocation, err := s.shopSeriesAllocationStore.GetByID(ctx, *seriesAllocationID)
|
||||
allocation, err := s.shopSeriesAllocationStore.GetByShopAndSeries(ctx, *shopID, *seriesID)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return result, nil
|
||||
@@ -483,7 +486,7 @@ func (s *Service) updateAccumulatedRechargeInTx(ctx context.Context, tx *gorm.DB
|
||||
// triggerOneTimeCommissionIfNeededInTx 触发一次性佣金(事务内使用)
|
||||
// 检查是否满足一次性佣金触发条件,满足则创建佣金记录并入账
|
||||
func (s *Service) triggerOneTimeCommissionIfNeededInTx(ctx context.Context, tx *gorm.DB, resourceType string, resourceID uint, rechargeAmount int64, userID uint) error {
|
||||
var seriesAllocationID *uint
|
||||
var seriesID *uint
|
||||
var accumulatedRecharge int64
|
||||
var firstCommissionPaid bool
|
||||
var shopID *uint
|
||||
@@ -494,7 +497,7 @@ func (s *Service) triggerOneTimeCommissionIfNeededInTx(ctx context.Context, tx *
|
||||
if err := tx.First(&card, resourceID).Error; err != nil {
|
||||
return errors.Wrap(errors.CodeDatabaseError, err, "查询IoT卡失败")
|
||||
}
|
||||
seriesAllocationID = card.SeriesAllocationID
|
||||
seriesID = card.SeriesID
|
||||
accumulatedRecharge = card.AccumulatedRecharge
|
||||
firstCommissionPaid = card.FirstCommissionPaid
|
||||
shopID = card.ShopID
|
||||
@@ -503,14 +506,14 @@ func (s *Service) triggerOneTimeCommissionIfNeededInTx(ctx context.Context, tx *
|
||||
if err := tx.First(&device, resourceID).Error; err != nil {
|
||||
return errors.Wrap(errors.CodeDatabaseError, err, "查询设备失败")
|
||||
}
|
||||
seriesAllocationID = device.SeriesAllocationID
|
||||
seriesID = device.SeriesID
|
||||
accumulatedRecharge = device.AccumulatedRecharge
|
||||
firstCommissionPaid = device.FirstCommissionPaid
|
||||
shopID = device.ShopID
|
||||
}
|
||||
|
||||
// 2. 如果没有系列分配或已发放佣金,跳过
|
||||
if seriesAllocationID == nil || firstCommissionPaid {
|
||||
// 2. 如果没有系列ID或已发放佣金,跳过
|
||||
if seriesID == nil || firstCommissionPaid {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -524,7 +527,7 @@ func (s *Service) triggerOneTimeCommissionIfNeededInTx(ctx context.Context, tx *
|
||||
}
|
||||
|
||||
// 4. 查询系列分配配置
|
||||
allocation, err := s.shopSeriesAllocationStore.GetByID(ctx, *seriesAllocationID)
|
||||
allocation, err := s.shopSeriesAllocationStore.GetByShopAndSeries(ctx, *shopID, *seriesID)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user