...
|
...
|
@@ -70,7 +70,7 @@ type OrderGood struct { |
|
|
UseGoodNumber int `json:"useGoodNumber"`
|
|
|
//货品单价
|
|
|
Price float64 `json:"price"`
|
|
|
//合伙人分红比例
|
|
|
//合伙人分红比例 比如12.7等同于12.7%,使用负值表示分红比例未进行设置
|
|
|
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
|
|
|
//分红支付状态
|
|
|
BonusStatus int `json:"bonusStatus"`
|
...
|
...
|
@@ -87,6 +87,20 @@ type OrderGood struct { |
|
|
DataFrom OrderDataFrom `json:"data_from"`
|
|
|
}
|
|
|
|
|
|
//NewOrderGood 初始值设定
|
|
|
func NewOrderGood() OrderGood {
|
|
|
return OrderGood{
|
|
|
UseGoodNumber: -1,
|
|
|
BonusStatus: OrderGoodWaitPay,
|
|
|
PartnerBonusPercent: -1,
|
|
|
GoodCompute: GoodCompute{
|
|
|
UsePartnerBonus: -1,
|
|
|
UseAmount: -1,
|
|
|
},
|
|
|
CurrentBonusStatus: OrderGoodBonusWaitPay{},
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//GetCurrentGoodNumber 获取当前的商品数量
|
|
|
func (good OrderGood) GetCurrentGoodNumber() int {
|
|
|
if good.UseGoodNumber >= 0 {
|
...
|
...
|
@@ -111,7 +125,7 @@ func (good OrderGood) GetCurrentPartnerBonus() float64 { |
|
|
return good.GoodCompute.PlanPartnerBonus
|
|
|
}
|
|
|
|
|
|
//GetCurrentAmount 获取当前的商品合伙人分红
|
|
|
//ModifyOrderGoodNumber 修改货品数量
|
|
|
func (good *OrderGood) ModifyOrderGoodNumber(number int, orderType int) error {
|
|
|
if good.PlanGoodNumber < number {
|
|
|
return fmt.Errorf("修改数量不能大于初始值:%d", good.PlanGoodNumber)
|
...
|
...
|
@@ -120,6 +134,7 @@ func (good *OrderGood) ModifyOrderGoodNumber(number int, orderType int) error { |
|
|
return err
|
|
|
}
|
|
|
|
|
|
//ModifyPertnerBonusPercent 修改货品的分红比例
|
|
|
func (good *OrderGood) ModifyPertnerBonusPercent(percent float64, orderType int) error {
|
|
|
err := good.CurrentBonusStatus.ModifyPertnerBonusPercent(good, percent, orderType)
|
|
|
return err
|
...
|
...
|
@@ -162,6 +177,7 @@ type OrderGoodBonusHasPay struct{} |
|
|
|
|
|
var _ OrderGoodBonusStatus = (*OrderGoodBonusHasPay)(nil)
|
|
|
|
|
|
//WartPayPartnerBonus 货品的支付状态从“待支付”状态变更为“待支付”
|
|
|
func (waitPay OrderGoodBonusWaitPay) WartPayPartnerBonus(good *OrderGood) error {
|
|
|
good.GoodCompute.PartnerBonusExpense = 0
|
|
|
good.GoodCompute.PartnerBonusHas = 0
|
...
|
...
|
@@ -178,6 +194,7 @@ func (waitPay OrderGoodBonusWaitPay) WartPayPartnerBonus(good *OrderGood) error |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//PayPartnerBonus 货品的支付状态从“待支付”状态变更为“已支付”
|
|
|
func (waitPay OrderGoodBonusWaitPay) PayPartnerBonus(good *OrderGood) error {
|
|
|
//待支付状态转支付时
|
|
|
//合伙人已收收分红等于合伙人应收分红(或者调整的)
|
...
|
...
|
@@ -196,6 +213,7 @@ func (waitPay OrderGoodBonusWaitPay) PayPartnerBonus(good *OrderGood) error { |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//PayPartnerBonus 货品的支付状态从“已支付”状态变更为“已支付”
|
|
|
func (hasPay OrderGoodBonusHasPay) PayPartnerBonus(good *OrderGood) error {
|
|
|
//已支付的值保持不变
|
|
|
//未支付的值保持不变
|
...
|
...
|
@@ -210,10 +228,12 @@ func (hasPay OrderGoodBonusHasPay) PayPartnerBonus(good *OrderGood) error { |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//WartPayPartnerBonus 货品的支付状态从“已支付”状态变更为“待支付”
|
|
|
func (hasPay OrderGoodBonusHasPay) WartPayPartnerBonus(good *OrderGood) error {
|
|
|
return errors.New("已支付的货单不能将状态回退为待支付")
|
|
|
}
|
|
|
|
|
|
//ModifyOrderGoodNumber 货品的支付状态为“已支付”状态变时,修改货品数量
|
|
|
func (hasPay OrderGoodBonusHasPay) ModifyOrderGoodNumber(good *OrderGood, number int, orderType int) error {
|
|
|
//规则描述:
|
|
|
//实际自建订单(orderType==1),已支付分红状态下“可以”修改货品数量
|
...
|
...
|
@@ -233,6 +253,7 @@ func (hasPay OrderGoodBonusHasPay) ModifyOrderGoodNumber(good *OrderGood, number |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//ModifyOrderGoodNumber 货品的支付状态为“待支付”状态变时,修改货品数量
|
|
|
func (waitPay OrderGoodBonusWaitPay) ModifyOrderGoodNumber(good *OrderGood, number int, orderType int) error {
|
|
|
//规则描述:
|
|
|
//实际自建订单(orderType==1),未支付分红状态下“可以”修改货品数量
|
...
|
...
|
@@ -247,6 +268,7 @@ func (waitPay OrderGoodBonusWaitPay) ModifyOrderGoodNumber(good *OrderGood, numb |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//ModifyPertnerBonusPercent 货品的支付状态为“待支付”状态变时,修改货品合伙人分红比例
|
|
|
func (waitPay OrderGoodBonusWaitPay) ModifyPertnerBonusPercent(good *OrderGood, percent float64, orderType int) error {
|
|
|
//规则描述:
|
|
|
//实际自建订单(orderType==1),未支付分红状态下“不可以”修改合伙人分红比例
|
...
|
...
|
@@ -276,20 +298,6 @@ func (hasPay OrderGoodBonusHasPay) ModifyPertnerBonusPercent(good *OrderGood, pe |
|
|
return errors.New("已支付分红的货品订单,不能修改合伙人分红比例")
|
|
|
}
|
|
|
|
|
|
//NewOrderGood 初始值设定
|
|
|
func NewOrderGood() OrderGood {
|
|
|
return OrderGood{
|
|
|
UseGoodNumber: -1,
|
|
|
BonusStatus: OrderGoodWaitPay,
|
|
|
PartnerBonusPercent: -1,
|
|
|
GoodCompute: GoodCompute{
|
|
|
UsePartnerBonus: -1,
|
|
|
UseAmount: -1,
|
|
|
},
|
|
|
CurrentBonusStatus: OrderGoodBonusWaitPay{},
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//Compute 数据汇总核算
|
|
|
func (good *OrderGood) Compute() error {
|
|
|
//计算预计货品总值
|
...
|
...
|
@@ -299,15 +307,17 @@ func (good *OrderGood) Compute() error { |
|
|
if good.PlanGoodNumber < 0 {
|
|
|
planGoodNumber = 0
|
|
|
}
|
|
|
planamount := price.Mul(decimal.NewFromInt(int64(planGoodNumber))) //price*planGoodNumber
|
|
|
//计算预计货品总值(planamount), 货品单价*预计货品数量(price*planGoodNumber)
|
|
|
planamount := price.Mul(decimal.NewFromInt(int64(planGoodNumber)))
|
|
|
var partnerBonusPercent float64
|
|
|
if good.PartnerBonusPercent < 0 {
|
|
|
partnerBonusPercent = 0
|
|
|
} else {
|
|
|
partnerBonusPercent = good.PartnerBonusPercent
|
|
|
}
|
|
|
//price*useGoodNumber
|
|
|
//计算预计合伙人分红(planPartnerBonus), 预计货品总值*合伙人分成比例/100(planamount*partnerBonusPercent/100)
|
|
|
planPartnerBonus := planamount.Mul(decimal.NewFromFloat(partnerBonusPercent)).Div(decimal.NewFromInt(100)) //price*planGoodNumber*PartnerBonusPercent
|
|
|
//货品预计总值
|
|
|
good.GoodCompute.PlanAmount, _ = planamount.Round(2).BigFloat().Float64()
|
|
|
good.GoodCompute.PlanPartnerBonus, _ = planPartnerBonus.Round(2).BigFloat().Float64()
|
|
|
if good.UseGoodNumber < 0 {
|
...
|
...
|
@@ -316,8 +326,8 @@ func (good *OrderGood) Compute() error { |
|
|
good.GoodCompute.UseAmount = -1
|
|
|
} else {
|
|
|
//计算调整后的货品总值
|
|
|
//计算调整后的合伙人分红
|
|
|
useamount := price.Mul(decimal.NewFromInt(int64(good.UseGoodNumber))) //price*useGoodNumber/price*useGoodNumber
|
|
|
useamount := price.Mul(decimal.NewFromInt(int64(good.UseGoodNumber)))
|
|
|
//计算调整后的合伙人分红 //price*useGoodNumber/price*useGoodNumber
|
|
|
usePartnerBonus := useamount.Mul(decimal.NewFromFloat(partnerBonusPercent)).Div(decimal.NewFromInt(100)) //price*useGoodNumber*PartnerBonusPercent
|
|
|
good.GoodCompute.UsePartnerBonus, _ = usePartnerBonus.Round(2).BigFloat().Float64()
|
|
|
good.GoodCompute.UseAmount, _ = useamount.Round(2).BigFloat().Float64()
|
...
|
...
|
|