diff --git a/business/partner/purchase/jdshop/order.go b/business/partner/purchase/jdshop/order.go index 0e605f0e6..865d988a9 100644 --- a/business/partner/purchase/jdshop/order.go +++ b/business/partner/purchase/jdshop/order.go @@ -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 }