【修复】修复秒杀团购限制个人购买数量的问题。

This commit is contained in:
大灰灰
2022-06-02 00:49:21 +08:00
parent 621c3e5cfb
commit 36c76eca63

View File

@@ -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;