package price import "time" // PriceType 价格类型 type PriceType int8 const ( TypeArticle PriceType = 1 // 文章 TypeColumn PriceType = 2 // 专栏 ) // Price 价格管理实体 type Price struct { ID uint64 `xorm:"pk autoincr 'id'"` TargetID uint64 `xorm:"not null 'target_id'"` // 目标ID(文章ID或专栏ID) Type PriceType `xorm:"not null 'type'"` // 价格类型 Amount int64 `xorm:"not null 'amount'"` // 基础价格(分) OneMonthPrice int64 `xorm:"not null 'one_month_price'"` // 1个月价格(分) ThreeMonthsPrice int64 `xorm:"not null 'three_months_price'"` // 3个月价格(分) SixMonthsPrice int64 `xorm:"not null 'six_months_price'"` // 6个月价格(分) OneYearPrice int64 `xorm:"not null 'one_year_price'"` // 1年价格(分) FirstMontDiscount float32 `xorm:"not null 'first_mont_discount'"` // 首月折扣 Discount float32 `xorm:"not null 'discount'"` // 折扣(分) AdminID uint64 `xorm:"not null 'admin_id'"` // 管理员ID CreatedAt time.Time `xorm:"created 'created_at'"` UpdatedAt time.Time `xorm:"updated 'updated_at'"` DeletedAt *time.Time `xorm:"deleted 'deleted_at'"` } // DefaultPrice 默认价格(分) const ( DefaultArticlePrice = 1000 // 文章默认价格10元 DefaultColumnPrice = 10000 // 专栏默认价格100元 ) // NewPrice 创建价格实体 func NewPrice(targetID uint64, priceType PriceType, amount int64, adminID uint64) *Price { return &Price{ TargetID: targetID, Type: priceType, Amount: amount, OneMonthPrice: amount, ThreeMonthsPrice: int64(float64(amount) * 0.9), // 9折 SixMonthsPrice: int64(float64(amount) * 0.8), // 8折 OneYearPrice: int64(float64(amount) * 0.7), // 7折 AdminID: adminID, Discount: 0.3, } }