fix: stopCards 停机时补充写入 stop_reason 和 stopped_at 字段

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-03-31 18:11:48 +08:00
parent cf602ab5be
commit bb5a5ec6ef

View File

@@ -365,7 +365,7 @@ func (h *PollingHandler) stopCardByUsageExhausted(ctx context.Context, card *mod
updates := map[string]any{
"network_status": 0, // 停机
"stopped_at": now,
"stop_reason": "套餐流量耗尽自动停机",
"stop_reason": constants.StopReasonTrafficExhausted,
"updated_at": now,
}
if err := h.db.Model(&model.IotCard{}).
@@ -686,12 +686,13 @@ func (h *PollingHandler) stopCards(ctx context.Context, cards []*model.IotCard,
zap.String("iccid", card.ICCID),
zap.String("reason", "套餐超额"))
// 更新数据库:卡的网络状态
now := time.Now()
if err := h.db.Model(&model.IotCard{}).
Where("id = ?", card.ID).
Updates(map[string]any{
"network_status": 0, // 停机
"network_status": 0,
"stopped_at": now,
"stop_reason": constants.StopReasonTrafficExhausted,
"updated_at": now,
}).Error; err != nil {
h.logger.Error("更新卡状态失败", zap.Uint("card_id", card.ID), zap.Error(err))
@@ -1018,7 +1019,7 @@ func (h *PollingHandler) HandleProtectConsistencyCheck(ctx context.Context, t *a
h.db.Model(&model.IotCard{}).Where("id = ?", card.ID).Updates(map[string]any{
"network_status": constants.NetworkStatusOffline,
"stopped_at": time.Now(),
"stop_reason": "保护期一致性检查自动停机",
"stop_reason": constants.StopReasonProtectPeriod,
})
h.updateCardCache(ctx, card.ID, map[string]any{"network_status": constants.NetworkStatusOffline})
return nil