添加优惠券功能,实现价格计算
This commit is contained in:
@@ -205,7 +205,25 @@ func (data *CreateResourceData) GetName() string {
|
||||
|
||||
func (data *CreateResourceData) GetPrice() float64 {
|
||||
if data.price == 0 {
|
||||
data.price = 0.01
|
||||
var count int
|
||||
switch data.Type {
|
||||
case 1:
|
||||
count = int(data.DailyLimit)
|
||||
case 2:
|
||||
count = int(data.Quota)
|
||||
}
|
||||
|
||||
seconds := int(data.Live)
|
||||
if seconds == 180 {
|
||||
seconds = 150
|
||||
}
|
||||
|
||||
times := int(data.Expire)
|
||||
if data.Type == 2 {
|
||||
times = 1
|
||||
}
|
||||
|
||||
data.price = float64(count*seconds*times) / 30000
|
||||
}
|
||||
return data.price
|
||||
}
|
||||
@@ -229,7 +247,7 @@ func createResource(data *CreateResourceData, uid int32) (*m.Resource, error) {
|
||||
Type: data.Type,
|
||||
Live: data.Live,
|
||||
Quota: data.Quota,
|
||||
Expire: common.LocalDateTime(time.Now().Add(time.Duration(data.Expire) * time.Second)),
|
||||
Expire: common.LocalDateTime(time.Now().Add(time.Duration(data.Expire) * 24 * time.Hour)),
|
||||
DailyLimit: data.DailyLimit,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user