Commit 9a422305 authored by liudong1993's avatar liudong1993

结算页面积分+优惠券

parent 54deb488
......@@ -13,6 +13,22 @@ namespace Mall.Model.Extend.Product
[DB(ConnectionName = "DefaultConnection")]
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>
/// 订单ids
/// </summary>
......
......@@ -36,6 +36,10 @@ namespace Mall.Model.Extend.User
/// 优惠卷ids
/// </summary>
public string CouponIds { get; set; }
/// <summary>
/// 用户优惠券id
/// </summary>
public string Ids { get; set; }
......
......@@ -169,6 +169,10 @@ namespace Mall.Module.Product
/// 订单支付
/// </summary>
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 购物车
......@@ -913,6 +917,40 @@ namespace Mall.Module.Product
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();
}
//快递默认
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();
......@@ -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();
}
List<int> disList = new List<int>();
//地址
if (defModel.Id > 0)
{
string areaIds = (defModel.Province ?? 0) + "," + (defModel.City ?? 0) + "," + (defModel.District ?? 0);
......@@ -940,9 +979,13 @@ namespace Mall.Module.Product
disList.Add(defModel.District ?? 0);
}
List<object> DList = new List<object>();
decimal TotalExpress = 0, TotalGoodsMoney = 0;
decimal TotalExpress = 0, TotalGoodsMoney = 0, TotalGoodsOriginalMoney = 0, TotalGoodsSellMoney = 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>();
if (demodel.DetailList.Any())
{
......@@ -1001,27 +1044,30 @@ namespace Mall.Module.Product
demodel.CouponsIds = demodel.User_Coupon_Id.ToString();
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 });
string[] arr = demodel.CouponsIds.Split(",");
foreach (var item in arr)
cList = member_CouponRepository.GetList(new RB_Member_DiscountCoupon_Extend() { UseState = 0, Ids = demodel.CouponsIds, UserId = umodel.Id, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
if (cList.Any())
{
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 });
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)
{
if (!cList.Where(x => x.CouponId == Convert.ToInt32(item)).Any())
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
List<RB_Goods_CouponModel> GoodsCouponList = new List<RB_Goods_CouponModel>();
//初始化值
foreach (var item in demodel.DetailList)
{
var gmodel = gList.Where(x => x.Id == item.GoodsId).FirstOrDefault();
......@@ -1156,7 +1202,9 @@ namespace Mall.Module.Product
#region 运费
decimal Express = 0;
if (defModel.Id > 0 && demodel.DeliveryMethod != OrderDeliveryMethodEnum.VerificationShop)
if (defModel.Id > 0 && demodel.DeliveryMethod == OrderDeliveryMethodEnum.ExpressDistribution)
{
if (!((gmodel.FullNumPinkage > 0 && item.Number > gmodel.FullNumPinkage) || (gmodel.FullMoneyPinkage > 0 && item.Final_Price > gmodel.FullMoneyPinkage)))
{
int FreightId2 = gmodel.FreightId ?? 0;
if (gmodel.FreightId == 0)
......@@ -1236,6 +1284,7 @@ namespace Mall.Module.Product
}
}
}
}
TotalExpress += Express;
item.Final_Price += Express;
#endregion
......@@ -1243,6 +1292,7 @@ namespace Mall.Module.Product
#region 积分
if (umodel.Integral > 0 && gmodel.PointsDeduction > 0 && integralModel.IntegralNum > 0)
{
IsPointsDeduction = true;
decimal SingleMaxMoney = 0, MultMaxMoney = 0;
if (gmodel.PointsDeductionType == 1) {
SingleMaxMoney = Math.Round(gmodel.MemberPrice * (gmodel.PointsDeduction ?? 0) / 100, 2, MidpointRounding.AwayFromZero);
......@@ -1336,7 +1386,8 @@ namespace Mall.Module.Product
#region 优惠券
//decimal CouponsMoney = 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))
{
var dcModel = dcList.Where(x => x.ID == Convert.ToInt32(couponItem)).FirstOrDefault();
......@@ -1387,7 +1438,76 @@ namespace Mall.Module.Product
}
#endregion
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
{
id = gmodel.Id,
......@@ -1399,47 +1519,48 @@ namespace Mall.Module.Product
pieces = gmodel.FullNumPinkage,//满件包邮
forehead = gmodel.FullMoneyPinkage,//满额包邮
freight_id = gmodel.FreightId,
express_price = Express,
express_price = item.Express,
unit_price = gmodel.SellingPrice,
total_original_price = (gmodel.SellingPrice??0)*(item.Number??0),
total_price = "7995.10",//优惠券(有平摊情况) 积分抵扣 (默认从第一个商品抵扣)
total_original_price = (gmodel.OriginalPrice ?? 0) * (item.Number ?? 0),
total_price = (gmodel.SellingPrice ?? 0) * (item.Number ?? 0),//优惠券(有平摊情况) 积分抵扣 (默认从第一个商品抵扣)
goods_attr = new
{
id = 0,
goods_id = gmodel.Id,
sign_id = item.SpecificationSort,
stock = gmodel.InventoryNum,
price = gmodel.MemberPrice,
original_price = gmodel.SellingPrice??0,
price = gmodel.SellingPrice??0,
original_price = gmodel.OriginalPrice ?? 0,
no = gmodel.GoodsNumbers,
weight = GoodsWeight,
weight = item.GoodsWeight,
pic_url = gmodel.CoverImage,
individual_share = umodel?.IsDistributor ?? 2,// 是否分销商
share_type = gmodel.SeparateDistributionMoneyType,//分销佣金类型,
member_price = gmodel.MemberPrice,
integral_price,//积分抵扣金额
use_integral,
integral_price=demodel.Use_Integral==1? item.IntegralMoney:0,//积分抵扣金额
use_integral= demodel.Use_Integral == 1 ? item.IntegralNumber:0,
couponMoney,
//discount= [],
//extra= [],
//goods_warehouse_id = 19813,
name = gmodel.Name,
cover_pic = gmodel.CoverImage,
detail = gmodel.GoodsDetails,
pic_list = gmodel.CarouselImageList.Select(x=>new {
pic_list = gmodel.CarouselImageList.Select(x => new {
id = x.Id,
pic_url = x.Path
}),
number = item.Number,
goods_share_level = DistributionCommissionList.Where(x=>x.GoodsId== gmodel.Id).Select(x=>new {
share_commission_first=x.OneCommission,
share_commission_second=x.TwoCommission,
share_commission_third=x.ThreeCommission,
level=x.DistributorGrade
goods_share_level = DistributionCommissionList.Where(x => x.GoodsId == gmodel.Id).Select(x => new {
share_commission_first = x.OneCommission,
share_commission_second = x.TwoCommission,
share_commission_third = x.ThreeCommission,
level = x.DistributorGrade
}),
attr_setting_type= gmodel.SeparateDistributionType
attr_setting_type = gmodel.SeparateDistributionType
},
attr_list,
discounts,
attr_list= item.Attr_list,
discounts = item.Discounts,
member_discount = ((gmodel.SellingPrice ?? 0) * (item.Number ?? 0)) - (gmodel.MemberPrice * (item.Number ?? 0)),
cover_pic = gmodel.CoverImage,
is_level_alone = gmodel.SeparateSetMember,//是否单独设置会员价
......@@ -1470,50 +1591,20 @@ namespace Mall.Module.Product
//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>();
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=new {
......@@ -1524,33 +1615,20 @@ namespace Mall.Module.Product
express_price = TotalExpress,
remark= "",
//order_form_data= [],
total_goods_price= "15999.10",
total_goods_original_price= "16004.00",
total_goods_price= TotalGoodsSellMoney,
total_goods_original_price= TotalGoodsOriginalMoney,
member_discount,
coupon= new{
enabled= true,
use= true,
coupon_discount= "20.00",
user_coupon_id= 70285
},
integral= new {
can_use= true,
use= true,
use_num= 49,
deduction_price= "4.90"
},
delivery= new {
send_type= "express",
disabled= false,
send_type_list= new List<object>() {new {
name= "快递配送",
value= "express"
} }
use= demodel.User_Coupon_Id>0? true:false,
coupon_discount= CouponsMoney,
user_coupon_id= demodel.User_Coupon_Id??0
},
integral= IntegralObj,
delivery= Delivery,
//store= null,
store_select_enable= true,
total_price= "16049.10",
total_price= TotalGoodsMoney,
//pick_up_enable= true,
//pick_up_price= null,
//diff_goods_form_count= 0,
......@@ -1559,7 +1637,7 @@ namespace Mall.Module.Product
var Robj = new {
mch_list,
total_price= "16049.10",
total_price= TotalGoodsMoney,
price_enable= true,
address= new{
id= defModel?.Id??0,
......@@ -1583,25 +1661,7 @@ namespace Mall.Module.Product
//hasCity= false,
template_message_list= new List<string>() { "WPELErDfYO3JnizA5Zikta6Y8qrBBAgecuj2aLoucuY", "pCmTJwvTqNpyRREo7vvqIYBcrATNWoitfbLS61fLhzU", "i6QPsaOHgfNwlIRMwmvFGSCqX28g0cRa8XaLZ5_gpgc" }
};
return ApiResult.Success("", new
{
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
});
return ApiResult.Success("", Robj);
}
/// <summary>
......
......@@ -63,6 +63,9 @@ namespace Mall.Repository.User
{
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)
{
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