新增提取函数,实现通过套餐编号提取
This commit is contained in:
@@ -25,7 +25,7 @@ var Channel = &channelServer{
|
||||
}
|
||||
|
||||
type ChannelServiceProvider interface {
|
||||
CreateChannels(source netip.Addr, resourceId int32, authWhitelist bool, authPassword bool, count int, edgeFilter *EdgeFilter) ([]*m.Channel, error)
|
||||
CreateChannels(source netip.Addr, resourceNo string, authWhitelist bool, authPassword bool, count int, edgeFilter *EdgeFilter) ([]*m.Channel, error)
|
||||
RemoveChannels(batch string) error
|
||||
ClearExpiredChannels(proxyId int32) (int, error)
|
||||
}
|
||||
@@ -34,8 +34,8 @@ type channelServer struct {
|
||||
provider ChannelServiceProvider
|
||||
}
|
||||
|
||||
func (s *channelServer) CreateChannels(source netip.Addr, resourceId int32, authWhitelist bool, authPassword bool, count int, edgeFilter *EdgeFilter) ([]*m.Channel, error) {
|
||||
return s.provider.CreateChannels(source, resourceId, authWhitelist, authPassword, count, edgeFilter)
|
||||
func (s *channelServer) CreateChannels(source netip.Addr, resourceNo string, authWhitelist bool, authPassword bool, count int, edgeFilter *EdgeFilter) ([]*m.Channel, error) {
|
||||
return s.provider.CreateChannels(source, resourceNo, authWhitelist, authPassword, count, edgeFilter)
|
||||
}
|
||||
|
||||
func (s *channelServer) RemoveChannels(batch string) error {
|
||||
@@ -115,12 +115,23 @@ func genPassPair() (string, string) {
|
||||
return string(username), string(password)
|
||||
}
|
||||
|
||||
func FindResourceNoById(resourceId int32) (string, error) {
|
||||
resource, err := q.Resource.
|
||||
Select(q.Resource.ResourceNo).
|
||||
Where(q.Resource.ID.Eq(resourceId)).
|
||||
Take()
|
||||
if err != nil {
|
||||
return "", ErrResourceNotExist
|
||||
}
|
||||
return u.Z(resource.ResourceNo), nil
|
||||
}
|
||||
|
||||
// 查找资源
|
||||
func findResource(resourceId int32, now time.Time) (*ResourceView, error) {
|
||||
func findResourceViewByNo(resourceNo string, now time.Time) (*ResourceView, error) {
|
||||
resource, err := q.Resource.
|
||||
Preload(field.Associations).
|
||||
Where(
|
||||
q.Resource.ID.Eq(resourceId),
|
||||
q.Resource.ResourceNo.Eq(resourceNo),
|
||||
q.Resource.Active.Is(true),
|
||||
).
|
||||
Take()
|
||||
@@ -131,7 +142,7 @@ func findResource(resourceId int32, now time.Time) (*ResourceView, error) {
|
||||
return nil, ErrResourceNotExist
|
||||
}
|
||||
var info = &ResourceView{
|
||||
Id: resource.ID,
|
||||
ID: resource.ID,
|
||||
User: *resource.User,
|
||||
Active: resource.Active,
|
||||
Type: resource.Type,
|
||||
@@ -177,7 +188,7 @@ func findResource(resourceId int32, now time.Time) (*ResourceView, error) {
|
||||
|
||||
// ResourceView 套餐数据的简化视图,便于直接获取主要数据
|
||||
type ResourceView struct {
|
||||
Id int32
|
||||
ID int32
|
||||
User m.User
|
||||
Active bool
|
||||
Type m.ResourceType
|
||||
@@ -195,13 +206,13 @@ type ResourceView struct {
|
||||
}
|
||||
|
||||
// 检查用户是否可提取
|
||||
func ensure(now time.Time, source netip.Addr, resourceId int32, authWhitelist bool, count int) (*ResourceView, []string, error) {
|
||||
func ensure(now time.Time, source netip.Addr, resourceNo string, authWhitelist bool, count int) (*ResourceView, []string, error) {
|
||||
if count > 400 {
|
||||
return nil, nil, core.NewBizErr("单次最多提取 400 个")
|
||||
}
|
||||
|
||||
// 获取用户套餐
|
||||
resource, err := findResource(resourceId, now)
|
||||
resource, err := findResourceViewByNo(resourceNo, now)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user