55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
|
|
|
package packages
|
|
|
|
import (
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
|
"github.com/iwind/TeaGo/types"
|
|
)
|
|
|
|
type PriceAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *PriceAction) RunPost(params struct {
|
|
PackageId int64
|
|
PeriodId int64
|
|
Count int32
|
|
}) {
|
|
if params.PackageId <= 0 || params.PeriodId <= 0 || params.Count <= 0 {
|
|
this.Data["price"] = 0
|
|
this.Data["amount"] = 0
|
|
this.Success()
|
|
return
|
|
}
|
|
|
|
// 数量
|
|
countInstancesResp, err := this.RPC().ADPackageInstanceRPC().CountIdleADPackageInstances(this.UserContext(), &pb.CountIdleADPackageInstancesRequest{AdPackageId: params.PackageId})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
var countInstances = types.Int32(countInstancesResp.Count)
|
|
if countInstances < params.Count {
|
|
this.Data["price"] = 0
|
|
this.Data["amount"] = 0
|
|
this.Success()
|
|
return
|
|
}
|
|
|
|
resp, err := this.RPC().ADPackagePriceRPC().FindADPackagePrice(this.UserContext(), &pb.FindADPackagePriceRequest{
|
|
AdPackageId: params.PackageId,
|
|
AdPackagePeriodId: params.PeriodId,
|
|
Count: params.Count,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
this.Data["price"] = resp.Price
|
|
this.Data["amount"] = resp.Amount
|
|
|
|
this.Success()
|
|
}
|