Commit fdfa5dd0 authored by liudong1993's avatar liudong1993

调整下单优惠券+积分抵扣

parent f367d62e
...@@ -204,5 +204,9 @@ namespace Mall.Model.Entity.Product ...@@ -204,5 +204,9 @@ namespace Mall.Model.Entity.Product
/// 成本单据ID /// 成本单据ID
/// </summary> /// </summary>
public int CostFinanceId { get; set; } public int CostFinanceId { get; set; }
/// <summary>
/// 积分赠送
/// </summary>
public int? IntegralGoodsPresent { get; set; }
} }
} }
...@@ -94,5 +94,9 @@ namespace Mall.Model.Entity.User ...@@ -94,5 +94,9 @@ namespace Mall.Model.Entity.User
/// 备注 /// 备注
/// </summary> /// </summary>
public string Remarks { get; set; } public string Remarks { get; set; }
/// <summary>
/// 订单id
/// </summary>
public int? OrderId { get; set; }
} }
} }
...@@ -2016,6 +2016,8 @@ namespace Mall.Module.Product ...@@ -2016,6 +2016,8 @@ namespace Mall.Module.Product
decimal TotalExpress = 0; decimal TotalExpress = 0;
decimal TotalMoney = 0; decimal TotalMoney = 0;
string GoodsIds = ""; string GoodsIds = "";
int TotalIntegralNumber = 0;//总使用积分
decimal TotalIntegralMoney = 0;//总使用积分抵扣金额
List<RB_Goods_CouponModel> GoodsCouponList = new List<RB_Goods_CouponModel>();//商品优惠卷 价格(每个商品优惠的价格) List<RB_Goods_CouponModel> GoodsCouponList = new List<RB_Goods_CouponModel>();//商品优惠卷 价格(每个商品优惠的价格)
decimal CouponsMoney = 0;//优惠卷验证 decimal CouponsMoney = 0;//优惠卷验证
#region 优惠卷初始化 #region 优惠卷初始化
...@@ -2405,6 +2407,8 @@ namespace Mall.Module.Product ...@@ -2405,6 +2407,8 @@ namespace Mall.Module.Product
} }
if (demodel.Use_Integral == 1) if (demodel.Use_Integral == 1)
{ {
TotalIntegralNumber += (item.IntegralNumber ?? 0);
TotalIntegralMoney += (item.IntegralMoney ?? 0);
item.Final_Price -= (item.IntegralMoney ?? 0); item.Final_Price -= (item.IntegralMoney ?? 0);
} }
#endregion #endregion
...@@ -2600,6 +2604,24 @@ namespace Mall.Module.Product ...@@ -2600,6 +2604,24 @@ namespace Mall.Module.Product
if (umodel.CouponsNum < 0) { umodel.CouponsNum = 0; } if (umodel.CouponsNum < 0) { umodel.CouponsNum = 0; }
keyValues.Add(nameof(RB_Member_User_Extend.CouponsNum), umodel.CouponsNum); keyValues.Add(nameof(RB_Member_User_Extend.CouponsNum), umodel.CouponsNum);
} }
if (demodel.Use_Integral == 1 && TotalIntegralNumber > 0) {
keyValues.Add(nameof(RB_Member_User_Extend.Integral), (umodel.Integral ?? 0));
member_IntegralRepository.Insert(new Model.Entity.User.RB_Member_Integral()
{
Id = 0,
CreateDate = DateTime.Now,
Description = "订单使用积分抵扣" + TotalIntegralMoney + "元",
Image = 0,
Integral = TotalIntegralNumber,
MallBaseId = demodel.MallBaseId,
PlatformType = demodel.OrderSource,
Remarks = "",
TenantId = demodel.TenantId,
Type = Common.Enum.MarketingCenter.RecordTypeEnum.Expend,
UserId = demodel.UserId,
OrderId = OrderId
}, trans);
}
List<WhereHelper> wheres = new List<WhereHelper>() { List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){ new WhereHelper(){
...@@ -3358,9 +3380,17 @@ namespace Mall.Module.Product ...@@ -3358,9 +3380,17 @@ namespace Mall.Module.Product
/// <param name="OrderId"></param> /// <param name="OrderId"></param>
private void InsertOrderDetail(RB_Goods_Order_Extend demodel, System.Data.IDbTransaction trans, int OrderId) private void InsertOrderDetail(RB_Goods_Order_Extend demodel, System.Data.IDbTransaction trans, int OrderId)
{ {
int IntegralPresentTotal = 0;
foreach (var item in demodel.DetailList) foreach (var item in demodel.DetailList)
{ {
int IntegralPresent = item.IntegralPresent ?? 0;
//积分
if (item.IntegralPresent > 0)
{
if (item.IntegralPresentType == 1)
{
IntegralPresent = Convert.ToInt32(((item.Final_Price ?? 0) + (item.FreightMoney ?? 0)) * (item.IntegralPresent ?? 0) / 100);
}
}
//插入订单明细表 //插入订单明细表
int detailId = goods_OrderDetailRepository.Insert(new RB_Goods_OrderDetail() int detailId = goods_OrderDetailRepository.Insert(new RB_Goods_OrderDetail()
{ {
...@@ -3385,22 +3415,11 @@ namespace Mall.Module.Product ...@@ -3385,22 +3415,11 @@ namespace Mall.Module.Product
TenantId = demodel.TenantId, TenantId = demodel.TenantId,
UpdateDate = DateTime.Now, UpdateDate = DateTime.Now,
IsComment = 2, IsComment = 2,
FreightMoney = item.FreightMoney FreightMoney = item.FreightMoney,
IntegralGoodsPresent = IntegralPresent
}, trans); }, trans);
item.Id = detailId; item.Id = detailId;
//积分
if (item.IntegralPresent > 0)
{
int IntegralPresent = item.IntegralPresent ?? 0;
if (item.IntegralPresentType == 1)
{
IntegralPresent = Convert.ToInt32(((item.Final_Price ?? 0) + (item.FreightMoney ?? 0)) * (item.IntegralPresent ?? 0) / 100);
}
if (IntegralPresent > 0)
{
IntegralPresentTotal += IntegralPresent;
}
}
//更新商品数量 //更新商品数量
Dictionary<string, object> keyValues = new Dictionary<string, object>() { Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_Goods.InventoryNum),item.InventoryNum-(item.Number??0)} { nameof(RB_Goods.InventoryNum),item.InventoryNum-(item.Number??0)}
...@@ -3456,7 +3475,7 @@ namespace Mall.Module.Product ...@@ -3456,7 +3475,7 @@ namespace Mall.Module.Product
goods_SpecificationPriceRepository.Update(keyValuesp, wheresp, trans); goods_SpecificationPriceRepository.Update(keyValuesp, wheresp, trans);
} }
//记录日志 //记录日志
Task.Run(() => goods_LogRepository.Insert(new RB_Goods_Log() goods_LogRepository.Insert(new RB_Goods_Log()
{ {
Id = 0, Id = 0,
Type = 2, Type = 2,
...@@ -3465,26 +3484,27 @@ namespace Mall.Module.Product ...@@ -3465,26 +3484,27 @@ namespace Mall.Module.Product
CreateDate = DateTime.Now, CreateDate = DateTime.Now,
MallBaseId = demodel.MallBaseId, MallBaseId = demodel.MallBaseId,
TenantId = demodel.TenantId TenantId = demodel.TenantId
})); }, trans);
}
} }
if (IntegralPresentTotal > 0)
{
member_IntegralRepository.Insert(new Model.Entity.User.RB_Member_Integral()
{
Id = 0,
CreateDate = DateTime.Now,
Description = "订单购买赠送积分",
Image = 0,
Integral = IntegralPresentTotal,
MallBaseId = demodel.MallBaseId,
PlatformType = demodel.OrderSource,
Remarks = "",
TenantId = demodel.TenantId,
Type = Common.Enum.MarketingCenter.RecordTypeEnum.Income,
UserId = demodel.UserId
});
} }
//if (IntegralPresentTotal > 0)
//{
// member_IntegralRepository.Insert(new Model.Entity.User.RB_Member_Integral()
// {
// Id = 0,
// CreateDate = DateTime.Now,
// Description = "订单购买赠送积分",
// Image = 0,
// Integral = IntegralPresentTotal,
// MallBaseId = demodel.MallBaseId,
// PlatformType = demodel.OrderSource,
// Remarks = "",
// TenantId = demodel.TenantId,
// Type = Common.Enum.MarketingCenter.RecordTypeEnum.Income,
// UserId = demodel.UserId,
// OrderId = OrderId
// }, trans);
//}
} }
/// <summary> /// <summary>
...@@ -3568,6 +3588,7 @@ namespace Mall.Module.Product ...@@ -3568,6 +3588,7 @@ namespace Mall.Module.Product
//回滚商品库存 //回滚商品库存
if (type == 1) if (type == 1)
{ {
int TotalIntegralNumber = 0;
var detailList = goods_OrderDetailRepository.GetOrderDetailList(new RB_Goods_OrderDetail_Extend() { GoodsId = omodel.OrderId, TenantId = tenantId, MallBaseId = mallBaseId }); var detailList = goods_OrderDetailRepository.GetOrderDetailList(new RB_Goods_OrderDetail_Extend() { GoodsId = omodel.OrderId, TenantId = tenantId, MallBaseId = mallBaseId });
if (detailList.Any()) if (detailList.Any())
{ {
...@@ -3625,7 +3646,7 @@ namespace Mall.Module.Product ...@@ -3625,7 +3646,7 @@ namespace Mall.Module.Product
} }
}; };
goodsRepository.Update(keyValues1, wheres1, trans); goodsRepository.Update(keyValues1, wheres1, trans);
Task.Run(() => goods_LogRepository.Insert(new RB_Goods_Log() goods_LogRepository.Insert(new RB_Goods_Log()
{ {
Id = 0, Id = 0,
Type = 2, Type = 2,
...@@ -3634,10 +3655,48 @@ namespace Mall.Module.Product ...@@ -3634,10 +3655,48 @@ namespace Mall.Module.Product
CreateDate = DateTime.Now, CreateDate = DateTime.Now,
MallBaseId = mallBaseId, MallBaseId = mallBaseId,
TenantId = tenantId TenantId = tenantId
})); });
if (item.IntegralNumber > 0) {
TotalIntegralNumber += (item.IntegralNumber ?? 0);
} }
} }
} }
var umodel = member_UserRepository.GetEntity(omodel.UserId);
//积分抵扣回滚
if (TotalIntegralNumber > 0) {
Dictionary<string, object> keyValues1 = new Dictionary<string, object>() {
{ nameof(RB_Member_User_Extend.Integral),umodel.Integral + TotalIntegralNumber}
};
List<WhereHelper> wheres1 = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Member_User_Extend.Id),
FiledValue=umodel.Id,
OperatorEnum=OperatorEnum.Equal
}
};
member_UserRepository.Update(keyValues1, wheres1, trans);
}
//优惠券回滚
if (!string.IsNullOrEmpty(omodel.CouponsIds)) {
var cList = member_CouponRepository.GetList(new RB_Member_DiscountCoupon_Extend() { UseState = 1, Ids = omodel.CouponsIds, UserId = omodel.UserId, TenantId = omodel.TenantId, MallBaseId = omodel.MallBaseId });
foreach (var item in cList) {
Dictionary<string, object> keyValues1 = new Dictionary<string, object>() {
{ nameof(RB_Member_DiscountCoupon_Extend.UseState),0}
};
List<WhereHelper> wheres1 = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Member_DiscountCoupon_Extend.Id),
FiledValue=item.Id,
OperatorEnum=OperatorEnum.Equal
}
};
member_CouponRepository.Update(keyValues1, wheres1, trans);
}
}
//余额支付回滚
}
Task.Run(() => goods_LogRepository.Insert(new RB_Goods_Log() Task.Run(() => goods_LogRepository.Insert(new RB_Goods_Log()
{ {
Id = 0, Id = 0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment