You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.3 KiB
Go

package price
import (
"cls/internal/domain/price"
"errors"
)
type PriceDto struct {
ID uint64 `json:"id" omitempty`
TargetID uint64 `json:"targetID" omitempty`
Type price.PriceType `json:"type" omitempty`
Amount int64 `json:"amount" omitempty`
OneMonthPrice int64 `json:"oneMonthPrice" omitempty`
ThreeMonthsPrice int64 `json:"threeMonthsPrice" omitempty`
SixMonthsPrice int64 `json:"sixMonthsPrice" omitempty`
OneYearPrice int64 `json:"oneYearPrice" omitempty`
Discount float32 `json:"discount" omitempty`
AdminID uint64 `json:"adminID" omitempty`
}
func (p *PriceDto) ToPrice() *price.Price {
return &price.Price{
ID: p.ID,
TargetID: p.TargetID,
Type: p.Type,
Amount: p.Amount,
OneMonthPrice: p.OneMonthPrice,
ThreeMonthsPrice: p.ThreeMonthsPrice,
SixMonthsPrice: p.SixMonthsPrice,
OneYearPrice: p.OneYearPrice,
Discount: p.Discount,
AdminID: p.AdminID,
}
}
func (p *PriceDto) Validate() error {
if p.Type == price.TypeArticle {
if p.Amount <= 0 {
return errors.New("文章价格必须大于0")
}
}
return nil
}