Files
cloudpods/pkg/compute/models/billingresource.go
T
2019-01-01 16:21:37 +08:00

60 lines
1.4 KiB
Go

package models
import (
"time"
)
const (
BILLING_TYPE_POSTPAID = "postpaid"
BILLING_TYPE_PREPAID = "prepaid"
)
type SBillingResourceBase struct {
BillingType string `width:"36" charset:"ascii" nullable:"true" default:"postpaid" list:"user" create:"admin_optional"`
ExpiredAt time.Time `nullable:"true" list:"user" create:"admin_optional"`
BillingCycle string `width:"10" charset:"ascii" nullable:"true" list:"user" create:"admin_optional"`
}
func (self *SBillingResourceBase) GetChargeType() string {
if len(self.BillingType) > 0 {
return self.BillingType
} else {
return BILLING_TYPE_POSTPAID
}
}
func (self *SBillingResourceBase) getBillingBaseInfo() SBillingBaseInfo {
info := SBillingBaseInfo{}
info.ChargeType = self.GetChargeType()
if self.GetChargeType() == BILLING_TYPE_PREPAID {
info.ExpiredAt = self.ExpiredAt
info.BillingCycle = self.BillingCycle
}
return info
}
func (self *SBillingResourceBase) IsValidPrePaid() bool {
if self.BillingType == BILLING_TYPE_PREPAID {
now := time.Now().UTC()
if self.ExpiredAt.After(now) {
return true
}
}
return false
}
type SBillingBaseInfo struct {
ChargeType string `json:",omitempty"`
ExpiredAt time.Time `json:",omitempty"`
BillingCycle string `json:",omitempty"`
}
type SCloudBillingInfo struct {
SCloudProviderInfo
SBillingBaseInfo
PriceKey string `json:",omitempty"`
InternetChargeType string `json:",omitempty"`
}