Commit 163b0873 authored by liudong1993's avatar liudong1993

下单 全局包邮

parent 2d131a62
......@@ -23,6 +23,10 @@ namespace Mall.Model.Entity.Product
get;
set;
}
/// <summary>
/// 规则id
/// </summary>
public int? FreeshippingId { get; set; }
/// <summary>
/// 订单商品id
......
......@@ -39,6 +39,7 @@ namespace Mall.Model.Extend.BaseSetUp
/// </summary>
public class FreeShippingGoodsDetail {
public int FreeShipping { get; set; }
public int CategoryId { get; set; }
public string Name { get; set; }
public int GoodsId { get; set; }
public string SpecificationKey { get; set; }
......
......@@ -229,6 +229,10 @@ namespace Mall.Module.Product
/// </summary>
private readonly RB_SupplierCommissionRepository supplierCommissionRepository = new RB_SupplierCommissionRepository();
private RB_FreeShippingRepository freeShippingRepository = new RB_FreeShippingRepository();
/// <summary>
/// 全局包邮记录
/// </summary>
private RB_Goods_OrderDetailFreeShippingRepository orderDetailFreeShippingRepository = new RB_Goods_OrderDetailFreeShippingRepository();
#region 购物车
......@@ -1714,8 +1718,8 @@ namespace Mall.Module.Product
if (fullNumPinkageModel != null)
{
//看所有商品是否满足该规则
var sglist = SatisfiedGoodsList.Where(x => x.FreeShipping != fullNumPinkageModel.ID).ToList();
var nosglist = SatisfiedGoodsList.Where(x => x.FreeShipping == fullNumPinkageModel.ID).ToList();
var sglist = SatisfiedGoodsList.Where(x => x.FreeShipping == fullNumPinkageModel.ID).ToList();
var nosglist = SatisfiedGoodsList.Where(x => x.FreeShipping != fullNumPinkageModel.ID).ToList();
if (sglist.Any())
{
//看着商品是否包含在这里面
......@@ -1727,60 +1731,58 @@ namespace Mall.Module.Product
}
else
{
//查询出规格下所有的分类
List<int> GZCList = new List<int>();
if (fullNumPinkageModel.CategoryId > 0)
{
GZCList = freeShippingList.Where(x => x.ID == fullNumPinkageModel.ID).Select(x => x.CategoryId).ToList();
}
//根据分类 查询出所有的订单商品
//根据 查询出所有的订单商品
var SatisfiedGoodsList2 = new List<FreeShippingGoodsDetail>();
foreach (var qitem in demodel.DetailList)
{
var qgmodel = gList.Where(x => x.Id == qitem.GoodsId).FirstOrDefault();
if (qgmodel != null && qgmodel.GoodsStatus == 1 && (qgmodel.FullMoneyPinkage ?? 0) == 0 && (qgmodel.FullNumPinkage ?? 0) == 0)
{
if (!nosglist.Where(x => x.GoodsId == qitem.GoodsId && x.SpecificationKey == qitem.SpecificationSort).Any())
{
string Name = fullNumPinkageModel.Name;
if (fullNumPinkageModel.FullNumPinkage > 0) {
Name += ":满" + fullNumPinkageModel.FullNumPinkage + "件包邮";
}
else if(fullNumPinkageModel.FullMoneyPinkage > 0) {
Name += ":满" + fullNumPinkageModel.FullMoneyPinkage + "元包邮";
}
if (GZCList.Any())
var fpkModel = freeShippingList.Where(x => qitem.CategoryIdList.Contains(x.CategoryId) && x.IsFreeShipping == 1 && x.IsEnable == 1 && x.FullNumPinkage > 0 && x.CategoryId > 0).OrderBy(x => x.FullNumPinkage).ThenByDescending(x => x.ID).FirstOrDefault();
if (fpkModel == null || fpkModel.ID <= 0)
{
if (qitem.CategoryIdList.Where(x => GZCList.Contains(x)).Any())
fpkModel = freeShippingList.Where(x => qitem.CategoryIdList.Contains(x.CategoryId) && x.IsFreeShipping == 1 && x.IsEnable == 1 && x.FullMoneyPinkage > 0 && x.CategoryId > 0).OrderBy(x => x.FullMoneyPinkage).ThenByDescending(x => x.ID).FirstOrDefault();
}
if (fpkModel == null || fpkModel.ID <= 0)
{
SatisfiedGoodsList2.Add(new FreeShippingGoodsDetail()
fpkModel = freeShippingList.Where(x => qitem.CategoryIdList.Contains(x.CategoryId) && x.IsFreeShipping == 1 && x.IsEnable == 1 && x.FullNumPinkage > 0 && x.CategoryId == 0).OrderBy(x => x.FullNumPinkage).ThenByDescending(x => x.ID).FirstOrDefault();
}
if (fpkModel == null || fpkModel.ID <= 0)
{
FreeShipping = fullNumPinkageModel.ID,
Name = Name,
GoodsId = qitem.GoodsId ?? 0,
SpecificationKey = qitem.NewSpecificationSort,
Number = qitem.Number ?? 0,
Money = qitem.NorGoodsMoney
});
fpkModel = freeShippingList.Where(x => qitem.CategoryIdList.Contains(x.CategoryId) && x.IsFreeShipping == 1 && x.IsEnable == 1 && x.FullMoneyPinkage > 0 && x.CategoryId == 0).OrderBy(x => x.FullMoneyPinkage).ThenByDescending(x => x.ID).FirstOrDefault();
}
if (fpkModel != null && fpkModel.ID == fullNumPinkageModel.ID) {
//是同一包邮规则里的
string Name = fullNumPinkageModel.Name;
if (fullNumPinkageModel.FullNumPinkage > 0)
{
Name += ":满" + fullNumPinkageModel.FullNumPinkage + "件包邮";
}
else
else if (fullNumPinkageModel.FullMoneyPinkage > 0)
{
Name += ":满" + fullNumPinkageModel.FullMoneyPinkage + "元包邮";
}
SatisfiedGoodsList2.Add(new FreeShippingGoodsDetail()
{
FreeShipping = fullNumPinkageModel.ID,
Name = Name,
GoodsId = qitem.GoodsId ?? 0,
SpecificationKey = qitem.NewSpecificationSort,
SpecificationKey = qitem.SpecificationSort,
Number = qitem.Number ?? 0,
Money = qitem.NorGoodsMoney
});
}
}
}
}
if (SatisfiedGoodsList2.Any())
{
//看是否满足包邮
if (fullNumPinkageModel.FullNumPinkage > 0)
{
if (SatisfiedGoodsList2.Sum(x => x.Number) > fullNumPinkageModel.FullNumPinkage)
if (SatisfiedGoodsList2.Sum(x => x.Number) >= fullNumPinkageModel.FullNumPinkage)
{
FreeShipping_Use = true;
SatisfiedGoodsList.AddRange(SatisfiedGoodsList2);
......@@ -1788,7 +1790,7 @@ namespace Mall.Module.Product
}
else if (fullNumPinkageModel.FullMoneyPinkage > 0)
{
if (SatisfiedGoodsList2.Sum(x => x.Money) > fullNumPinkageModel.FullMoneyPinkage)
if (SatisfiedGoodsList2.Sum(x => x.Money) >= fullNumPinkageModel.FullMoneyPinkage)
{
FreeShipping_Use = true;
SatisfiedGoodsList.AddRange(SatisfiedGoodsList2);
......@@ -2392,6 +2394,7 @@ namespace Mall.Module.Product
}
}
#endregion
List<FreeShippingGoodsDetail> SatisfiedGoodsList = new List<FreeShippingGoodsDetail>();//可包邮的商品
if (demodel.DetailList.Any())
{
//积分
......@@ -2489,7 +2492,8 @@ namespace Mall.Module.Product
#endregion
}
}
List<int> YFCategoryList = new List<int>();//全局适配 分类
var mallbaseModel = mallBaseRepository.GetListRepository(new Model.Extend.BaseSetUp.RB_MallBase_Extend() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }).FirstOrDefault();
foreach (var item in demodel.DetailList)
{
var gmodel = gList.Where(x => x.Id == item.GoodsId).FirstOrDefault();
......@@ -2499,6 +2503,10 @@ namespace Mall.Module.Product
}
var categoryList = clist.Where(x => x.GoodsId == item.GoodsId).ToList();
if ((mallbaseModel?.IsFreeShipping ?? 0) == 1 && (gmodel.FullMoneyPinkage ?? 0) == 0 && (gmodel.FullNumPinkage ?? 0) == 0)
{
YFCategoryList.AddRange(categoryList.Select(x => x.CategoryId ?? 0).ToList());
}
item.InventoryNum = gmodel.InventoryNum ?? 0;
item.CommissionPrice = gmodel.Commission;// 粉象 返佣金额
......@@ -2801,6 +2809,15 @@ namespace Mall.Module.Product
}
}
}
#region 处理全局包邮
List<RB_FreeShipping_Extend> freeShippingList = new List<RB_FreeShipping_Extend>();
if (YFCategoryList.Any())
{
YFCategoryList = YFCategoryList.Distinct().ToList();
string categoryIds = string.Join(",", YFCategoryList);
freeShippingList = freeShippingRepository.GetFreeShippingListByCategoryIds(new RB_FreeShipping_Extend { MallBaseId = demodel.MallBaseId, TenantId = demodel.TenantId, CategoryIds = categoryIds });
}
#endregion
foreach (var item in demodel.DetailList)
{
var gmodel = gList.Where(x => x.Id == item.GoodsId).FirstOrDefault();
......@@ -2826,6 +2843,121 @@ namespace Mall.Module.Product
int exNum = demodel.DetailList.Where(x => x.GoodsId == item.GoodsId).Sum(x => x.Number ?? 0);
decimal exMoney = demodel.DetailList.Where(x => x.GoodsId == item.GoodsId).Sum(x => x.NorGoodsMoney);
if (!((gmodel.FullNumPinkage > 0 && exNum >= gmodel.FullNumPinkage) || (gmodel.FullMoneyPinkage > 0 && exMoney >= gmodel.FullMoneyPinkage)))
{
bool FreeShipping_Use = false;
if ((gmodel.FullMoneyPinkage ?? 0) == 0 && (gmodel.FullNumPinkage ?? 0) == 0 && YFCategoryList.Any())
{
//查找全局包邮规则
if (freeShippingList != null && freeShippingList.Any())
{
var fullNumPinkageModel = freeShippingList.Where(x => item.CategoryIdList.Contains(x.CategoryId) && x.IsFreeShipping == 1 && x.IsEnable == 1 && x.FullNumPinkage > 0 && x.CategoryId > 0).OrderBy(x => x.FullNumPinkage).ThenByDescending(x => x.ID).FirstOrDefault();
if (fullNumPinkageModel == null || fullNumPinkageModel.ID <= 0)
{
fullNumPinkageModel = freeShippingList.Where(x => item.CategoryIdList.Contains(x.CategoryId) && x.IsFreeShipping == 1 && x.IsEnable == 1 && x.FullMoneyPinkage > 0 && x.CategoryId > 0).OrderBy(x => x.FullMoneyPinkage).ThenByDescending(x => x.ID).FirstOrDefault();
}
if (fullNumPinkageModel == null || fullNumPinkageModel.ID <= 0)
{
fullNumPinkageModel = freeShippingList.Where(x => item.CategoryIdList.Contains(x.CategoryId) && x.IsFreeShipping == 1 && x.IsEnable == 1 && x.FullNumPinkage > 0 && x.CategoryId == 0).OrderBy(x => x.FullNumPinkage).ThenByDescending(x => x.ID).FirstOrDefault();
}
if (fullNumPinkageModel == null || fullNumPinkageModel.ID <= 0)
{
fullNumPinkageModel = freeShippingList.Where(x => item.CategoryIdList.Contains(x.CategoryId) && x.IsFreeShipping == 1 && x.IsEnable == 1 && x.FullMoneyPinkage > 0 && x.CategoryId == 0).OrderBy(x => x.FullMoneyPinkage).ThenByDescending(x => x.ID).FirstOrDefault();
}
if (fullNumPinkageModel != null)
{
//看所有商品是否满足该规则
var sglist = SatisfiedGoodsList.Where(x => x.FreeShipping == fullNumPinkageModel.ID).ToList();
var nosglist = SatisfiedGoodsList.Where(x => x.FreeShipping != fullNumPinkageModel.ID).ToList();
if (sglist.Any())
{
//看着商品是否包含在这里面
if (sglist.Where(x => x.GoodsId == item.GoodsId && x.SpecificationKey == item.SpecificationSort).Any())
{
FreeShipping_Use = true;
item.FreeShippingRemarks = sglist.Where(x => x.GoodsId == item.GoodsId && x.SpecificationKey == item.SpecificationSort).FirstOrDefault().Name;
}
}
else
{
//根据 查询出所有的订单商品
var SatisfiedGoodsList2 = new List<FreeShippingGoodsDetail>();
foreach (var qitem in demodel.DetailList)
{
var qgmodel = gList.Where(x => x.Id == qitem.GoodsId).FirstOrDefault();
if (qgmodel != null && qgmodel.GoodsStatus == 1 && (qgmodel.FullMoneyPinkage ?? 0) == 0 && (qgmodel.FullNumPinkage ?? 0) == 0)
{
if (!nosglist.Where(x => x.GoodsId == qitem.GoodsId && x.SpecificationKey == qitem.SpecificationSort).Any())
{
var fpkModel = freeShippingList.Where(x => qitem.CategoryIdList.Contains(x.CategoryId) && x.IsFreeShipping == 1 && x.IsEnable == 1 && x.FullNumPinkage > 0 && x.CategoryId > 0).OrderBy(x => x.FullNumPinkage).ThenByDescending(x => x.ID).FirstOrDefault();
if (fpkModel == null || fpkModel.ID <= 0)
{
fpkModel = freeShippingList.Where(x => qitem.CategoryIdList.Contains(x.CategoryId) && x.IsFreeShipping == 1 && x.IsEnable == 1 && x.FullMoneyPinkage > 0 && x.CategoryId > 0).OrderBy(x => x.FullMoneyPinkage).ThenByDescending(x => x.ID).FirstOrDefault();
}
if (fpkModel == null || fpkModel.ID <= 0)
{
fpkModel = freeShippingList.Where(x => qitem.CategoryIdList.Contains(x.CategoryId) && x.IsFreeShipping == 1 && x.IsEnable == 1 && x.FullNumPinkage > 0 && x.CategoryId == 0).OrderBy(x => x.FullNumPinkage).ThenByDescending(x => x.ID).FirstOrDefault();
}
if (fpkModel == null || fpkModel.ID <= 0)
{
fpkModel = freeShippingList.Where(x => qitem.CategoryIdList.Contains(x.CategoryId) && x.IsFreeShipping == 1 && x.IsEnable == 1 && x.FullMoneyPinkage > 0 && x.CategoryId == 0).OrderBy(x => x.FullMoneyPinkage).ThenByDescending(x => x.ID).FirstOrDefault();
}
if (fpkModel != null && fpkModel.ID == fullNumPinkageModel.ID)
{
//是同一包邮规则里的
string Name = fullNumPinkageModel.Name;
if (fullNumPinkageModel.FullNumPinkage > 0)
{
Name += ":满" + fullNumPinkageModel.FullNumPinkage + "件包邮";
}
else if (fullNumPinkageModel.FullMoneyPinkage > 0)
{
Name += ":满" + fullNumPinkageModel.FullMoneyPinkage + "元包邮";
}
SatisfiedGoodsList2.Add(new FreeShippingGoodsDetail()
{
FreeShipping = fullNumPinkageModel.ID,
Name = Name,
GoodsId = qitem.GoodsId ?? 0,
SpecificationKey = qitem.SpecificationSort,
Number = qitem.Number ?? 0,
Money = qitem.NorGoodsMoney,
CategoryId = fullNumPinkageModel.CategoryId
});
}
}
}
}
if (SatisfiedGoodsList2.Any())
{
//看是否满足包邮
if (fullNumPinkageModel.FullNumPinkage > 0)
{
if (SatisfiedGoodsList2.Sum(x => x.Number) >= fullNumPinkageModel.FullNumPinkage)
{
FreeShipping_Use = true;
SatisfiedGoodsList.AddRange(SatisfiedGoodsList2);
}
}
else if (fullNumPinkageModel.FullMoneyPinkage > 0)
{
if (SatisfiedGoodsList2.Sum(x => x.Money) >= fullNumPinkageModel.FullMoneyPinkage)
{
FreeShipping_Use = true;
SatisfiedGoodsList.AddRange(SatisfiedGoodsList2);
}
}
}
//看着商品是否包含在这里面
if (SatisfiedGoodsList.Where(x => x.GoodsId == item.GoodsId && x.SpecificationKey == item.SpecificationSort).Any())
{
item.FreeShippingRemarks = SatisfiedGoodsList.Where(x => x.GoodsId == item.GoodsId && x.SpecificationKey == item.SpecificationSort).FirstOrDefault().Name;
}
}
}
}
}
if (FreeShipping_Use == false)
{
int FreightId2 = gmodel.FreightId ?? 0;
if (gmodel.FreightId == 0)
......@@ -2906,6 +3038,7 @@ namespace Mall.Module.Product
}
}
}
}
TotalExpress += Express;
#endregion
item.FreightMoney = Express;
......@@ -2939,7 +3072,8 @@ namespace Mall.Module.Product
if (OrderId > 0)
{
//插入订单明细+ 商品库存更新
InsertOrderDetail(demodel, trans, OrderId);
InsertOrderDetail(demodel, trans, OrderId, SatisfiedGoodsList);
//用户订单数增加
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_Member_User_Extend.OrderNum),(umodel.OrderNum??0)+1}
......@@ -4363,7 +4497,7 @@ namespace Mall.Module.Product
/// <param name="demodel"></param>
/// <param name="trans"></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, List<FreeShippingGoodsDetail> SatisfiedGoodsList)
{
foreach (var item in demodel.DetailList)
{
......@@ -4410,9 +4544,31 @@ namespace Mall.Module.Product
FreightCostMoney = 0,
FreightFinanceId = 0,
PresentFXGrade = item.PresentFXGrade,
PresentFXMonth = item.PresentFXMonth
PresentFXMonth = item.PresentFXMonth,
FreeShippingRemarks = item.FreeShippingRemarks
}, trans);
item.Id = detailId;
if (detailId > 0 && SatisfiedGoodsList.Any()) {
//插入适配的包邮规则
var fsmodel = SatisfiedGoodsList.Where(x => x.GoodsId == item.GoodsId && x.SpecificationKey == item.SpecificationSort).FirstOrDefault();
if (fsmodel!=null)
{
orderDetailFreeShippingRepository.Insert(new RB_Goods_OrderDetailFreeShipping()
{
FreeshippingId = fsmodel.FreeShipping,
Category = fsmodel.CategoryId,
CreateDate = DateTime.Now,
FullMoneyPinkage = 0,
FullNumPinkage = 0,
Id = 0,
MallBaseId = demodel.MallBaseId,
Name = fsmodel.Name,
OrderDetailId = detailId,
Status = 0,
TenantId = demodel.TenantId
}, trans);
}
}
//更新商品数量
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
......
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