【新增】优惠券及全局优惠的【指定商品减固定金额】【指定商品打X折】【指定商品一口价】,增加针对订单符合条件商品是只单个数量计算,还是针对满足条件商品的所有数量计算优惠。

【优化】订单详情不在针对优惠条件下,修改商品sku保存的优惠后单品售价,防止出现优惠模式下,购买多个同样商品,但是只计算一个商品数量优惠的情况,可能导致明细合计与订单计算合计歧义。
【修复】修复优惠券及全局优惠【指定商品每第几件减去指定金额】多次满足条件不叠加计算的问题。
【修复】修复优惠券未在领取有效期内,但是可以领取的问题。
This commit is contained in:
jianweie code
2023-11-07 14:54:04 +08:00
parent 6ac2ecb8ab
commit a65372ad11
7 changed files with 125 additions and 38 deletions

View File

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

View File

@@ -684,9 +684,10 @@ namespace CoreCms.Net.Services
public async Task<WebApiCallBack> ReceiveCoupon(int promotionId)
{
var jm = new WebApiCallBack();
var dt = DateTime.Now;
var where = PredicateBuilder.True<CoreCmsPromotion>();
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;

View File

@@ -211,14 +211,16 @@
<thead>
<tr>
<th>商品名称</th>
<th width="24">商品<br />单价</th>
<th width="24">购买<br />数量</th>
<th width="24">商品<br />总价</th>
<th width="130">货品编码</th>
<th width="130">商品编码</th>
<th>商品总重量</th>
<th width="24">发货<br />数量</th>
<th width="24">退货<br /></th>
<th width="30">商品<br />单价</th>
<th width="30">购买<br />数量</th>
<th width="30">优惠<br />金额</th>
<th width="40">商品<br />总价</th>
<th width="110">优惠券名称</th>
<th width="120">货品编码</th>
<th width="120">商品编码</th>
<th width="30">商品总重</th>
<th width="30">发货<br />数量</th>
<th width="30">退货<br />数量</th>
</tr>
</thead>
<tbody>
@@ -227,7 +229,9 @@
<td>{{item.name}} - {{item.addon}}</td>
<td>{{item.price}}</td>
<td>{{item.nums}}</td>
<td>{{item.promotionAmount}}</td>
<td>{{item.amount}}</td>
<td>{{# if(item.promotionObj){ }}{{item.promotionObj.name}}{{# } else { }}{{# } }}</td>
<td>{{item.sn}}</td>
<td>{{item.bn}}</td>
<td>{{item.weight}}</td>

View File

@@ -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("请输入金额");

View File

@@ -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) {

View File

@@ -35,6 +35,15 @@
</div>
<div class="layui-form-mid layui-word-aux">商品优惠的金额</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">商品范围</label>
<div class="layui-input-inline layui-inline-4">
<input type="radio" name="isApplyToNum" value="1" title="一个数量" checked>
<input type="radio" name="isApplyToNum" value="2" title="所有数量">
</div>
<div class="layui-form-mid layui-word-aux">是否针对所有数量都计算优惠</div>
</div>
</script>
<script id="goods_discount_tpl" type="text/html">
<div class="layui-form-item">
@@ -48,6 +57,14 @@
</div>
<div class="layui-form-mid layui-word-aux">大于0小于10的数字</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">商品范围</label>
<div class="layui-input-inline layui-inline-4">
<input type="radio" name="isApplyToNum" value="1" title="一个数量" checked>
<input type="radio" name="isApplyToNum" value="2" title="所有数量">
</div>
<div class="layui-form-mid layui-word-aux">是否针对所有数量都计算优惠</div>
</div>
</script>
<script id="goods_one_price_tpl" type="text/html">
<div class="layui-form-item">
@@ -61,6 +78,14 @@
</div>
<div class="layui-form-mid layui-word-aux">商品的固定价格</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">商品范围</label>
<div class="layui-input-inline layui-inline-4">
<input type="radio" name="isApplyToNum" value="1" title="一个数量" checked>
<input type="radio" name="isApplyToNum" value="2" title="所有数量">
</div>
<div class="layui-form-mid layui-word-aux">是否针对所有数量都计算优惠</div>
</div>
</script>
<script id="order_reduce_tpl" type="text/html">
<div class="layui-form-item">
@@ -94,11 +119,11 @@
<div class="layui-form-mid">指定商品每第几件减去指定金额</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">第几件</label>
<label class="layui-form-label">第几件</label>
<div class="layui-input-inline seller-inline-2">
<input name="num" lay-verType="tips" lay-verify="required|number" autocomplete="off" value="1" placeholder="" class="layui-input" type="number">
</div>
<div class="layui-form-mid layui-word-aux">每第几件商品</div>
<div class="layui-form-mid layui-word-aux">如设置2下单10那么就5*优惠金额</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">优惠金额</label>

View File

@@ -36,6 +36,14 @@
</div>
<div class="layui-form-mid layui-word-aux">商品优惠的金额</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">商品范围</label>
<div class="layui-input-inline layui-inline-4">
<input type="radio" name="isApplyToNum" value="1" title="一个数量" {{d.isApplyToNum=="1"?'checked':''}}>
<input type="radio" name="isApplyToNum" value="2" title="所有数量" {{d.isApplyToNum=="2"?'checked':''}}>
</div>
<div class="layui-form-mid layui-word-aux">是否针对所有数量都计算优惠</div>
</div>
</script>
<script id="goods_discount_tpl" type="text/html">
<div class="layui-form-item">
@@ -49,6 +57,14 @@
</div>
<div class="layui-form-mid layui-word-aux">大于0小于10的数字</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">商品范围</label>
<div class="layui-input-inline layui-inline-4">
<input type="radio" name="isApplyToNum" value="1" title="一个数量" {{d.isApplyToNum=="1"?'checked':''}}>
<input type="radio" name="isApplyToNum" value="2" title="所有数量" {{d.isApplyToNum=="2"?'checked':''}}>
</div>
<div class="layui-form-mid layui-word-aux">是否针对所有数量都计算优惠</div>
</div>
</script>
<script id="goods_one_price_tpl" type="text/html">
<div class="layui-form-item">
@@ -62,6 +78,14 @@
</div>
<div class="layui-form-mid layui-word-aux">商品的固定价格</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">商品范围</label>
<div class="layui-input-inline layui-inline-4">
<input type="radio" name="isApplyToNum" value="1" title="一个数量" {{d.isApplyToNum=="1"?'checked':''}}>
<input type="radio" name="isApplyToNum" value="2" title="所有数量" {{d.isApplyToNum=="2"?'checked':''}}>
</div>
<div class="layui-form-mid layui-word-aux">是否针对所有数量都计算优惠</div>
</div>
</script>
<script id="order_reduce_tpl" type="text/html">
<div class="layui-form-item">
@@ -95,11 +119,11 @@
<div class="layui-form-mid">指定商品每第几件减去指定金额</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">第几件</label>
<label class="layui-form-label">第几件</label>
<div class="layui-input-inline seller-inline-2">
<input name="num" lay-verType="tips" lay-verify="required|number" autocomplete="off" value="{{d.num}}" placeholder="" class="layui-input" type="number">
</div>
<div class="layui-form-mid layui-word-aux">每第几件商品</div>
<div class="layui-form-mid layui-word-aux">如设置2下单10那么就5*优惠金额</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">优惠金额</label>