You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
3.3 KiB
60 lines
3.3 KiB
package goods
|
|
|
|
import (
|
|
"recook/internal/define"
|
|
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
type Sku struct {
|
|
ID uint `gorm:"column:id;primary_key" json:"id"`
|
|
GoodsID uint `gorm:"column:goods_id" json:"goodsId"`
|
|
Name string `gorm:"column:name" json:"name"`
|
|
CombineID string `gorm:"column:combine_id" json:"combineId"`
|
|
PicURL string `gorm:"column:pic_url" json:"picUrl"`
|
|
Code string `gorm:"column:code" json:"code"`
|
|
PurchasePrice decimal.Decimal `gorm:"column:purchase_price" json:"purchasePrice"`
|
|
OriginalPrice decimal.Decimal `gorm:"column:original_price" json:"originalPrice"` // 原价
|
|
DiscountPrice decimal.Decimal `gorm:"column:discount_price" json:"discountPrice"` // 折扣价
|
|
CommissionRate decimal.Decimal `gorm:"column:commission_rate" json:"commissionRate"` // 佣金比
|
|
Commission decimal.Decimal `gorm:"column:commission" json:"commission"` // 佣金
|
|
SalePrice decimal.Decimal `json:"sale_price" gorm:"-"`
|
|
ControlPrice decimal.Decimal `gorm:"column:control_price" json:"controlPrice"` // 供应商最低控价
|
|
SalesVolume uint `gorm:"column:sales_volume" json:"salesVolume"` // 销售量 销售量只简单累加
|
|
Inventory uint `gorm:"column:inventory" json:"inventory"` // 库存量 可以直接补货
|
|
SalesVolumeInc uint `gorm:"column:sales_volume_inc" json:"salesVolumeInc"` // 销售量的增量
|
|
Coupon decimal.Decimal `gorm:"coupon" json:"coupon"`
|
|
GoodsNum string `gorm:"goods_num" json:"goodsNum"` //商品货号
|
|
BmSkuId string `gorm:"bm_sku_id" json:"bm_sku_id"` //舶茂的skuid
|
|
BmShopId string `gorm:"bm_shop_id" json:"bm_shop_id"` //舶茂的商家id
|
|
ThirdPartySkuId string `gorm:"column:third_party_sku_id" json:"thirdPartySkuId"` //第三方skuid
|
|
ThirdPartyType int `gorm:"column:third_party_type" json:"thirdPartySkuType"` //第三方类型
|
|
SaleInventory uint `json:"sale_inventory" gorm:"column:sale_inventory"`
|
|
Limit uint `json:"limit" gorm:"column:limit_num"`
|
|
Min uint `json:"min" gorm:"column:min_num"`
|
|
SalePurchasePrice decimal.Decimal `json:"sale_purchase_price" gorm:"column:sale_purchase_price"` // 批发供货价
|
|
}
|
|
|
|
// TableName sets the insert table name for this struct type
|
|
func (r *Sku) TableName() string {
|
|
return "recook_goods_sku"
|
|
}
|
|
|
|
func (r *Sku) GetBase() decimal.Decimal {
|
|
cost := r.PurchasePrice.Mul(decimal.NewFromFloat(1.03))
|
|
base := r.DiscountPrice.Sub(cost).Mul(decimal.NewFromFloat32(define.Coefficient))
|
|
return base.Round(2)
|
|
}
|
|
|
|
func (o *Sku) GetSalePrice(level int) decimal.Decimal {
|
|
if o.SalePurchasePrice.IsZero() {
|
|
return decimal.Zero
|
|
}
|
|
if level == 10 {
|
|
return o.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2)
|
|
}
|
|
s1 := o.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03)).Mul(decimal.NewFromFloat(1.2)).Round(2)
|
|
// s1 = s1.Add(o.DiscountPrice.Sub(o.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03))).Mul(decimal.NewFromFloat(0.2)).Round(2))
|
|
return s1.Round(2)
|
|
}
|