Files
waf-platform/EdgeAPI/internal/db/models/server_dao_ext_plus.go

41 lines
1.1 KiB
Go

// 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 {
servers, err := this.Query(tx).
State(ServerStateEnabled).
Attr("userPlanId", userPlanId).
Where("(trafficLimitStatus IS NOT NULL AND JSON_EXTRACT(trafficLimitStatus, '$.planId') IS NOT NULL)").
ResultPk().
FindAll()
if err != nil {
return err
}
if len(servers) == 0 {
return nil
}
err = this.Query(tx).
State(ServerStateEnabled).
Attr("userPlanId", userPlanId).
Where("(trafficLimitStatus IS NOT NULL AND JSON_EXTRACT(trafficLimitStatus, '$.planId') IS NOT NULL)").
Set("trafficLimitStatus", dbs.SQL("NULL")).
UpdateQuickly()
if err != nil {
return err
}
for _, server := range servers {
err = this.NotifyUpdate(tx, int64(server.(*Server).Id))
if err != nil {
return err
}
}
return nil
}