京东商城售前调整

This commit is contained in:
苏尹岚
2020-09-14 11:30:59 +08:00
parent afd11d02c6
commit 65b2525a02

View File

@@ -7,6 +7,8 @@ import (
"strings"
"time"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/platformapi"
"git.rosy.net.cn/baseapi/platformapi/jdshopapi"
@@ -116,6 +118,32 @@ func (p *PurchaseHandler) CancelOrder(ctx *jxcontext.Context, order *model.Goods
return err
}
func (p *PurchaseHandler) AdjustOrder(ctx *jxcontext.Context, order *model.GoodsOrder, removedSkuList []*model.OrderSku, reason string) (err error) {
var (
db = dao.GetDB()
diffShopPrice int64
diffSalePrice int64
)
if order.Status >= model.OrderStatusDelivering {
return fmt.Errorf("配送中以后的订单无法进行售前退款!")
}
//1、删除原order_sku 中售前调整的商品
for _, sku := range removedSkuList {
sql := `DELETE FROM order_sku WHERE vendor_order_id = ? AND vendor_id = ? AND sku_id = ?`
sqlParams := []interface{}{order.VendorOrderID, order.VendorID, sku.SkuID}
dao.ExecuteSQL(db, sql, sqlParams)
diffShopPrice += sku.ShopPrice
diffSalePrice += sku.SalePrice
}
//2、修改goods_order 中的shopprice,若是扣点的订单还要改new_earning_price和total_shop_money
order.AdjustCount += 1
order.ShopPrice = order.ShopPrice - diffShopPrice
if order.EarningType == model.EarningTypePoints {
order.TotalShopMoney = utils.Float64TwoInt64(float64(float64(order.TotalShopMoney)/jdshopapi.JdsPayPercentage-float64(diffSalePrice)) * jdshopapi.JdsPayPercentage)
jxutils.RefreshOrderEarningPrice2(order, order.OrderPayPercentage)
partner.CurOrderManager.UpdateOrderFields(order, []string{"TotalShopMoney", "NewEarningPrice"})
}
partner.CurOrderManager.UpdateOrderFields(order, []string{"AdjustCount", "ShopPrice"})
return err
}