package order import ( "github.com/golangkit/formatime" "github.com/shopspring/decimal" ) type Profit struct { ID int `json:"id"` OrderID uint `json:"order_id"` Base decimal.Decimal `json:"base"` Type IncomeType `json:"type"` Income decimal.Decimal `json:"income"` UserID uint `json:"user_id"` CreatedAt formatime.Second `json:"created_at"` Status int `json:"status"` Version int `json:"-"` DealID int `json:"-"` IsEnterprise bool `json:"is_enterprise"` } func (o Profit) TableName() string { return "jyy_order_profit" } type IncomeType uint const ( Self IncomeType = iota + 1 Guide Brand Shop Company All Sale Share Vip Card ) var profitStr = map[IncomeType]string{ Self: "自购收益", Guide: "导购收益", Brand: "品牌补贴", Shop: "开店补贴", Company: "店铺补贴", All: "子公司自购导购收益", Sale: "批发收益", Share: "子公司分享收益", Vip: "vip穿透收益", Card: "买卡收益", } func (o IncomeType) GetStr() string { return profitStr[o] } var profitMap = map[IncomeType]decimal.Decimal{ Self: decimal.NewFromFloat(0.5), Guide: decimal.NewFromFloat(0.5), Brand: decimal.NewFromFloat(0.0), Shop: decimal.NewFromFloat(0.2), Company: decimal.NewFromFloat(0.3), All: decimal.NewFromFloat(1), Sale: decimal.NewFromFloat(1), Share: decimal.NewFromFloat(1), Vip: decimal.NewFromFloat(0.2), Card: decimal.NewFromFloat(0.6), } func (o IncomeType) GetProfit() decimal.Decimal { return profitMap[o] } func CreateProfit(id uint, t1 IncomeType, base decimal.Decimal, orderID uint, status ...int) *Profit { s := 0 if len(status) != 0 { s = status[0] } return &Profit{ OrderID: orderID, Base: base, Type: t1, Income: base.Mul(profitMap[t1]).Round(2), UserID: id, CreatedAt: formatime.NewSecondNow(), Status: s, Version: 2, } }