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.

82 lines
1.8 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"`
Version int `json:"-"`
}
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
)
var profitStr = map[IncomeType]string{
Self: "自购收益",
Guide: "导购收益",
Brand: "品牌补贴",
Shop: "开店补贴",
Company: "店铺补贴",
All: "子公司自购导购收益",
Sale: "批发收益",
Share: "子公司分享收益",
Vip: "vip穿透收益",
}
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),
}
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,
Version: 2,
}
}