Sfoglia il codice sorgente

feat(gameShield): 添加游戏盾牌过期时间字段并更新相关逻辑

- 在 GameShield 模型中添加 ExpireTime 字段,用于存储过期时间戳
- 更新 UpdateGameShieldByHostId 方法,使用 req.HostId 替代 req.Id
- 在 UpdateGameShieldByHostId 方法中使用 req作为参数,而不是空的 GameShield 结构体
- 在 gameshieldbackend.go 中添加获取游戏盾牌下一次到期日期的逻辑,并更新数据库记录
fusu 3 mesi fa
parent
commit
af681733cd

+ 1 - 0
internal/model/gameshield.go

@@ -13,6 +13,7 @@ type GameShield struct {
 	HostId         string
 	Checked        int
 	DunName        string
+	ExpireTime     int64 `gorm:"type:bigint"`
 }
 
 func (m *GameShield) TableName() string {

+ 1 - 1
internal/repository/gameshield.go

@@ -128,7 +128,7 @@ func (r *gameShieldRepository) GetGameShieldRuleIdByAppName(ctx context.Context,
 }
 
 func (r *gameShieldRepository) UpdateGameShieldByHostId(ctx context.Context, req *model.GameShield) error {
-	if err := r.DB(ctx).Where("host_id = ?", req.Id).Updates(&model.GameShield{}).Error; err != nil {
+	if err := r.DB(ctx).Where("host_id = ?", req.HostId).Updates(req).Error; err != nil {
 		return err
 	}
 	return nil

+ 7 - 2
internal/service/gameshieldbackend.go

@@ -142,10 +142,15 @@ func (s *gameShieldBackendService) GameShieldBackend(ctx context.Context, req *v
 	if err != nil {
 		return "", 0, err
 	}
-	if err := s.gameShieldRepository.UpdateGameShieldByHostId(ctx, &model.GameShield{Id: req.HostId, Key: KeyAndField.Key}); err != nil {
+	timeBase, err := s.gameShieldRepository.GetGameShieldNextduedate(ctx, int64(req.Uid), strconv.Itoa(req.HostId))
+	if err != nil {
+		return "", 0, err
+	}
+	timestampSec, err := strconv.ParseInt(timeBase, 10, 64)
+	if err != nil {
 		return "", 0, err
 	}
-	if res, err = s.shieldService.GetKeyAndEditGameShield(ctx, strconv.Itoa(req.HostId), require.DunName); err != nil {
+	if err := s.gameShieldRepository.UpdateGameShieldByHostId(ctx, &model.GameShield{HostId: strconv.Itoa(req.HostId), Key: KeyAndField.Key, ExpireTime: timestampSec}); err != nil {
 		return "", 0, err
 	}
 	return res, count, nil

+ 1 - 0
internal/task/gameShield.go

@@ -0,0 +1 @@
+package task