From a65372ad1175b1a02436191d967459e2480d4c65 Mon Sep 17 00:00:00 2001 From: jianweie code Date: Tue, 7 Nov 2023 14:54:04 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=88=B8=E5=8F=8A=E5=85=A8=E5=B1=80=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E7=9A=84=E3=80=90=E6=8C=87=E5=AE=9A=E5=95=86=E5=93=81=E5=87=8F?= =?UTF-8?q?=E5=9B=BA=E5=AE=9A=E9=87=91=E9=A2=9D=E3=80=91=E3=80=90=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E5=95=86=E5=93=81=E6=89=93X=E6=8A=98=E3=80=91?= =?UTF-8?q?=E3=80=90=E6=8C=87=E5=AE=9A=E5=95=86=E5=93=81=E4=B8=80=E5=8F=A3?= =?UTF-8?q?=E4=BB=B7=E3=80=91,=E5=A2=9E=E5=8A=A0=E9=92=88=E5=AF=B9?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=AC=A6=E5=90=88=E6=9D=A1=E4=BB=B6=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=98=AF=E5=8F=AA=E5=8D=95=E4=B8=AA=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=EF=BC=8C=E8=BF=98=E6=98=AF=E9=92=88=E5=AF=B9?= =?UTF-8?q?=E6=BB=A1=E8=B6=B3=E6=9D=A1=E4=BB=B6=E5=95=86=E5=93=81=E7=9A=84?= =?UTF-8?q?=E6=89=80=E6=9C=89=E6=95=B0=E9=87=8F=E8=AE=A1=E7=AE=97=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E3=80=82=20=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=AF=A6=E6=83=85=E4=B8=8D=E5=9C=A8=E9=92=88?= =?UTF-8?q?=E5=AF=B9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?q?=E9=87=91=E9=A2=9D=E3=80=91=E5=A4=9A=E6=AC=A1=E6=BB=A1=E8=B6=B3?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E4=B8=8D=E5=8F=A0=E5=8A=A0=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82=20=E3=80=90=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E3=80=91=E4=BF=AE=E5=A4=8D=E4=BC=98=E6=83=A0=E5=88=B8?= =?UTF-8?q?=E6=9C=AA=E5=9C=A8=E9=A2=86=E5=8F=96=E6=9C=89=E6=95=88=E6=9C=9F?= =?UTF-8?q?=E5=86=85=EF=BC=8C=E4=BD=86=E6=98=AF=E5=8F=AF=E4=BB=A5=E9=A2=86?= =?UTF-8?q?=E5=8F=96=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CoreCmsPromotionResultServices.cs | 45 ++++++++++++------- .../Promotion/CoreCmsPromotionServices.cs | 11 ++++- .../wwwroot/views/order/orders/details.html | 20 +++++---- .../wwwroot/views/promotion/coupon/edit.html | 14 ++++-- .../views/promotion/promotion/edit.html | 16 ++++--- .../promotion/promotion/resultcreate.html | 29 +++++++++++- .../views/promotion/promotion/resultedit.html | 28 +++++++++++- 7 files changed, 125 insertions(+), 38 deletions(-) diff --git a/CoreCms.Net.Services/Promotion/CoreCmsPromotionResultServices.cs b/CoreCms.Net.Services/Promotion/CoreCmsPromotionResultServices.cs index 17c67d3d..f3ab7287 100644 --- a/CoreCms.Net.Services/Promotion/CoreCmsPromotionResultServices.cs +++ b/CoreCms.Net.Services/Promotion/CoreCmsPromotionResultServices.cs @@ -258,6 +258,7 @@ namespace CoreCms.Net.Services { if (!parameters.ContainsKey("money")) return 0; var objMoney = parameters["money"].ObjectToDecimal(0); + var isApplyToNum = parameters["isApplyToNum"].ObjectToInt(1); decimal promotionMoney = 0; //判断极端情况,减的太多,超过商品单价了,那么就最多减到0 @@ -265,11 +266,12 @@ namespace CoreCms.Net.Services { objMoney = cartProducts.products.price; } - cartProducts.products.price = Math.Round(cartProducts.products.price - objMoney, 2); + //此处不存储优惠后单价,防止出现针对单个产品,多个数量情况下,单一优惠券无法针对每个数量的商品进行计算售价。 + //cartProducts.products.price = Math.Round(cartProducts.products.price - objMoney, 2); //此次商品促销一共优惠了多少钱 - promotionMoney = promotionInfo.type == (int)GlobalEnumVars.PromotionType.Coupon ? objMoney : Math.Round(cartProducts.nums * objMoney, 2); + promotionMoney = promotionInfo.type == (int)GlobalEnumVars.PromotionType.Coupon ? isApplyToNum == 1 ? objMoney : Math.Round(cartProducts.nums * objMoney, 2) : Math.Round(cartProducts.nums * objMoney, 2); //设置商品优惠总金额 - cartProducts.products.promotionAmount = Math.Round(cartProducts.products.promotionAmount + objMoney, 2); + cartProducts.products.promotionAmount = Math.Round(cartProducts.products.promotionAmount + promotionMoney, 2); //设置商品的实际销售金额(单品) cartProducts.products.amount = Math.Round(cartProducts.products.amount - promotionMoney, 2); return promotionMoney; @@ -286,13 +288,22 @@ namespace CoreCms.Net.Services { if (!parameters.ContainsKey("discount")) return 0; var objDiscount = parameters["discount"].ObjectToDecimal(0); + var isApplyToNum = parameters["isApplyToNum"].ObjectToInt(1); + + //判断参数是否设置的正确 + if (objDiscount >= 10 || objDiscount <= 0) + { + return 0; + } - decimal promotionMoney = 0; decimal goodsPrice = cartProducts.products.price; - cartProducts.products.price = Math.Round(Math.Round(Math.Round(cartProducts.products.price * objDiscount, 3) * 10, 2) / 100, 2); + //此处不存储优惠后单价,防止出现针对单个产品,多个数量情况下,单一优惠券无法针对每个数量的商品进行计算售价。 + //cartProducts.products.price = Math.Round(Math.Round(Math.Round(cartProducts.products.price * objDiscount, 3) * 10, 2) / 100, 2); + var productsPrice = Math.Round(Math.Round(Math.Round(cartProducts.products.price * objDiscount, 3) * 10, 2) / 100, 2); + //单品优惠的金额 - var pmoney = Math.Round(goodsPrice - cartProducts.products.price, 2); - promotionMoney = promotionInfo.type == (int)GlobalEnumVars.PromotionType.Coupon ? pmoney : Math.Round(cartProducts.nums * pmoney, 2); + var pmoney = Math.Round(goodsPrice - productsPrice, 2); + var promotionMoney = promotionInfo.type == (int)GlobalEnumVars.PromotionType.Coupon ? isApplyToNum == 1 ? pmoney : Math.Round(cartProducts.nums * pmoney, 2) : Math.Round(cartProducts.nums * pmoney, 2); //设置商品优惠总金额 cartProducts.products.promotionAmount = Math.Round(cartProducts.products.promotionAmount + promotionMoney, 2); //设置商品的实际销售总金额 @@ -306,6 +317,7 @@ namespace CoreCms.Net.Services { if (!parameters.ContainsKey("money")) return 0; var objMoney = parameters["money"].ObjectToDecimal(0); + var isApplyToNum = parameters["isApplyToNum"].ObjectToInt(1); //如果一口价比商品价格高,那么就不执行了 decimal promotionMoney = 0; @@ -314,10 +326,12 @@ namespace CoreCms.Net.Services return promotionMoney; } var goodsPrice = (decimal)cartProducts.products.price; - cartProducts.products.price = Math.Round(objMoney, 2); + //此处不存储优惠后单价,防止出现针对单个产品,多个数量情况下,单一优惠券无法针对每个数量的商品进行计算售价。 + //cartProducts.products.price = Math.Round(objMoney, 2); + var productsPrice = Math.Round(objMoney, 2); //单品优惠的金额 - var pmoney = Math.Round(goodsPrice - cartProducts.products.price, 2); - promotionMoney = promotionInfo.type == (int)GlobalEnumVars.PromotionType.Coupon ? pmoney : Math.Round(cartProducts.nums * pmoney, 2); + var pmoney = Math.Round(goodsPrice - productsPrice, 2); + promotionMoney = promotionInfo.type == (int)GlobalEnumVars.PromotionType.Coupon ? isApplyToNum == 1 ? pmoney : Math.Round(cartProducts.nums * pmoney, 2) : Math.Round(cartProducts.nums * pmoney, 2); //设置商品优惠总金额 cartProducts.products.promotionAmount = Math.Round(cartProducts.products.promotionAmount + promotionMoney, 2); //设置商品的实际销售总金额 @@ -344,11 +358,12 @@ namespace CoreCms.Net.Services if (cartProducts.nums >= num) { - //var promotionNum = buyNum / num; - var pmoney = Math.Round(objMoney / buyNum, 2); //单品优惠的金额 - var goodsPrice = (decimal)cartProducts.products.price; - cartProducts.products.price = goodsPrice - pmoney; //优惠后的平均价格 - promotionMoney = Math.Round(cartProducts.nums * pmoney, 2);//优惠金额 + var promotionNum = buyNum / num; + //var pmoney = Math.Round(objMoney / buyNum, 2); //单品优惠的金额 + //var goodsPrice = (decimal)cartProducts.products.price; + //此处不存储优惠后单价,防止出现针对单个产品,多个数量情况下,单一优惠券无法针对每个数量的商品进行计算售价。 + //cartProducts.products.price = goodsPrice - pmoney; //优惠后的平均价格 + promotionMoney = Math.Round(promotionNum * objMoney, 2);//优惠金额 //设置商品优惠总金额 cartProducts.products.promotionAmount = Math.Round(cartProducts.products.promotionAmount + promotionMoney, 2); diff --git a/CoreCms.Net.Services/Promotion/CoreCmsPromotionServices.cs b/CoreCms.Net.Services/Promotion/CoreCmsPromotionServices.cs index b04aa66f..3ea331e4 100644 --- a/CoreCms.Net.Services/Promotion/CoreCmsPromotionServices.cs +++ b/CoreCms.Net.Services/Promotion/CoreCmsPromotionServices.cs @@ -684,9 +684,10 @@ namespace CoreCms.Net.Services public async Task ReceiveCoupon(int promotionId) { var jm = new WebApiCallBack(); - + var dt = DateTime.Now; var where = PredicateBuilder.True(); - where = where.And(p => p.endTime > DateTime.Now); //判断优惠券失效时间 是否可领取 + where = where.And(p => p.endTime > dt); //判断优惠券失效时间 是否可领取 + //where = where.And(p => p.startTime < dt); where = where.And(p => p.isEnable == true); //启用状态 where = where.And(p => p.type == (int)GlobalEnumVars.PromotionType.Coupon); //促销 类型 where = where.And(p => p.isAutoReceive == true); //自动领取状态 @@ -699,6 +700,12 @@ namespace CoreCms.Net.Services { jm.data = info; //判断最大领取数量 + if (info.endTime < dt || info.startTime > dt) + { + jm.status = false; + jm.msg = "请在领取时间范围内领取"; + return jm; + } if (info.maxRecevieNums == 0) { jm.status = true; diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/order/orders/details.html b/CoreCms.Net.Web.Admin/wwwroot/views/order/orders/details.html index 6ce5d247..286dbe49 100644 --- a/CoreCms.Net.Web.Admin/wwwroot/views/order/orders/details.html +++ b/CoreCms.Net.Web.Admin/wwwroot/views/order/orders/details.html @@ -211,14 +211,16 @@ 商品名称 - 商品
单价 - 购买
数量 - 商品
总价 - 货品编码 - 商品编码 - 商品总重量 - 发货
数量 - 退货
数量 + 商品
单价 + 购买
数量 + 优惠
金额 + 商品
总价 + 优惠券名称 + 货品编码 + 商品编码 + 商品总重量 + 发货
数量 + 退货
数量 @@ -227,7 +229,9 @@ {{item.name}} - {{item.addon}} {{item.price}} {{item.nums}} + {{item.promotionAmount}} {{item.amount}} + {{# if(item.promotionObj){ }}{{item.promotionObj.name}}{{# } else { }}{{# } }} {{item.sn}} {{item.bn}} {{item.weight}} diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/promotion/coupon/edit.html b/CoreCms.Net.Web.Admin/wwwroot/views/promotion/coupon/edit.html index fe834093..ce96989c 100644 --- a/CoreCms.Net.Web.Admin/wwwroot/views/promotion/coupon/edit.html +++ b/CoreCms.Net.Web.Admin/wwwroot/views/promotion/coupon/edit.html @@ -123,9 +123,9 @@ , where: { promotionId: d.params.data.model.id } , method: 'POST' , cols: [[ //标题栏 - { field: 'code', width: 120, title: '条件代码' }, + { field: 'code', width: 150, title: '条件代码' }, { - field: 'code', title: '条件名称', width: 150, templet: function (data) { + field: 'code', title: '条件名称', width: 200, templet: function (data) { if (data.code) { for (var i = 0; i < d.params.data.promotionConditionTypes.length; i++) { if (data.code == d.params.data.promotionConditionTypes[i].sKey) { @@ -156,9 +156,9 @@ , where: { promotionId: d.params.data.model.id } , method: 'POST' , cols: [[ //标题栏 - { field: 'code', width: 120, title: '结果代码' }, + { field: 'code', width: 150, title: '结果代码' }, { - field: 'code', title: '条件名称', width: 150, templet: function (data) { + field: 'code', title: '条件名称', width: 200, templet: function (data) { if (data.code) { for (var i = 0; i < d.params.data.promotionResultTypes.length; i++) { if (data.code == d.params.data.promotionResultTypes[i].sKey) { @@ -416,18 +416,21 @@ return false; } parameters.money = field.money; + parameters.isApplyToNum = field.isApplyToNum; } else if (field.code === 'GOODS_DISCOUNT') { //指定商品打X折 if (!!!field.discount) { layer.msg("请输入折扣"); return false; } parameters.discount = field.discount; + parameters.isApplyToNum = field.isApplyToNum; } else if (field.code === 'GOODS_ONE_PRICE') {//指定商品一口价 if (!!!field.money) { layer.msg("请输入金额"); return false; } parameters.money = field.money; + parameters.isApplyToNum = field.isApplyToNum; } else if (field.code === 'ORDER_REDUCE') {//订单减指定金额 if (!!!field.money) { layer.msg("请输入金额"); @@ -511,18 +514,21 @@ return false; } parameters.money = field.money; + parameters.isApplyToNum = field.isApplyToNum; } else if (field.code === 'GOODS_DISCOUNT') { //指定商品打X折 if (!!!field.discount) { layer.msg("请输入折扣"); return false; } parameters.discount = field.discount; + parameters.isApplyToNum = field.isApplyToNum; } else if (field.code === 'GOODS_ONE_PRICE') {//指定商品一口价 if (!!!field.money) { layer.msg("请输入金额"); return false; } parameters.money = field.money; + parameters.isApplyToNum = field.isApplyToNum; } else if (field.code === 'ORDER_REDUCE') {//订单减指定金额 if (!!!field.money) { layer.msg("请输入金额"); diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/promotion/promotion/edit.html b/CoreCms.Net.Web.Admin/wwwroot/views/promotion/promotion/edit.html index 6744d1a3..fa0594cc 100644 --- a/CoreCms.Net.Web.Admin/wwwroot/views/promotion/promotion/edit.html +++ b/CoreCms.Net.Web.Admin/wwwroot/views/promotion/promotion/edit.html @@ -90,7 +90,7 @@ , cols: [[ //标题栏 { field: 'code', width: 150, title: '条件代码' }, { - field: 'code', title: '条件名称', width: 150, templet: function (data) { + field: 'code', title: '条件名称', width: 200, templet: function (data) { if (data.code) { for (var i = 0; i < d.params.data.promotionConditionTypes.length; i++) { if (data.code == d.params.data.promotionConditionTypes[i].sKey) { @@ -123,7 +123,7 @@ , cols: [[ //标题栏 { field: 'code', width: 150, title: '结果代码' }, { - field: 'code', title: '条件名称', width: 150, templet: function (data) { + field: 'code', title: '条件名称', width: 200, templet: function (data) { if (data.code) { for (var i = 0; i < d.params.data.promotionResultTypes.length; i++) { if (data.code == d.params.data.promotionResultTypes[i].sKey) { @@ -365,7 +365,7 @@ form.on('submit(LAY-app-CoreCmsPromotionResult-createForm-submit)', function (data) { var field = data.field; //获取提交的字段 - + console.log(field); if (!!!field.code) { layer.msg("请先选择促销条件"); return false; @@ -381,18 +381,21 @@ return false; } parameters.money = field.money; + parameters.isApplyToNum = field.isApplyToNum; } else if (field.code === 'GOODS_DISCOUNT') { //指定商品打X折 if (!!!field.discount) { layer.msg("请输入折扣"); return false; } parameters.discount = field.discount; + parameters.isApplyToNum = field.isApplyToNum; } else if (field.code === 'GOODS_ONE_PRICE') {//指定商品一口价 if (!!!field.money) { layer.msg("请输入金额"); return false; } parameters.money = field.money; + parameters.isApplyToNum = field.isApplyToNum; } else if (field.code === 'ORDER_REDUCE') {//订单减指定金额 if (!!!field.money) { layer.msg("请输入金额"); @@ -418,7 +421,7 @@ parameters.money = field.money; } postData.parameters = JSON.stringify(parameters); - if (debug) { console.log(field); console.log(postData); } //开启调试返回数据 + if (debug) { console.log('field', field); console.log('postData', postData); } //开启调试返回数据 //提交 Ajax 成功后,关闭当前弹层并重载表格 coreHelper.Post("Api/CoreCmsPromotion/DoResultCreate", postData, function (e) { if (e.code === 0) { @@ -476,18 +479,21 @@ return false; } parameters.money = field.money; + parameters.isApplyToNum = field.isApplyToNum; } else if (field.code === 'GOODS_DISCOUNT') { //指定商品打X折 if (!!!field.discount) { layer.msg("请输入折扣"); return false; } parameters.discount = field.discount; + parameters.isApplyToNum = field.isApplyToNum; } else if (field.code === 'GOODS_ONE_PRICE') {//指定商品一口价 if (!!!field.money) { layer.msg("请输入金额"); return false; } parameters.money = field.money; + parameters.isApplyToNum = field.isApplyToNum; } else if (field.code === 'ORDER_REDUCE') {//订单减指定金额 if (!!!field.money) { layer.msg("请输入金额"); @@ -513,7 +519,7 @@ parameters.money = field.money; } postData.parameters = JSON.stringify(parameters); - if (debug) { console.log(field); console.log(postData); } //开启调试返回数据 + if (debug) { console.log('field', field); console.log('postData', postData); } //开启调试返回数据 //提交 Ajax 成功后,关闭当前弹层并重载表格 coreHelper.Post("Api/CoreCmsPromotion/DoResultEdit", postData, function (e) { if (e.code === 0) { diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/promotion/promotion/resultcreate.html b/CoreCms.Net.Web.Admin/wwwroot/views/promotion/promotion/resultcreate.html index 6a4aa697..46793480 100644 --- a/CoreCms.Net.Web.Admin/wwwroot/views/promotion/promotion/resultcreate.html +++ b/CoreCms.Net.Web.Admin/wwwroot/views/promotion/promotion/resultcreate.html @@ -35,6 +35,15 @@
商品优惠的金额
+
+ +
+ + +
+
是否针对所有数量都计算优惠
+
+