From 7871f4e553501cb2844313b50fe1991e49f2b8fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=81=B0=E7=81=B0?= Date: Sun, 23 Jan 2022 18:28:54 +0000 Subject: [PATCH] =?UTF-8?q?!190=20=E3=80=90=E5=AE=8C=E5=96=84=E3=80=91?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=90=A5=E9=94=80=E7=BB=93=E6=9E=9C=E3=80=90?= =?UTF-8?q?GOODS=5FHALF=5FPRICE=E3=80=91=E6=8C=87=E5=AE=9A=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=AF=8F=E7=AC=AC=E5=87=A0=E4=BB=B6=E5=87=8F=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E9=87=91=E9=A2=9D=E3=80=82=20###=20=20=E5=BC=80?= =?UTF-8?q?=E6=BA=90=E7=A4=BE=E5=8C=BA=E7=89=88=EF=BC=88=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E4=B8=93=E4=B8=9A=E7=89=88=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=89=EF=BC=9A=20=E3=80=90=E5=AE=8C=E5=96=84=E3=80=91?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=90=A5=E9=94=80=E7=BB=93=E6=9E=9C=E3=80=90?= =?UTF-8?q?GOODS=5FHALF=5FPRICE=E3=80=91=E6=8C=87=E5=AE=9A=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=AF=8F=E7=AC=AC=E5=87=A0=E4=BB=B6=E5=87=8F=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E9=87=91=E9=A2=9D=E3=80=82=20###=200.1.2=20=E4=BC=9A?= =?UTF-8?q?=E5=91=98=E4=B8=93=E4=B8=9A=E7=89=88=EF=BC=9A=20=E3=80=90?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E3=80=91=E5=BE=AE=E4=BF=A1=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E5=B8=A6=E8=B4=A7=E7=BB=84=E4=BB=B6=E6=B7=BB=E5=8A=A0=E6=94=AF?= =?UTF-8?q?=E6=8C=81base64=E4=B8=8A=E4=BC=A0=E5=88=B0=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E4=BE=A7=E5=8A=9F=E8=83=BD=E3=80=82=20=E3=80=90=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E3=80=91=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E5=B7=A5=E4=BD=9C=E7=BA=BF=E7=A8=8B=E6=95=B0=E5=8F=8A?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=95=B0=E9=87=8F=E3=80=82=20=E3=80=90?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E3=80=91=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=97=B6=E9=97=B4=E5=9F=BA=E5=87=86=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E4=B8=BA=E6=9C=AC=E5=9C=B0loacl=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CoreCmsPromotionResultServices.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/CoreCms.Net.Services/Promotion/CoreCmsPromotionResultServices.cs b/CoreCms.Net.Services/Promotion/CoreCmsPromotionResultServices.cs index bdb4792..e6ae5cf 100644 --- a/CoreCms.Net.Services/Promotion/CoreCmsPromotionResultServices.cs +++ b/CoreCms.Net.Services/Promotion/CoreCmsPromotionResultServices.cs @@ -80,6 +80,9 @@ namespace CoreCms.Net.Services case "GOODS_ONE_PRICE": promotionModel = result_GOODS_ONE_PRICE(parameters, item, promotionInfo); break; + case "GOODS_HALF_PRICE": //todo 指定商品每第几件减指定金额 + promotionModel = result_GOODS_HALF_PRICE(parameters, item, promotionInfo); + break; default: promotionModel = 0; break; @@ -316,5 +319,34 @@ namespace CoreCms.Net.Services return promotionMoney; } + //商品第N个半价 + public decimal result_GOODS_HALF_PRICE(JObject parameters, CartProducts cartProducts, CoreCmsPromotion promotionInfo) + { + if (!parameters.ContainsKey("money")) return 0; + var objMoney = parameters["money"].ObjectToDecimal(0); + + //如果一口价比商品价格高,那么就不执行了 + decimal promotionMoney = 0; + if (cartProducts.products.price <= objMoney) + { + return promotionMoney; + } + //第几个优惠 + var num = parameters["num"].ObjectToInt(0); + //购买的数量 + var buyNum = cartProducts.nums; + //取整数,保证满足了,才优惠 ,比如设置 原价 10 第2个 减少5,购买5个产品的时候,实际只优惠2个产品的价格 + var promotionNum = buyNum / num; + var pmoney = Math.Round((decimal)promotionNum * objMoney / buyNum, 2); //单品优惠的金额 + var goodsPrice = (decimal)cartProducts.products.price; + cartProducts.products.price = goodsPrice - pmoney; //优惠后的平均价格 + promotionMoney = Math.Round(cartProducts.nums * pmoney, 2);//优惠金额 + //设置商品优惠总金额 + cartProducts.products.promotionAmount = Math.Round(cartProducts.products.promotionAmount + promotionMoney, 2); + //设置商品的实际销售总金额 + cartProducts.products.amount = Math.Round(cartProducts.products.amount - promotionMoney, 2); + return promotionMoney; + } + } }