Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,171 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package userpackages
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
// 价格
|
||||
pricesResp, err := this.RPC().TrafficPackagePriceRPC().FindAllTrafficPackagePrices(this.AdminContext(), &pb.FindAllTrafficPackagePricesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var priceMap = map[string]float64{} // packageId@regionId@periodId => price
|
||||
var allPackageIdMap = map[int64]bool{}
|
||||
var allRegionIdMap = map[int64]bool{}
|
||||
var allPeriodIdMap = map[int64]bool{}
|
||||
for _, price := range pricesResp.TrafficPackagePrices {
|
||||
if price.Price > 0 {
|
||||
allPackageIdMap[price.TrafficPackageId] = true
|
||||
allRegionIdMap[price.NodeRegionId] = true
|
||||
allPeriodIdMap[price.TrafficPackagePeriodId] = true
|
||||
|
||||
var key = types.String(price.TrafficPackageId) + "@" + types.String(price.NodeRegionId) + "@" + types.String(price.TrafficPackagePeriodId)
|
||||
priceMap[key] = price.Price
|
||||
}
|
||||
}
|
||||
this.Data["prices"] = priceMap
|
||||
|
||||
// 流量包
|
||||
var packageMaps = []maps.Map{}
|
||||
packagesResp, err := this.RPC().TrafficPackageRPC().FindAllAvailableTrafficPackages(this.AdminContext(), &pb.FindAllAvailableTrafficPackagesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for _, p := range packagesResp.TrafficPackages {
|
||||
_, hasPrice := allPackageIdMap[p.Id]
|
||||
if hasPrice {
|
||||
packageMaps = append(packageMaps, maps.Map{
|
||||
"id": p.Id,
|
||||
"size": p.Size,
|
||||
"unit": p.Unit,
|
||||
})
|
||||
}
|
||||
}
|
||||
this.Data["packages"] = packageMaps
|
||||
|
||||
// 区域
|
||||
var regionMaps = []maps.Map{}
|
||||
regionsResp, err := this.RPC().NodeRegionRPC().FindAllAvailableNodeRegions(this.AdminContext(), &pb.FindAllAvailableNodeRegionsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for _, region := range regionsResp.NodeRegions {
|
||||
_, hasPrice := allRegionIdMap[region.Id]
|
||||
if hasPrice {
|
||||
regionMaps = append(regionMaps, maps.Map{
|
||||
"id": region.Id,
|
||||
"name": region.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
this.Data["regions"] = regionMaps
|
||||
|
||||
// 周期
|
||||
var periodMaps = []maps.Map{}
|
||||
periodResp, err := this.RPC().TrafficPackagePeriodRPC().FindAllAvailableTrafficPackagePeriods(this.AdminContext(), &pb.FindAllAvailableTrafficPackagePeriodsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for _, period := range periodResp.TrafficPackagePeriods {
|
||||
_, hasPrice := allPeriodIdMap[period.Id]
|
||||
if hasPrice {
|
||||
periodMaps = append(periodMaps, maps.Map{
|
||||
"id": period.Id,
|
||||
"count": period.Count,
|
||||
"unit": period.Unit,
|
||||
"unitName": userconfigs.TrafficPackagePeriodUnitName(period.Unit),
|
||||
})
|
||||
}
|
||||
}
|
||||
this.Data["periods"] = periodMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
UserId int64
|
||||
PackageId int64
|
||||
RegionId int64
|
||||
PeriodId int64
|
||||
Count int32
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.UserTrafficPackage_LogCreateUserTrafficPackage, params.UserId, params.PackageId, params.RegionId, params.PeriodId, params.Count)
|
||||
|
||||
if params.UserId <= 0 {
|
||||
this.Fail("请选择用户")
|
||||
return
|
||||
}
|
||||
|
||||
if params.PackageId <= 0 {
|
||||
this.Fail("请选择流量包规格")
|
||||
return
|
||||
}
|
||||
|
||||
if params.RegionId <= 0 {
|
||||
this.Fail("请选择区域")
|
||||
return
|
||||
}
|
||||
|
||||
if params.PeriodId <= 0 {
|
||||
this.Fail("请选择有效期")
|
||||
return
|
||||
}
|
||||
|
||||
if params.Count <= 0 {
|
||||
this.Fail("请选择流量包数量")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := this.RPC().TrafficPackagePriceRPC().FindTrafficPackagePrice(this.AdminContext(), &pb.FindTrafficPackagePriceRequest{
|
||||
TrafficPackageId: params.PackageId,
|
||||
NodeRegionId: params.RegionId,
|
||||
TrafficPackagePeriodId: params.PeriodId,
|
||||
Count: params.Count,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if resp.Price == 0 {
|
||||
this.Fail("当前所选条件下的流量包不可用")
|
||||
return
|
||||
}
|
||||
|
||||
_, err = this.RPC().UserTrafficPackageRPC().CreateUserTrafficPackage(this.AdminContext(), &pb.CreateUserTrafficPackageRequest{
|
||||
UserId: params.UserId,
|
||||
TrafficPackageId: params.PackageId,
|
||||
NodeRegionId: params.RegionId,
|
||||
TrafficPackagePeriodId: params.PeriodId,
|
||||
Count: params.Count,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package userpackages
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
UserPackageId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.UserTrafficPackage_LogDeleteUserTrafficPackage, params.UserPackageId)
|
||||
|
||||
_, err := this.RPC().UserTrafficPackageRPC().DeleteUserTrafficPackage(this.AdminContext(), &pb.DeleteUserTrafficPackageRequest{UserTrafficPackageId: params.UserPackageId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package userpackages
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/dateutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "userPackage")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
UserId int64
|
||||
RegionId int64
|
||||
PackageId int64
|
||||
PeriodId int64
|
||||
}) {
|
||||
countResp, err := this.RPC().UserTrafficPackageRPC().CountUserTrafficPackages(this.AdminContext(), &pb.CountUserTrafficPackagesRequest{
|
||||
TrafficPackageId: params.PackageId,
|
||||
NodeRegionId: params.RegionId,
|
||||
UserId: params.UserId,
|
||||
ExpiresDay: "",
|
||||
TrafficPackagePeriodId: params.PeriodId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
userPackagesResp, err := this.RPC().UserTrafficPackageRPC().ListUserTrafficPackages(this.AdminContext(), &pb.ListUserTrafficPackagesRequest{
|
||||
TrafficPackageId: params.PackageId,
|
||||
UserId: params.UserId,
|
||||
NodeRegionId: params.RegionId,
|
||||
TrafficPackagePeriodId: params.PeriodId,
|
||||
ExpiresDay: "",
|
||||
AvailableOnly: false,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var userPackageMaps = []maps.Map{}
|
||||
for _, userPackage := range userPackagesResp.UserTrafficPackages {
|
||||
// user
|
||||
var userMap maps.Map
|
||||
if userPackage.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": userPackage.User.Id,
|
||||
"username": userPackage.User.Username,
|
||||
"fullname": userPackage.User.Fullname,
|
||||
}
|
||||
}
|
||||
|
||||
// package
|
||||
var packageMap maps.Map
|
||||
if userPackage.TrafficPackage != nil {
|
||||
packageMap = maps.Map{
|
||||
"id": userPackage.TrafficPackage.Id,
|
||||
"size": userPackage.TrafficPackage.Size,
|
||||
"unit": userPackage.TrafficPackage.Unit,
|
||||
}
|
||||
}
|
||||
|
||||
// region
|
||||
var regionMap maps.Map
|
||||
if userPackage.NodeRegion != nil {
|
||||
regionMap = maps.Map{
|
||||
"id": userPackage.NodeRegion.Id,
|
||||
"name": userPackage.NodeRegion.Name,
|
||||
}
|
||||
}
|
||||
|
||||
userPackageMaps = append(userPackageMaps, maps.Map{
|
||||
"id": userPackage.Id,
|
||||
"dayFrom": dateutils.SplitYmd(userPackage.DayFrom),
|
||||
"dayTo": dateutils.SplitYmd(userPackage.DayTo),
|
||||
"user": userMap,
|
||||
"package": packageMap,
|
||||
"region": regionMap,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", userPackage.CreatedAt),
|
||||
"periodCount": userPackage.TrafficPackagePeriodCount,
|
||||
"periodUnitName": userconfigs.TrafficPackagePeriodUnitName(userPackage.TrafficPackagePeriodUnit),
|
||||
"usedSize": numberutils.FormatBytes(userPackage.UsedBytes),
|
||||
"availableSize": numberutils.FormatBytes(userPackage.TotalBytes - userPackage.UsedBytes),
|
||||
"canDelete": userPackage.CanDelete,
|
||||
"isExpired": userPackage.DayTo < timeutil.Format("Ymd"),
|
||||
"isUsedAll": userPackage.UsedBytes >= userPackage.TotalBytes,
|
||||
})
|
||||
}
|
||||
this.Data["userPackages"] = userPackageMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package userpackages
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type PriceAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *PriceAction) RunPost(params struct {
|
||||
PackageId int64
|
||||
RegionId int64
|
||||
PeriodId int64
|
||||
Count int32
|
||||
}) {
|
||||
if params.PackageId <= 0 || params.RegionId <= 0 || params.PeriodId <= 0 || params.Count <= 0 {
|
||||
this.Data["price"] = 0
|
||||
this.Data["amount"] = 0
|
||||
this.Success()
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := this.RPC().TrafficPackagePriceRPC().FindTrafficPackagePrice(this.AdminContext(), &pb.FindTrafficPackagePriceRequest{
|
||||
TrafficPackageId: params.PackageId,
|
||||
NodeRegionId: params.RegionId,
|
||||
TrafficPackagePeriodId: params.PeriodId,
|
||||
Count: params.Count,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["price"] = resp.Price
|
||||
this.Data["amount"] = resp.Amount
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user