添加优惠券功能,实现价格计算

This commit is contained in:
2025-04-19 14:59:19 +08:00
parent 999d0b0a1d
commit 058c4f4313
9 changed files with 581 additions and 19 deletions

View File

@@ -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,
},
}