Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package periods
|
||||
|
||||
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/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
Count int32
|
||||
Unit string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var periodId int64
|
||||
|
||||
defer func() {
|
||||
this.CreateLogInfo(codes.TrafficPackagePeriod_LogCreateTrafficPackagePeriod, periodId)
|
||||
}()
|
||||
|
||||
if params.Count <= 0 {
|
||||
this.FailField("count", "请输入有效期数量")
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().TrafficPackagePeriodRPC().CreateTrafficPackagePeriod(this.AdminContext(), &pb.CreateTrafficPackagePeriodRequest{
|
||||
Count: params.Count,
|
||||
Unit: params.Unit,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
periodId = createResp.TrafficPackagePeriodId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package periods
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/finance/financeutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "period")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
// 是否已启用
|
||||
config, err := financeutils.ReadPriceConfig(this.AdminContext())
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["enableTrafficPackages"] = config != nil && config.EnableTrafficPackages
|
||||
|
||||
// 所有有效期
|
||||
periodsResp, err := this.RPC().TrafficPackagePeriodRPC().FindAllTrafficPackagePeriods(this.AdminContext(), &pb.FindAllTrafficPackagePeriodsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var periodMaps = []maps.Map{}
|
||||
for _, period := range periodsResp.TrafficPackagePeriods {
|
||||
periodMaps = append(periodMaps, maps.Map{
|
||||
"id": period.Id,
|
||||
"count": period.Count,
|
||||
"unit": period.Unit,
|
||||
"unitName": userconfigs.TrafficPackagePeriodUnitName(period.Unit),
|
||||
"isOn": period.IsOn,
|
||||
})
|
||||
}
|
||||
this.Data["periods"] = periodMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package period
|
||||
|
||||
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 {
|
||||
PeriodId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.TrafficPackagePeriod_LogDeleteTrafficPackagePeriod, params.PeriodId)
|
||||
|
||||
_, err := this.RPC().TrafficPackagePeriodRPC().DeleteTrafficPackagePeriod(this.AdminContext(), &pb.DeleteTrafficPackagePeriodRequest{TrafficPackagePeriodId: params.PeriodId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package period
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
type UpdatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
PeriodId int64
|
||||
}) {
|
||||
periodResp, err := this.RPC().TrafficPackagePeriodRPC().FindTrafficPackagePeriod(this.AdminContext(), &pb.FindTrafficPackagePeriodRequest{TrafficPackagePeriodId: params.PeriodId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var period = periodResp.TrafficPackagePeriod
|
||||
if period == nil {
|
||||
this.NotFound("trafficPackagePeriod", params.PeriodId)
|
||||
return
|
||||
}
|
||||
this.Data["period"] = maps.Map{
|
||||
"id": period.Id,
|
||||
"count": period.Count,
|
||||
"unitName": userconfigs.PricePeriodName(period.Unit),
|
||||
"isOn": period.IsOn,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
PeriodId int64
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.TrafficPackagePeriod_LogUpdateTrafficPackagePeriod, params.PeriodId)
|
||||
|
||||
_, err := this.RPC().TrafficPackagePeriodRPC().UpdateTrafficPackagePeriod(this.AdminContext(), &pb.UpdateTrafficPackagePeriodRequest{
|
||||
TrafficPackagePeriodId: params.PeriodId,
|
||||
IsOn: params.IsOn,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user