35 lines
874 B
Go
35 lines
874 B
Go
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
//go:build plus
|
|
|
|
package services
|
|
|
|
import (
|
|
"context"
|
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
)
|
|
|
|
// PriceService 价格相关服务
|
|
type PriceService struct {
|
|
BaseService
|
|
}
|
|
|
|
// CalculatePrice 计算费用
|
|
func (this *PriceService) CalculatePrice(ctx context.Context, req *pb.CalculatePriceRequest) (*pb.CalculatePriceResponse, error) {
|
|
_, _, err := this.ValidateAdminAndUser(ctx, true)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var tx = this.NullTx()
|
|
amount, hasRegionPrice, err := models.SharedUserBillDAO.CalculatePrice(tx, req.PriceType, req.TrafficGB, req.BandwidthMB, req.NodeRegionId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &pb.CalculatePriceResponse{
|
|
Amount: amount,
|
|
HasNodeRegionPrice: hasRegionPrice,
|
|
}, nil
|
|
}
|