From 36c76eca635efd56a32dc98bb909b510b13ee274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=81=B0=E7=81=B0?= Date: Thu, 2 Jun 2022 00:49:21 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E7=A7=92=E6=9D=80=E5=9B=A2=E8=B4=AD=E9=99=90=E5=88=B6?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E8=B4=AD=E4=B9=B0=E6=95=B0=E9=87=8F=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Promotion/CoreCmsPromotionServices.cs | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/CoreCms.Net.Services/Promotion/CoreCmsPromotionServices.cs b/CoreCms.Net.Services/Promotion/CoreCmsPromotionServices.cs index 3a462c31..6515a946 100644 --- a/CoreCms.Net.Services/Promotion/CoreCmsPromotionServices.cs +++ b/CoreCms.Net.Services/Promotion/CoreCmsPromotionServices.cs @@ -20,8 +20,8 @@ using CoreCms.Net.Loging; using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.Entities.Expression; using CoreCms.Net.Model.ViewModels.Basics; -using CoreCms.Net.Model.ViewModels.UI; using CoreCms.Net.Model.ViewModels.DTO; +using CoreCms.Net.Model.ViewModels.UI; using CoreCms.Net.Utility.Extensions; using CoreCms.Net.Utility.Helper; using Microsoft.AspNetCore.Mvc; @@ -223,6 +223,7 @@ namespace CoreCms.Net.Services { JObject parameters = (JObject)JsonConvert.DeserializeObject(condition.parameters); + var res = await GetGroupDetail(parameters["goodsId"].ObjectToInt(0), userId, "group", item.id); if (res.status) { @@ -312,25 +313,32 @@ namespace CoreCms.Net.Services } //调整前台显示数量 - if (!string.IsNullOrEmpty(promotion.parameters)) - { - var extendParams = (JObject)JsonConvert.DeserializeObject(promotion.parameters); - var checkOrder = orderServices.FindLimitOrder(goods.product.id, userId, promotion.startTime, promotion.endTime); + var checkOrder = orderServices.FindLimitOrder(goods.product.id, userId, promotion.startTime, promotion.endTime, promotion.type); - if (extendParams != null && extendParams.ContainsKey("max_goods_nums") && extendParams["max_goods_nums"].ObjectToInt(0) != 0) - { - var maxGoodsNums = extendParams["max_goods_nums"].ObjectToInt(0); - goods.stock = maxGoodsNums; - //活动销售件数 - goods.product.stock = maxGoodsNums - checkOrder.TotalOrders; - goods.buyPromotionCount = checkOrder.TotalOrders; - } - else - { - goods.buyPromotionCount = checkOrder.TotalOrders; - } + var productStock = goods.product.stock; + + //如果最大为设置值 + if (promotion.maxGoodsNums > 0) + { + //最多只能买这么多 + goods.stock = promotion.maxGoodsNums; + //然后实际能买的要减去以前买的 + goods.product.stock = checkOrder.TotalOrders - promotion.maxGoodsNums >= 0 ? 0 : promotion.maxGoodsNums - checkOrder.TotalOrders; } + //如果设置了限购数量 + if (promotion.maxNums > 0) + { + //最多只能买这么多 + goods.stock = promotion.maxNums; + //实际可购买数量为:实际消费数量-最大可消费数量,如果大于或者等于,就不能买了。库存为0,或最大购买数减去已经购买数 + goods.product.stock = checkOrder.TotalOrders - promotion.maxNums >= 0 ? 0 : promotion.maxNums - checkOrder.TotalOrders; + } + + + goods.buyPromotionCount = checkOrder.TotalOrders; + + var dt = DateTime.Now; goods.groupId = promotion.id;