作者 唐旭辉

更新

package syncOrder
//从其他系统接收订单数据
//接收来源于海鲜干货小程序的订单数据
... ...
... ... @@ -125,6 +125,9 @@ func (good *OrderGood) Update(m map[string]interface{}) error {
if v, ok := m["Remark"]; ok {
good.Remark = v.(string)
}
if v, ok := m["RemarkReason"]; ok {
good.RemarkReason = v.(OrderGoodRemarkReason)
}
err := good.Compute()
return err
}
... ... @@ -151,6 +154,7 @@ func (waitPay OrderGoodBonusWaitPay) WartPayPartnerBonus(good *OrderGood) error
good.GoodCompute.PartnerBonusNot = good.GoodCompute.UsePartnerBonus
}
good.CurrentBonusStatus = OrderGoodBonusWaitPay{}
good.BonusStatus = OrderGoodWaitPay
return nil
}
... ... @@ -168,6 +172,7 @@ func (waitPay OrderGoodBonusWaitPay) PayPartnerBonus(good *OrderGood) error {
good.GoodCompute.PartnerBonusExpense = 0
good.GoodCompute.PartnerBonusNot = 0
good.CurrentBonusStatus = OrderGoodBonusHasPay{}
good.BonusStatus = OrderGoodHasPay
return nil
}
... ... @@ -181,6 +186,7 @@ func (hasPay OrderGoodBonusHasPay) PayPartnerBonus(good *OrderGood) error {
good.GoodCompute.PartnerBonusExpense = good.GoodCompute.PartnerBonusHas - good.GoodCompute.UsePartnerBonus
}
good.CurrentBonusStatus = OrderGoodBonusHasPay{}
good.BonusStatus = OrderGoodHasPay
return nil
}
... ...
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.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
return nil
}
func (waitPay OrderGoodBonusBestshopWaitPay) UpdatePertnerBonusPercent(good *OrderGood, percent float64) error {
good.PartnerBonusPercent = percent
return nil
}
//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("已支付分红的货品订单,不能修改合伙人分红比例")
}
... ...
... ... @@ -82,7 +82,10 @@ func (serve *OrderBonusService) UpdateBounsByGoodNumber(orderId int64, adminId i
updateGood = oldOrder.Goods[i]
formerNumber = updateGood.GetCurrentGoodNumber()
formerAmount = updateGood.GetCurrentAmount()
updateGood.UseGoodNumber = goodWithNumber
err := new(domain.OrderGoodWithBestshop).UpdateBonusByGoodNumber(&updateGood, goodWithNumber)
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
updateGood.RemarkReason.ModifyGoodNumber = reason
//计算
if err := updateGood.Compute(); err != nil {
... ... @@ -180,7 +183,10 @@ func (serve *OrderBonusService) UpdateBounsByPartnerBonusPercent(orderId int64,
updateGood = oldOrder.Goods[i]
formerPartnerBonusPercent = updateGood.PartnerBonusPercent
formerPartnerBonus = updateGood.GetCurrentPartnerBonus()
updateGood.PartnerBonusPercent = partnerPercent
err := new(domain.OrderGoodWithBestshop).UpdateBonusByPertnerBonusPercent(&updateGood, partnerPercent)
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
updateGood.RemarkReason.ModifyPartnerBonusPercent = reason
//计算
if err := updateGood.Compute(); err != nil {
... ... @@ -273,7 +279,10 @@ func (serve *OrderBonusService) PayOrderGoodBonus(orderId int64, goodId int64, a
continue
}
updateGood = oldOrder.Goods[i]
updateGood.CurrentBonusStatus.PayPartnerBonus(&updateGood)
err := new(domain.OrderGoodWithBestshop).PayPartnerBonus(&updateGood)
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
//计算
if err := updateGood.Compute(); err != nil {
return errors.New("核算商品数据失败" + err.Error())
... ...