Files
cloudpods/pkg/compute/models/billingresource.go
T

71 lines
2.0 KiB
Go

// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package models
import (
"time"
api "yunion.io/x/onecloud/pkg/apis/billing"
)
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 api.BILLING_TYPE_POSTPAID
}
}
func (self *SBillingResourceBase) getBillingBaseInfo() SBillingBaseInfo {
info := SBillingBaseInfo{}
info.ChargeType = self.GetChargeType()
if self.GetChargeType() == api.BILLING_TYPE_PREPAID {
info.ExpiredAt = self.ExpiredAt
info.BillingCycle = self.BillingCycle
}
return info
}
func (self *SBillingResourceBase) IsValidPrePaid() bool {
if self.BillingType == api.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"`
}