|
|
|
|
package price
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"cls-server/internal/application/article"
|
|
|
|
|
"cls-server/internal/application/column"
|
|
|
|
|
"cls-server/internal/domain/price"
|
|
|
|
|
"errors"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type PriceDto struct {
|
|
|
|
|
ID uint64 `json:"id" omitempty`
|
|
|
|
|
TargetID uint64 `json:"targetID" omitempty`
|
|
|
|
|
Type price.PriceType `json:"type" omitempty`
|
|
|
|
|
FirstMontDiscount float32 `json:"firstMontDiscount" 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`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PriceDefaultDto struct {
|
|
|
|
|
Id uint64 `json:"id"`
|
|
|
|
|
Amount int64 `json:"amount"`
|
|
|
|
|
FirstMontDiscount float32 `json:"firstMontDiscount" omitempty`
|
|
|
|
|
OneMonthPrice int64 `json:"oneMonthPrice"` // 1个月价格(分)
|
|
|
|
|
ThreeMonthsPrice int64 `json:"threeMonthsPrice"` // 3个月价格(分)
|
|
|
|
|
SixMonthsPrice int64 `json:"sixMonthsPrice"` // 6个月价格(分)
|
|
|
|
|
OneYearPrice int64 `json:"oneYearPrice"` // 1年价格(分)
|
|
|
|
|
Discount float32 `json:"discount" omitempty`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ArticlePriceDto struct {
|
|
|
|
|
Article *article.ArticleDto `json:"article"`
|
|
|
|
|
Price *PriceDto `json:"price"`
|
|
|
|
|
}
|
|
|
|
|
type ColumnPriceDto struct {
|
|
|
|
|
Column *column.ColumnDto `json:"column"`
|
|
|
|
|
Price *PriceDto `json:"price"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|