优化套餐变更后网站限流状态

This commit is contained in:
GoEdgeLab
2024-04-12 11:35:52 +08:00
parent e713ae1811
commit 416cf4981d
3 changed files with 53 additions and 7 deletions

View File

@@ -2504,7 +2504,7 @@ func (this *ServerDAO) UpdateServerTrafficLimitStatus(tx *dbs.Tx, serverId int64
} }
if len(oldStatus.UntilDay) > 0 && if len(oldStatus.UntilDay) > 0 &&
oldStatus.UntilDay >= day /** 如果已经限制,且比当前日期长,则无需重复 **/ && oldStatus.UntilDay >= day /** 如果已经限制,且比当前日期长,则无需重复 **/ &&
oldStatus.PlanId == planId /** 套餐无变化 **/ { oldStatus.PlanId == planId {
// no need to change // no need to change
return nil return nil
} }
@@ -2555,7 +2555,7 @@ func (this *ServerDAO) UpdateServersTrafficLimitStatusWithUserPlanId(tx *dbs.Tx,
return nil return nil
} }
// ResetServersTrafficLimitStatusWithPlanId 重置网站限流状态 // ResetServersTrafficLimitStatusWithPlanId 重置某个套餐相关网站限流状态
func (this *ServerDAO) ResetServersTrafficLimitStatusWithPlanId(tx *dbs.Tx, planId int64) error { func (this *ServerDAO) ResetServersTrafficLimitStatusWithPlanId(tx *dbs.Tx, planId int64) error {
return this.Query(tx). return this.Query(tx).
Where("JSON_EXTRACT(trafficLimitStatus, '$.planId')=:planId"). Where("JSON_EXTRACT(trafficLimitStatus, '$.planId')=:planId").
@@ -2632,13 +2632,17 @@ func (this *ServerDAO) UpdateServerUserPlanId(tx *dbs.Tx, serverId int64, userPl
return errors.New("serverId should not be smaller than 0") return errors.New("serverId should not be smaller than 0")
} }
oldClusterId, err := this.Query(tx). oldServerOne, queryErr := SharedServerDAO.
Query(tx).
Pk(serverId). Pk(serverId).
Result("clusterId"). Result("clusterId", "userPlanId").
FindInt64Col(0) Find()
if err != nil { if queryErr != nil || oldServerOne == nil {
return err return queryErr
} }
var oldServer = oldServerOne.(*Server)
var oldClusterId = int64(oldServer.ClusterId)
var oldUserPlanId = int64(oldServer.UserPlanId)
// 取消套餐 // 取消套餐
if userPlanId <= 0 { if userPlanId <= 0 {
@@ -2670,6 +2674,15 @@ func (this *ServerDAO) UpdateServerUserPlanId(tx *dbs.Tx, serverId int64, userPl
if err != nil { if err != nil {
return err return err
} }
// 重置以往的用户套餐状态
if oldUserPlanId > 0 {
err = SharedUserPlanStatDAO.ResetUserPlanStatsWithUserPlanId(tx, oldUserPlanId)
if err != nil {
return err
}
}
err = this.NotifyUpdate(tx, serverId) err = this.NotifyUpdate(tx, serverId)
if err != nil { if err != nil {
return err return err
@@ -2717,6 +2730,21 @@ func (this *ServerDAO) UpdateServerUserPlanId(tx *dbs.Tx, serverId int64, userPl
if err != nil { if err != nil {
return err return err
} }
// 重置以往的用户套餐统计状态
if oldUserPlanId > 0 {
err = SharedUserPlanStatDAO.ResetUserPlanStatsWithUserPlanId(tx, oldUserPlanId)
if err != nil {
return err
}
}
// 重置当前用户套餐统计状态
err = SharedUserPlanStatDAO.ResetUserPlanStatsWithUserPlanId(tx, userPlanId)
if err != nil {
return err
}
err = this.NotifyUpdate(tx, serverId) err = this.NotifyUpdate(tx, serverId)
if err != nil { if err != nil {
return err return err

View File

@@ -0,0 +1,12 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build !plus
package models
import "github.com/iwind/TeaGo/dbs"
// ResetServersTrafficLimitStatusWithUserPlanId 重置用户套餐相关网站限流状态
func (this *ServerDAO) ResetServersTrafficLimitStatusWithUserPlanId(tx *dbs.Tx, userPlanId int64) error {
// stub
return nil
}

View File

@@ -6,5 +6,11 @@ package models
import "github.com/iwind/TeaGo/dbs" import "github.com/iwind/TeaGo/dbs"
func (this *UserPlanStatDAO) IncreaseUserPlanStat(tx *dbs.Tx, userPlanId int64, trafficBytes int64, countRequests int64, countWebsocketConnections int64) error { func (this *UserPlanStatDAO) IncreaseUserPlanStat(tx *dbs.Tx, userPlanId int64, trafficBytes int64, countRequests int64, countWebsocketConnections int64) error {
// stub
return nil
}
func (this *UserPlanStatDAO) ResetUserPlanStatsWithUserPlanId(tx *dbs.Tx, userPlanId int64) error {
// stub
return nil return nil
} }