mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 23:20:26 +08:00
优化套餐变更后网站限流状态
This commit is contained in:
@@ -2504,7 +2504,7 @@ func (this *ServerDAO) UpdateServerTrafficLimitStatus(tx *dbs.Tx, serverId int64
|
||||
}
|
||||
if len(oldStatus.UntilDay) > 0 &&
|
||||
oldStatus.UntilDay >= day /** 如果已经限制,且比当前日期长,则无需重复 **/ &&
|
||||
oldStatus.PlanId == planId /** 套餐无变化 **/ {
|
||||
oldStatus.PlanId == planId {
|
||||
// no need to change
|
||||
return nil
|
||||
}
|
||||
@@ -2555,7 +2555,7 @@ func (this *ServerDAO) UpdateServersTrafficLimitStatusWithUserPlanId(tx *dbs.Tx,
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResetServersTrafficLimitStatusWithPlanId 重置网站限流状态
|
||||
// ResetServersTrafficLimitStatusWithPlanId 重置某个套餐相关网站限流状态
|
||||
func (this *ServerDAO) ResetServersTrafficLimitStatusWithPlanId(tx *dbs.Tx, planId int64) error {
|
||||
return this.Query(tx).
|
||||
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")
|
||||
}
|
||||
|
||||
oldClusterId, err := this.Query(tx).
|
||||
oldServerOne, queryErr := SharedServerDAO.
|
||||
Query(tx).
|
||||
Pk(serverId).
|
||||
Result("clusterId").
|
||||
FindInt64Col(0)
|
||||
if err != nil {
|
||||
return err
|
||||
Result("clusterId", "userPlanId").
|
||||
Find()
|
||||
if queryErr != nil || oldServerOne == nil {
|
||||
return queryErr
|
||||
}
|
||||
var oldServer = oldServerOne.(*Server)
|
||||
var oldClusterId = int64(oldServer.ClusterId)
|
||||
var oldUserPlanId = int64(oldServer.UserPlanId)
|
||||
|
||||
// 取消套餐
|
||||
if userPlanId <= 0 {
|
||||
@@ -2670,6 +2674,15 @@ func (this *ServerDAO) UpdateServerUserPlanId(tx *dbs.Tx, serverId int64, userPl
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 重置以往的用户套餐状态
|
||||
if oldUserPlanId > 0 {
|
||||
err = SharedUserPlanStatDAO.ResetUserPlanStatsWithUserPlanId(tx, oldUserPlanId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err = this.NotifyUpdate(tx, serverId)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -2717,6 +2730,21 @@ func (this *ServerDAO) UpdateServerUserPlanId(tx *dbs.Tx, serverId int64, userPl
|
||||
if err != nil {
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
12
internal/db/models/server_dao_ext.go
Normal file
12
internal/db/models/server_dao_ext.go
Normal 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
|
||||
}
|
||||
@@ -6,5 +6,11 @@ package models
|
||||
import "github.com/iwind/TeaGo/dbs"
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user