fix: 套餐激活和流量重置后注入并调用复机回调
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -13,11 +13,10 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// ResumeCallback 任务 24.7: 复机回调接口
|
||||
// 用于在套餐激活后触发自动复机
|
||||
// ResumeCallback 复机回调接口
|
||||
// 用于在套餐激活或流量重置后触发自动复机
|
||||
type ResumeCallback interface {
|
||||
// ResumeCardIfStopped 购买套餐后自动复机
|
||||
ResumeCardIfStopped(ctx context.Context, cardID uint) error
|
||||
ResumeCardIfStopped(ctx context.Context, carrierType string, carrierID uint) error
|
||||
}
|
||||
|
||||
type ActivationService struct {
|
||||
@@ -149,16 +148,15 @@ func (s *ActivationService) ActivateByRealname(ctx context.Context, carrierType
|
||||
zap.Time("activated_at", activatedAt),
|
||||
zap.Time("expires_at", expiresAt))
|
||||
|
||||
// 任务 24.7: 在套餐激活后触发自动复机
|
||||
if s.resumeCallback != nil && carrierType == "iot_card" {
|
||||
go func(cardID uint) {
|
||||
resumeCtx := context.Background()
|
||||
if err := s.resumeCallback.ResumeCardIfStopped(resumeCtx, cardID); err != nil {
|
||||
s.logger.Error("自动复机失败",
|
||||
zap.Uint("card_id", cardID),
|
||||
if s.resumeCallback != nil {
|
||||
go func(ct string, cid uint) {
|
||||
if err := s.resumeCallback.ResumeCardIfStopped(context.Background(), ct, cid); err != nil {
|
||||
s.logger.Error("实名激活后自动复机失败",
|
||||
zap.String("carrier_type", ct),
|
||||
zap.Uint("carrier_id", cid),
|
||||
zap.Error(err))
|
||||
}
|
||||
}(carrierID)
|
||||
}(carrierType, carrierID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,16 +308,15 @@ func (s *ActivationService) activateNextMainPackage(ctx context.Context, tx *gor
|
||||
zap.Time("activated_at", activatedAt),
|
||||
zap.Time("expires_at", expiresAt))
|
||||
|
||||
// 任务 24.7: 在套餐激活后触发自动复机
|
||||
if s.resumeCallback != nil && carrierType == "iot_card" {
|
||||
go func(cardID uint) {
|
||||
resumeCtx := context.Background()
|
||||
if err := s.resumeCallback.ResumeCardIfStopped(resumeCtx, cardID); err != nil {
|
||||
if s.resumeCallback != nil {
|
||||
go func(ct string, cid uint) {
|
||||
if err := s.resumeCallback.ResumeCardIfStopped(context.Background(), ct, cid); err != nil {
|
||||
s.logger.Error("排队激活后自动复机失败",
|
||||
zap.Uint("card_id", cardID),
|
||||
zap.String("carrier_type", ct),
|
||||
zap.Uint("carrier_id", cid),
|
||||
zap.Error(err))
|
||||
}
|
||||
}(carrierID)
|
||||
}(carrierType, carrierID)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user