// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn . //go:build plus package models import ( "errors" teaconst "github.com/TeaOSLab/EdgeAPI/internal/const" "github.com/iwind/TeaGo/dbs" "github.com/iwind/TeaGo/types" ) func (this *NodeDAO) CountAllAuthorityNodes(tx *dbs.Tx) (int64, error) { return this.Query(tx). State(NodeStateEnabled). Where("clusterId IN (SELECT id FROM " + SharedNodeClusterDAO.Table + " WHERE state=1)"). Count() } func (this *NodeDAO) CheckNodesLimit(tx *dbs.Tx) error { var maxNodes = teaconst.MaxNodes if maxNodes <= 0 && !teaconst.IsPlus { maxNodes = teaconst.DefaultMaxNodes // 免费版节点数量限制 } // 检查节点数量 if maxNodes > 0 { count, err := this.CountAllAuthorityNodes(tx) if err != nil { return err } if count >= int64(maxNodes) { if teaconst.IsPlus { return errors.New("[商业版]超出最大节点数限制:" + types.String(maxNodes) + ",当前已用:" + types.String(count) + ",请购买更多配额") } else { return errors.New("[免费版]超出最大节点数限制:" + types.String(maxNodes) + ",当前已用:" + types.String(count) + ",请购买商业版以获得更多配额") } } } return nil }