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.

65 lines
1.3 KiB

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"`
}
func (o Profit) TableName() string {
return "jyy_order_profit"
}
type IncomeType uint
const (
Self IncomeType = iota + 1
Guide
Brand
Shop
)
var profitStr = map[IncomeType]string{
Self: "自购收益",
Guide: "导购收益",
Brand: "品牌补贴",
Shop: "开店补贴",
}
func (o IncomeType) GetStr() string {
return profitStr[o]
}
var profitMap = map[IncomeType]decimal.Decimal{
Self: decimal.NewFromFloat(0.4),
Guide: decimal.NewFromFloat(0.4),
Brand: decimal.NewFromFloat(0.1),
Shop: decimal.NewFromFloat(0.2),
}
func (o IncomeType) GetProfit() decimal.Decimal {
return profitMap[o]
}
func CreateProfit(id uint, t1 IncomeType, base decimal.Decimal, orderID uint) *Profit {
return &Profit{
OrderID: orderID,
Base: base,
Type: t1,
Income: base.Mul(profitMap[t1]).Round(2),
UserID: id,
CreatedAt: formatime.NewSecondNow(),
Status: 0,
}
}