order_with_bestshop.go
3.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package domain
import "errors"
//类型为(orderType=OrderTypeBestShop) 海鲜干货的订单分红
//因页面上的对于该类型的订单分红状态处理方式 有别于原有的其他类型(OrderReal),所以单独提取出来
// OrderGoodWithBestshopBonusStatus 支付状态
type OrderGoodWithBestshopBonusStatus interface {
OrderGoodBonusStatus
UpdateOrderGoodNumber(good *OrderGood, number int) error
UpdatePertnerBonusPercent(good *OrderGood, percent float64) error
}
//OrderGoodWithBestshop 处理订单中商品的分红相关数据
type OrderGoodWithBestshop struct {
currentBonusStatus OrderGoodWithBestshopBonusStatus
}
func (o *OrderGoodWithBestshop) UpdateBonusByGoodNumber(good *OrderGood, number int) error {
o.reset(good)
err := o.currentBonusStatus.UpdateOrderGoodNumber(good, number)
return err
}
func (o *OrderGoodWithBestshop) UpdateBonusByPertnerBonusPercent(good *OrderGood, percent float64) error {
o.reset(good)
err := o.currentBonusStatus.UpdatePertnerBonusPercent(good, percent)
return err
}
func (o *OrderGoodWithBestshop) PayPartnerBonus(good *OrderGood) error {
o.currentBonusStatus = OrderGoodBonusBestshopHasPay{}
err := good.Compute()
if err != nil {
return errors.New("核算商品数据失败" + err.Error())
}
err = good.CurrentBonusStatus.PayPartnerBonus(good)
return err
}
func (o *OrderGoodWithBestshop) reset(good *OrderGood) {
switch good.BonusStatus {
case OrderGoodWaitPay:
o.currentBonusStatus = OrderGoodBonusBestshopWaitPay{}
case OrderGoodHasPay:
o.currentBonusStatus = OrderGoodBonusBestshopHasPay{}
}
return
}
//OrderGoodBonusBestshopWaitPay 货品支付状态:待支付
type OrderGoodBonusBestshopWaitPay struct {
OrderGoodBonusWaitPay
}
var _ OrderGoodWithBestshopBonusStatus = (*OrderGoodBonusBestshopWaitPay)(nil)
func (waitPay OrderGoodBonusBestshopWaitPay) UpdateOrderGoodNumber(good *OrderGood, number int) error {
good.UseGoodNumber = number
//待支付状态计算
err := good.Compute()
if err != nil {
return errors.New("核算商品数据失败" + err.Error())
}
err = good.CurrentBonusStatus.WartPayPartnerBonus(good)
return err
}
func (waitPay OrderGoodBonusBestshopWaitPay) UpdatePertnerBonusPercent(good *OrderGood, percent float64) error {
good.PartnerBonusPercent = percent
//待支付状态计算
err := good.Compute()
if err != nil {
return errors.New("核算商品数据失败" + err.Error())
}
err = good.CurrentBonusStatus.WartPayPartnerBonus(good)
return err
}
//OrderGoodBonusBestshopHasPay 货品支付状态:已支付
type OrderGoodBonusBestshopHasPay struct {
OrderGoodBonusHasPay
}
var _ OrderGoodWithBestshopBonusStatus = (*OrderGoodBonusBestshopHasPay)(nil)
func (hasPay OrderGoodBonusBestshopHasPay) UpdateOrderGoodNumber(good *OrderGood, number int) error {
return errors.New("已支付分红的货品订单,不能修改货品数量")
}
func (hasPay OrderGoodBonusBestshopHasPay) UpdatePertnerBonusPercent(good *OrderGood, percent float64) error {
return errors.New("已支付分红的货品订单,不能修改合伙人分红比例")
}