Commit 9a422305 authored by liudong1993's avatar liudong1993

结算页面积分+优惠券

parent 54deb488
...@@ -13,6 +13,22 @@ namespace Mall.Model.Extend.Product ...@@ -13,6 +13,22 @@ namespace Mall.Model.Extend.Product
[DB(ConnectionName = "DefaultConnection")] [DB(ConnectionName = "DefaultConnection")]
public class RB_Goods_OrderDetail_Extend : RB_Goods_OrderDetail public class RB_Goods_OrderDetail_Extend : RB_Goods_OrderDetail
{ {
/// <summary>
/// 会员优惠
/// </summary>
public object Discounts { get; set; }
/// <summary>
/// 属性列表
/// </summary>
public object Attr_list { get; set; }
/// <summary>
/// 快递费用
/// </summary>
public decimal? Express { get; set; }
/// <summary>
/// 重量
/// </summary>
public int? GoodsWeight { get; set; }
/// <summary> /// <summary>
/// 订单ids /// 订单ids
/// </summary> /// </summary>
......
...@@ -36,6 +36,10 @@ namespace Mall.Model.Extend.User ...@@ -36,6 +36,10 @@ namespace Mall.Model.Extend.User
/// 优惠卷ids /// 优惠卷ids
/// </summary> /// </summary>
public string CouponIds { get; set; } public string CouponIds { get; set; }
/// <summary>
/// 用户优惠券id
/// </summary>
public string Ids { get; set; }
......
...@@ -169,6 +169,10 @@ namespace Mall.Module.Product ...@@ -169,6 +169,10 @@ namespace Mall.Module.Product
/// 订单支付 /// 订单支付
/// </summary> /// </summary>
private readonly RB_Goods_Online_TradeRepository goods_Online_TradeRepository = new RB_Goods_Online_TradeRepository(); private readonly RB_Goods_Online_TradeRepository goods_Online_TradeRepository = new RB_Goods_Online_TradeRepository();
/// <summary>
/// 小程序基础
/// </summary>
private readonly RB_MallBaseRepository mallBaseRepository = new RB_MallBaseRepository();
#region 购物车 #region 购物车
...@@ -913,6 +917,40 @@ namespace Mall.Module.Product ...@@ -913,6 +917,40 @@ namespace Mall.Module.Product
if (demodel.Use_Integral == 1 && umodel.Integral>0) { if (demodel.Use_Integral == 1 && umodel.Integral>0) {
integralModel = integral_SettingsRepository.GetIntegralSettingsList(new Model.Entity.MarketingCenter.RB_Integral_Settings() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }).FirstOrDefault(); integralModel = integral_SettingsRepository.GetIntegralSettingsList(new Model.Entity.MarketingCenter.RB_Integral_Settings() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }).FirstOrDefault();
} }
//快递默认
demodel.DeliveryMethod ??= OrderDeliveryMethodEnum.ExpressDistribution;
#region 快递列表
var mallbaseModel = mallBaseRepository.GetListRepository(new Model.Extend.BaseSetUp.RB_MallBase_Extend() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }).FirstOrDefault();
var Delivery = new object();
if (!string.IsNullOrEmpty(mallbaseModel?.DeliverWay))
{
var DelivertList = EnumHelper.GetEnumList(typeof(OrderDeliveryMethodEnum));
string[] arr = mallbaseModel?.DeliverWay.Split(',');
var send_type_list = new List<object>();
foreach (var item in arr)
{
if (!string.IsNullOrEmpty(item))
{
var delmodel = DelivertList.Where(x => x.Value == item).FirstOrDefault();
send_type_list.Add(new
{
name = delmodel.Key,
value = delmodel.Value
});
}
}
if (arr.Any()) {//设置默认发货方式
var delmodel = DelivertList.Where(x => x.Value == arr[0]).FirstOrDefault();
demodel.DeliveryMethod = (OrderDeliveryMethodEnum)Convert.ToInt32(delmodel.Value);
}
Delivery = new
{
send_type = demodel.DeliveryMethod,
disabled = false,
send_type_list
};
}
#endregion
//获取用户的默认收货地址 //获取用户的默认收货地址
RB_Member_ShippingAddress_Extend defModel = new RB_Member_ShippingAddress_Extend(); RB_Member_ShippingAddress_Extend defModel = new RB_Member_ShippingAddress_Extend();
...@@ -925,6 +963,7 @@ namespace Mall.Module.Product ...@@ -925,6 +963,7 @@ namespace Mall.Module.Product
defModel = member_ShippingAddressRepository.GetList(new RB_Member_ShippingAddress_Extend() { UserId = demodel.UserId, IsDefault = 1, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }).FirstOrDefault(); defModel = member_ShippingAddressRepository.GetList(new RB_Member_ShippingAddress_Extend() { UserId = demodel.UserId, IsDefault = 1, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }).FirstOrDefault();
} }
List<int> disList = new List<int>(); List<int> disList = new List<int>();
//地址
if (defModel.Id > 0) if (defModel.Id > 0)
{ {
string areaIds = (defModel.Province ?? 0) + "," + (defModel.City ?? 0) + "," + (defModel.District ?? 0); string areaIds = (defModel.Province ?? 0) + "," + (defModel.City ?? 0) + "," + (defModel.District ?? 0);
...@@ -938,11 +977,15 @@ namespace Mall.Module.Product ...@@ -938,11 +977,15 @@ namespace Mall.Module.Product
disList.Add(defModel.Province ?? 0); disList.Add(defModel.Province ?? 0);
disList.Add(defModel.City ?? 0); disList.Add(defModel.City ?? 0);
disList.Add(defModel.District ?? 0); disList.Add(defModel.District ?? 0);
} }
List<object> DList = new List<object>(); List<object> DList = new List<object>();
decimal TotalExpress = 0, TotalGoodsMoney = 0; decimal TotalExpress = 0, TotalGoodsMoney = 0, TotalGoodsOriginalMoney = 0, TotalGoodsSellMoney = 0;//总快递费 总商品价格 总原价 总售价
int DefFreightId = 0; int DefFreightId = 0;
decimal member_discount = 0; decimal member_discount = 0;//总会员优惠
decimal Total_integral_price = 0;//总积分金额
int Total_use_integral = 0;//总积分
decimal CouponsMoney = 0;//优惠总金额
bool IsPointsDeduction = false;//是否有商品可使用积分抵扣
List<object> goods_list = new List<object>(); List<object> goods_list = new List<object>();
if (demodel.DetailList.Any()) if (demodel.DetailList.Any())
{ {
...@@ -1001,27 +1044,30 @@ namespace Mall.Module.Product ...@@ -1001,27 +1044,30 @@ namespace Mall.Module.Product
demodel.CouponsIds = demodel.User_Coupon_Id.ToString(); demodel.CouponsIds = demodel.User_Coupon_Id.ToString();
if (!string.IsNullOrEmpty(demodel.CouponsIds)) if (!string.IsNullOrEmpty(demodel.CouponsIds))
{ {
cList = member_CouponRepository.GetList(new RB_Member_DiscountCoupon_Extend() { UseState = 0, CouponIds = demodel.CouponsIds, UserId = umodel.Id, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }); cList = member_CouponRepository.GetList(new RB_Member_DiscountCoupon_Extend() { UseState = 0, Ids = demodel.CouponsIds, UserId = umodel.Id, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
string[] arr = demodel.CouponsIds.Split(","); if (cList.Any())
foreach (var item in arr)
{ {
if (!string.IsNullOrEmpty(item)) string cIds = string.Join(",", cList.Select(x => x.CouponId).Distinct());
{ dcList = discountCouponRepository.GetDiscountCouponList(new Model.Extend.MarketingCenter.RB_DiscountCoupon_Extend() { CouponIds = cIds, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
if (!cList.Where(x => x.CouponId == Convert.ToInt32(item)).Any()) dcpList = discountCoupon_ProductRepository.GetListByDiscountCouponIds(new Model.Entity.MarketingCenter.RB_DiscountCoupon() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }, cIds);
if (dcList.Any()) {
foreach (var item in cList)
{ {
return ApiResult.Failed("优惠券不存在,请核实后再试"); if (item.CouponId > 0)
{
if (!dcList.Where(x => x.ID == item.CouponId).Any())
{
return ApiResult.Failed("优惠券不存在,请核实后再试");
}
}
} }
} }
} }
if (cList.Any())
{
dcList = discountCouponRepository.GetDiscountCouponList(new Model.Extend.MarketingCenter.RB_DiscountCoupon_Extend() { CouponIds = demodel.CouponsIds, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
dcpList = discountCoupon_ProductRepository.GetListByDiscountCouponIds(new Model.Entity.MarketingCenter.RB_DiscountCoupon() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }, demodel.CouponsIds);
}
} }
} }
#endregion #endregion
List<RB_Goods_CouponModel> GoodsCouponList = new List<RB_Goods_CouponModel>(); List<RB_Goods_CouponModel> GoodsCouponList = new List<RB_Goods_CouponModel>();
//初始化值
foreach (var item in demodel.DetailList) foreach (var item in demodel.DetailList)
{ {
var gmodel = gList.Where(x => x.Id == item.GoodsId).FirstOrDefault(); var gmodel = gList.Where(x => x.Id == item.GoodsId).FirstOrDefault();
...@@ -1156,79 +1202,82 @@ namespace Mall.Module.Product ...@@ -1156,79 +1202,82 @@ namespace Mall.Module.Product
#region 运费 #region 运费
decimal Express = 0; decimal Express = 0;
if (defModel.Id > 0 && demodel.DeliveryMethod != OrderDeliveryMethodEnum.VerificationShop) if (defModel.Id > 0 && demodel.DeliveryMethod == OrderDeliveryMethodEnum.ExpressDistribution)
{ {
int FreightId2 = gmodel.FreightId ?? 0; if (!((gmodel.FullNumPinkage > 0 && item.Number > gmodel.FullNumPinkage) || (gmodel.FullMoneyPinkage > 0 && item.Final_Price > gmodel.FullMoneyPinkage)))
if (gmodel.FreightId == 0)
{
FreightId2 = DefFreightId;
}
if (FreightId2 > 0)
{ {
var rulesModel = rulesList.Where(x => x.ID == FreightId2).FirstOrDefault(); int FreightId2 = gmodel.FreightId ?? 0;
List<Model.Extend.BaseSetUp.RB_Logistics_RulesPrice_Extend> priceList2 = priceList.Where(x => x.RulesId == FreightId2).ToList(); if (gmodel.FreightId == 0)
if (priceList2.Any())
{ {
var priceIds = priceList2.Select(x => x.ID).ToList(); FreightId2 = DefFreightId;
var regionList2 = regionList.Where(x => priceIds.Contains(x.RulesPriceId)).ToList(); }
if (FreightId2 > 0)
var regionModel = regionList2.Where(x => disList.Contains(x.RegionId)).FirstOrDefault(); {
if (regionModel != null) var rulesModel = rulesList.Where(x => x.ID == FreightId2).FirstOrDefault();
List<Model.Extend.BaseSetUp.RB_Logistics_RulesPrice_Extend> priceList2 = priceList.Where(x => x.RulesId == FreightId2).ToList();
if (priceList2.Any())
{ {
var pmodel = priceList2.Where(x => x.ID == regionModel.RulesPriceId).FirstOrDefault(); var priceIds = priceList2.Select(x => x.ID).ToList();
if (pmodel != null && rulesModel != null) var regionList2 = regionList.Where(x => priceIds.Contains(x.RulesPriceId)).ToList();
var regionModel = regionList2.Where(x => disList.Contains(x.RegionId)).FirstOrDefault();
if (regionModel != null)
{ {
if (rulesModel.ChargeMode == Common.Enum.MallBase.ChargeModeEnum.Num) var pmodel = priceList2.Where(x => x.ID == regionModel.RulesPriceId).FirstOrDefault();
if (pmodel != null && rulesModel != null)
{ {
//按件计费 if (rulesModel.ChargeMode == Common.Enum.MallBase.ChargeModeEnum.Num)
if (item.Number <= pmodel.First)
{
Express = pmodel.FirstPrice;
}
else
{ {
if (pmodel.Second > 0) //按件计费
if (item.Number <= pmodel.First)
{ {
if (((item.Number ?? 0) - pmodel.First) % pmodel.Second == 0) Express = pmodel.FirstPrice;
}
else
{
if (pmodel.Second > 0)
{ {
Express = pmodel.FirstPrice + (((item.Number ?? 0) - pmodel.First) / pmodel.Second) * pmodel.SecondPrice; if (((item.Number ?? 0) - pmodel.First) % pmodel.Second == 0)
{
Express = pmodel.FirstPrice + (((item.Number ?? 0) - pmodel.First) / pmodel.Second) * pmodel.SecondPrice;
}
else
{
Express = pmodel.FirstPrice + (((item.Number ?? 0) - pmodel.First) / pmodel.Second + 1) * pmodel.SecondPrice;
}
} }
else else
{ {
Express = pmodel.FirstPrice + (((item.Number ?? 0) - pmodel.First) / pmodel.Second + 1) * pmodel.SecondPrice; Express = pmodel.FirstPrice;
} }
} }
else
{
Express = pmodel.FirstPrice;
}
}
}
else
{
//重量计费
int TotalW = (item.Number ?? 0) * GoodsWeight;
if (TotalW <= pmodel.First)
{
Express = pmodel.FirstPrice;
} }
else else
{ {
if (pmodel.Second > 0) //重量计费
int TotalW = (item.Number ?? 0) * GoodsWeight;
if (TotalW <= pmodel.First)
{ {
if ((TotalW - pmodel.First) % pmodel.Second == 0) Express = pmodel.FirstPrice;
}
else
{
if (pmodel.Second > 0)
{ {
Express = pmodel.FirstPrice + ((TotalW - pmodel.First) / pmodel.Second) * pmodel.SecondPrice; if ((TotalW - pmodel.First) % pmodel.Second == 0)
{
Express = pmodel.FirstPrice + ((TotalW - pmodel.First) / pmodel.Second) * pmodel.SecondPrice;
}
else
{
Express = pmodel.FirstPrice + ((TotalW - pmodel.First) / pmodel.Second + 1) * pmodel.SecondPrice;
}
} }
else else
{ {
Express = pmodel.FirstPrice + ((TotalW - pmodel.First) / pmodel.Second + 1) * pmodel.SecondPrice; Express = pmodel.FirstPrice;
} }
} }
else
{
Express = pmodel.FirstPrice;
}
} }
} }
} }
...@@ -1243,6 +1292,7 @@ namespace Mall.Module.Product ...@@ -1243,6 +1292,7 @@ namespace Mall.Module.Product
#region 积分 #region 积分
if (umodel.Integral > 0 && gmodel.PointsDeduction > 0 && integralModel.IntegralNum > 0) if (umodel.Integral > 0 && gmodel.PointsDeduction > 0 && integralModel.IntegralNum > 0)
{ {
IsPointsDeduction = true;
decimal SingleMaxMoney = 0, MultMaxMoney = 0; decimal SingleMaxMoney = 0, MultMaxMoney = 0;
if (gmodel.PointsDeductionType == 1) { if (gmodel.PointsDeductionType == 1) {
SingleMaxMoney = Math.Round(gmodel.MemberPrice * (gmodel.PointsDeduction ?? 0) / 100, 2, MidpointRounding.AwayFromZero); SingleMaxMoney = Math.Round(gmodel.MemberPrice * (gmodel.PointsDeduction ?? 0) / 100, 2, MidpointRounding.AwayFromZero);
...@@ -1336,7 +1386,8 @@ namespace Mall.Module.Product ...@@ -1336,7 +1386,8 @@ namespace Mall.Module.Product
#region 优惠券 #region 优惠券
//decimal CouponsMoney = 0; //decimal CouponsMoney = 0;
if (demodel.User_Coupon_Id > 0) { if (demodel.User_Coupon_Id > 0) {
string couponItem = demodel.User_Coupon_Id.ToString(); var ccmodel = cList.Where(x => x.Id == demodel.User_Coupon_Id).FirstOrDefault();
string couponItem = (ccmodel?.CouponId ?? 0).ToString();
if (!string.IsNullOrEmpty(couponItem)) if (!string.IsNullOrEmpty(couponItem))
{ {
var dcModel = dcList.Where(x => x.ID == Convert.ToInt32(couponItem)).FirstOrDefault(); var dcModel = dcList.Where(x => x.ID == Convert.ToInt32(couponItem)).FirstOrDefault();
...@@ -1387,7 +1438,76 @@ namespace Mall.Module.Product ...@@ -1387,7 +1438,76 @@ namespace Mall.Module.Product
} }
#endregion #endregion
TotalGoodsMoney += item.Final_Price ?? 0; TotalGoodsMoney += item.Final_Price ?? 0;
TotalGoodsOriginalMoney += (gmodel.OriginalPrice ?? 0) * (item.Number ?? 0);
TotalGoodsSellMoney += gmodel.MemberPrice * (item.Number ?? 0);
item.GoodsWeight = GoodsWeight;
item.Express = Express;
item.IntegralMoney = integral_price;
item.IntegralNumber = use_integral;
item.Attr_list = attr_list;
item.Discounts = discounts;
Total_integral_price += integral_price;
Total_use_integral += use_integral;
}
if (demodel.User_Coupon_Id > 0 && GoodsCouponList.Any()) {
decimal FinalMoney = GoodsCouponList.Sum(x => x.TotalMoney);
var ccmodel = cList.Where(x => x.Id == demodel.User_Coupon_Id).FirstOrDefault();
var dcModel = dcList.Where(x => x.ID == (ccmodel?.CouponId ?? 0)).FirstOrDefault();
if (dcModel == null)
{
return ApiResult.Failed("优惠卷不存在,亲核实后再试");
}
if (dcModel.MinConsumePrice > 0)
{
if (FinalMoney < dcModel.MinConsumePrice)
{
FinalMoney = 0;
}
}
if (dcModel.CouponType == Common.Enum.MarketingCenter.CouponTypeEnum.FullReduction && FinalMoney > 0)
{
CouponsMoney = dcModel.DiscountsPrice;
}
else if(dcModel.CouponType == Common.Enum.MarketingCenter.CouponTypeEnum.Discount && FinalMoney > 0)
{
decimal disMoney = Math.Round(FinalMoney * (10 - dcModel.DiscountsPrice) / 10, 2, MidpointRounding.AwayFromZero);
if (dcModel.MaxDiscountsPrice > 0 && dcModel.MaxDiscountsPrice < disMoney)
{
disMoney = dcModel.MaxDiscountsPrice;
}
CouponsMoney = disMoney;
}
//每个商品优惠券分摊金额
if (CouponsMoney > 0) {
foreach (var item in GoodsCouponList) {
item.CouponMoney = Math.Round((item.TotalMoney / FinalMoney) * CouponsMoney, 2, MidpointRounding.AwayFromZero);
}
if (CouponsMoney != GoodsCouponList.Sum(x => x.CouponMoney)) {
//四舍五入存在差值
decimal diffMoney = CouponsMoney - GoodsCouponList.Sum(x => x.CouponMoney);
var gcModel = GoodsCouponList.OrderBy(x => x.CouponMoney).Take(1).FirstOrDefault();
gcModel.CouponMoney += diffMoney;
}
}
}
//赋值
foreach (var item in demodel.DetailList)
{
var gmodel = gList.Where(x => x.Id == item.GoodsId).FirstOrDefault();
if (gmodel == null || gmodel.GoodsStatus != 1)
{
continue;
}
decimal couponMoney = 0;//优惠金额
var couponModel = GoodsCouponList.Where(x => x.GoodsId == item.GoodsId).FirstOrDefault();
if (couponModel != null) {
couponMoney = couponModel.CouponMoney;
TotalGoodsMoney -= couponMoney;//总价格需减去优惠券金额
}
goods_list.Add(new goods_list.Add(new
{ {
id = gmodel.Id, id = gmodel.Id,
...@@ -1399,47 +1519,48 @@ namespace Mall.Module.Product ...@@ -1399,47 +1519,48 @@ namespace Mall.Module.Product
pieces = gmodel.FullNumPinkage,//满件包邮 pieces = gmodel.FullNumPinkage,//满件包邮
forehead = gmodel.FullMoneyPinkage,//满额包邮 forehead = gmodel.FullMoneyPinkage,//满额包邮
freight_id = gmodel.FreightId, freight_id = gmodel.FreightId,
express_price = Express, express_price = item.Express,
unit_price = gmodel.SellingPrice, unit_price = gmodel.SellingPrice,
total_original_price = (gmodel.SellingPrice??0)*(item.Number??0), total_original_price = (gmodel.OriginalPrice ?? 0) * (item.Number ?? 0),
total_price = "7995.10",//优惠券(有平摊情况) 积分抵扣 (默认从第一个商品抵扣) total_price = (gmodel.SellingPrice ?? 0) * (item.Number ?? 0),//优惠券(有平摊情况) 积分抵扣 (默认从第一个商品抵扣)
goods_attr = new goods_attr = new
{ {
id = 0, id = 0,
goods_id = gmodel.Id, goods_id = gmodel.Id,
sign_id = item.SpecificationSort, sign_id = item.SpecificationSort,
stock = gmodel.InventoryNum, stock = gmodel.InventoryNum,
price = gmodel.MemberPrice, price = gmodel.SellingPrice??0,
original_price = gmodel.SellingPrice??0, original_price = gmodel.OriginalPrice ?? 0,
no = gmodel.GoodsNumbers, no = gmodel.GoodsNumbers,
weight = GoodsWeight, weight = item.GoodsWeight,
pic_url = gmodel.CoverImage, pic_url = gmodel.CoverImage,
individual_share = umodel?.IsDistributor ?? 2,// 是否分销商 individual_share = umodel?.IsDistributor ?? 2,// 是否分销商
share_type = gmodel.SeparateDistributionMoneyType,//分销佣金类型, share_type = gmodel.SeparateDistributionMoneyType,//分销佣金类型,
member_price = gmodel.MemberPrice, member_price = gmodel.MemberPrice,
integral_price,//积分抵扣金额 integral_price=demodel.Use_Integral==1? item.IntegralMoney:0,//积分抵扣金额
use_integral, use_integral= demodel.Use_Integral == 1 ? item.IntegralNumber:0,
couponMoney,
//discount= [], //discount= [],
//extra= [], //extra= [],
//goods_warehouse_id = 19813, //goods_warehouse_id = 19813,
name = gmodel.Name, name = gmodel.Name,
cover_pic = gmodel.CoverImage, cover_pic = gmodel.CoverImage,
detail = gmodel.GoodsDetails, detail = gmodel.GoodsDetails,
pic_list = gmodel.CarouselImageList.Select(x=>new { pic_list = gmodel.CarouselImageList.Select(x => new {
id = x.Id, id = x.Id,
pic_url = x.Path pic_url = x.Path
}), }),
number = item.Number, number = item.Number,
goods_share_level = DistributionCommissionList.Where(x=>x.GoodsId== gmodel.Id).Select(x=>new { goods_share_level = DistributionCommissionList.Where(x => x.GoodsId == gmodel.Id).Select(x => new {
share_commission_first=x.OneCommission, share_commission_first = x.OneCommission,
share_commission_second=x.TwoCommission, share_commission_second = x.TwoCommission,
share_commission_third=x.ThreeCommission, share_commission_third = x.ThreeCommission,
level=x.DistributorGrade level = x.DistributorGrade
}), }),
attr_setting_type= gmodel.SeparateDistributionType attr_setting_type = gmodel.SeparateDistributionType
}, },
attr_list, attr_list= item.Attr_list,
discounts, discounts = item.Discounts,
member_discount = ((gmodel.SellingPrice ?? 0) * (item.Number ?? 0)) - (gmodel.MemberPrice * (item.Number ?? 0)), member_discount = ((gmodel.SellingPrice ?? 0) * (item.Number ?? 0)) - (gmodel.MemberPrice * (item.Number ?? 0)),
cover_pic = gmodel.CoverImage, cover_pic = gmodel.CoverImage,
is_level_alone = gmodel.SeparateSetMember,//是否单独设置会员价 is_level_alone = gmodel.SeparateSetMember,//是否单独设置会员价
...@@ -1470,50 +1591,20 @@ namespace Mall.Module.Product ...@@ -1470,50 +1591,20 @@ namespace Mall.Module.Product
//form= null //form= null
}); });
} }
decimal CouponsMoney = 0;//优惠总金额
if (demodel.User_Coupon_Id > 0 && GoodsCouponList.Any()) {
decimal FinalMoney = GoodsCouponList.Sum(x => x.TotalMoney);
var dcModel = dcList.Where(x => x.ID == demodel.User_Coupon_Id).FirstOrDefault();
if (dcModel == null)
{
return ApiResult.Failed("优惠卷不存在,亲核实后再试");
}
if (dcModel.MinConsumePrice > 0)
{
if (FinalMoney < dcModel.MinConsumePrice)
{
FinalMoney = 0;
}
}
if (dcModel.CouponType == Common.Enum.MarketingCenter.CouponTypeEnum.FullReduction && FinalMoney > 0)
{
CouponsMoney = dcModel.DiscountsPrice;
}
else if(dcModel.CouponType == Common.Enum.MarketingCenter.CouponTypeEnum.Discount && FinalMoney > 0)
{
decimal disMoney = Math.Round(FinalMoney * (10 - dcModel.DiscountsPrice) / 10, 2, MidpointRounding.AwayFromZero);
if (dcModel.MaxDiscountsPrice > 0 && dcModel.MaxDiscountsPrice < disMoney)
{
disMoney = dcModel.MaxDiscountsPrice;
}
CouponsMoney = disMoney;
}
//每个商品优惠券分摊金额
if (CouponsMoney > 0) {
foreach (var item in GoodsCouponList) {
item.CouponMoney = Math.Round((item.TotalMoney / FinalMoney) * CouponsMoney, 2, MidpointRounding.AwayFromZero);
}
if (CouponsMoney != GoodsCouponList.Sum(x => x.CouponMoney)) {
//四舍五入存在差值
}
}
}
} }
List<object> mch_list = new List<object>(); List<object> mch_list = new List<object>();
var minModel = miniProgramRepository.GetEntity(demodel.MallBaseId); var minModel = miniProgramRepository.GetEntity(demodel.MallBaseId);
//积分
var IntegralObj = new
{
can_use = IsPointsDeduction,
use = demodel.Use_Integral == 1 ? true : false,
use_num = Total_use_integral,
deduction_price = Total_integral_price
};
mch_list.Add(new mch_list.Add(new
{ {
mch=new { mch=new {
...@@ -1524,33 +1615,20 @@ namespace Mall.Module.Product ...@@ -1524,33 +1615,20 @@ namespace Mall.Module.Product
express_price = TotalExpress, express_price = TotalExpress,
remark= "", remark= "",
//order_form_data= [], //order_form_data= [],
total_goods_price= "15999.10", total_goods_price= TotalGoodsSellMoney,
total_goods_original_price= "16004.00", total_goods_original_price= TotalGoodsOriginalMoney,
member_discount, member_discount,
coupon= new{ coupon= new{
enabled= true, enabled= true,
use= true, use= demodel.User_Coupon_Id>0? true:false,
coupon_discount= "20.00", coupon_discount= CouponsMoney,
user_coupon_id= 70285 user_coupon_id= demodel.User_Coupon_Id??0
},
integral= new {
can_use= true,
use= true,
use_num= 49,
deduction_price= "4.90"
}, },
delivery= new { integral= IntegralObj,
send_type= "express", delivery= Delivery,
disabled= false,
send_type_list= new List<object>() {new {
name= "快递配送",
value= "express"
} }
},
//store= null, //store= null,
store_select_enable= true, store_select_enable= true,
total_price= "16049.10", total_price= TotalGoodsMoney,
//pick_up_enable= true, //pick_up_enable= true,
//pick_up_price= null, //pick_up_price= null,
//diff_goods_form_count= 0, //diff_goods_form_count= 0,
...@@ -1559,7 +1637,7 @@ namespace Mall.Module.Product ...@@ -1559,7 +1637,7 @@ namespace Mall.Module.Product
var Robj = new { var Robj = new {
mch_list, mch_list,
total_price= "16049.10", total_price= TotalGoodsMoney,
price_enable= true, price_enable= true,
address= new{ address= new{
id= defModel?.Id??0, id= defModel?.Id??0,
...@@ -1583,25 +1661,7 @@ namespace Mall.Module.Product ...@@ -1583,25 +1661,7 @@ namespace Mall.Module.Product
//hasCity= false, //hasCity= false,
template_message_list= new List<string>() { "WPELErDfYO3JnizA5Zikta6Y8qrBBAgecuj2aLoucuY", "pCmTJwvTqNpyRREo7vvqIYBcrATNWoitfbLS61fLhzU", "i6QPsaOHgfNwlIRMwmvFGSCqX28g0cRa8XaLZ5_gpgc" } template_message_list= new List<string>() { "WPELErDfYO3JnizA5Zikta6Y8qrBBAgecuj2aLoucuY", "pCmTJwvTqNpyRREo7vvqIYBcrATNWoitfbLS61fLhzU", "i6QPsaOHgfNwlIRMwmvFGSCqX28g0cRa8XaLZ5_gpgc" }
}; };
return ApiResult.Success("", new return ApiResult.Success("", Robj);
{
ShippingAddressModel = new
{
defModel.Id,
defModel.Name,
defModel.Mobile,
defModel.DistrictAddress,
defModel.Address,
defModel.Province,
defModel.City,
defModel.District
},
DetailList = DList,
TotalExpress,
umodel.MemberGrade,
DeliveryMethod = (int)OrderDeliveryMethodEnum.ExpressDistribution,
Level_Show = umodel.MemberGrade > 0 ? 1 : 2
});
} }
/// <summary> /// <summary>
......
...@@ -63,6 +63,9 @@ namespace Mall.Repository.User ...@@ -63,6 +63,9 @@ namespace Mall.Repository.User
{ {
builder.Append($" AND a.{nameof(RB_Member_DiscountCoupon_Extend.CouponId)} in ({query.CouponIds})"); builder.Append($" AND a.{nameof(RB_Member_DiscountCoupon_Extend.CouponId)} in ({query.CouponIds})");
} }
if (!string.IsNullOrEmpty(query.Ids)) {
builder.Append($" AND a.{nameof(RB_Member_DiscountCoupon_Extend.Id)} in ({query.Ids})");
}
if (query.UseState >= 0) if (query.UseState >= 0)
{ {
builder.Append($" AND a.{nameof(RB_Member_DiscountCoupon_Extend.UseState)}={query.UseState}"); builder.Append($" AND a.{nameof(RB_Member_DiscountCoupon_Extend.UseState)}={query.UseState}");
......
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