修复设备套餐流量不同步的问题
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m32s

This commit is contained in:
2026-04-22 18:04:53 +08:00
parent 6eb6d381f7
commit a207c51bfb
8 changed files with 182 additions and 42 deletions

View File

@@ -35,7 +35,7 @@ type PollingCallback interface {
// 用于在手动刷新流量后触发套餐扣减,避免循环依赖
type DataDeductor interface {
// DeductDataUsage 按优先级扣减套餐流量
DeductDataUsage(ctx context.Context, carrierType string, carrierID uint, usageMB int64) error
DeductDataUsage(ctx context.Context, carrierType string, carrierID uint, usageMB float64) error
}
type Service struct {
@@ -279,6 +279,7 @@ func (s *Service) toStandaloneResponse(card *model.IotCard, shopMap map[uint]str
NetworkStatusName: constants.GetNetworkStatusName(card.NetworkStatus),
DataUsageMB: card.DataUsageMB,
CurrentMonthUsageMB: card.CurrentMonthUsageMB,
LastGatewayReadingMB: card.LastGatewayReadingMB,
CurrentMonthStartDate: card.CurrentMonthStartDate,
LastMonthTotalMB: card.LastMonthTotalMB,
LastDataCheckAt: card.LastDataCheckAt,
@@ -884,7 +885,7 @@ func (s *Service) RefreshCardDataFromGateway(ctx context.Context, iccid string)
// 有增量时触发套餐流量扣减
if flowIncrementMB > 0 && s.dataDeductor != nil {
if err := s.dataDeductor.DeductDataUsage(ctx, "iot_card", card.ID, int64(flowIncrementMB)); err != nil {
if err := s.dataDeductor.DeductDataUsage(ctx, constants.AssetTypeIotCard, card.ID, flowIncrementMB); err != nil {
s.logger.Warn("手动刷新:套餐流量扣减失败",
zap.Uint("card_id", card.ID),
zap.Float64("increment_mb", flowIncrementMB),