|
|
@ -10,13 +10,10 @@ using Microsoft.Extensions.Caching.Memory; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
using NLog; |
|
|
|
using System; |
|
|
|
using System.Collections.Concurrent; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Net.Http; |
|
|
|
using System.Security.Cryptography; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Yitter.IdGenerator; |
|
|
@ -453,6 +450,7 @@ namespace BBWY.Server.Business |
|
|
|
var preferentialAmount = 0M; |
|
|
|
if (dbOrder == null) |
|
|
|
{ |
|
|
|
var orderTotalInfo = insertOrderTotalInfoList.FirstOrDefault(x => x.Id == orderId); |
|
|
|
dbOrder = new Order() |
|
|
|
{ |
|
|
|
Id = orderId, |
|
|
@ -462,7 +460,7 @@ namespace BBWY.Server.Business |
|
|
|
EndTime = endTime, |
|
|
|
StartTime = orderJToken.Value<DateTime>("orderStartTime"), |
|
|
|
ModifyTime = modifyTime, |
|
|
|
OrderPayment = orderPayment, |
|
|
|
OrderPayment = orderPayment, //(orderTotalInfo?.TotalShouldPay) ?? orderPayment,
|
|
|
|
SellerPreferentialAmount = sellerPreferentialAmount, |
|
|
|
OrderSellerPrice = orderSellerPrice, |
|
|
|
OrderTotalPrice = orderTotalPrice, |
|
|
@ -474,7 +472,8 @@ namespace BBWY.Server.Business |
|
|
|
StoreOrder = storeOrder, |
|
|
|
StoreId = storeId, |
|
|
|
IsGift = orderSellerPrice == 0M, |
|
|
|
StorageType = storageType |
|
|
|
StorageType = storageType, |
|
|
|
PreferentialAmount = (orderTotalInfo?.TotalPingTaiChengDanYouHuiQuan) ?? 0M |
|
|
|
}; |
|
|
|
|
|
|
|
if (memoryCache.TryGetValue(orderId, out sDCalculationCostRequest)) |
|
|
@ -635,31 +634,31 @@ namespace BBWY.Server.Business |
|
|
|
|
|
|
|
#region 订单优惠
|
|
|
|
|
|
|
|
var orderCouponJArray = (JArray)orderJToken["couponDetailList"]; |
|
|
|
if (orderCouponJArray.HasValues) |
|
|
|
{ |
|
|
|
foreach (var orderCouponJToken in orderCouponJArray) |
|
|
|
{ |
|
|
|
var couponType = orderCouponJToken.Value<string>("couponType"); |
|
|
|
if (string.IsNullOrEmpty(couponType)) |
|
|
|
continue; |
|
|
|
//dbOrder.PreferentialAmount += orderCouponJToken.Value<decimal>("couponPrice");
|
|
|
|
preferentialAmount += orderCouponJToken.Value<decimal>("couponPrice"); |
|
|
|
if (!dbOrderCouponList.Any(oc => oc.OrderId == orderId)) |
|
|
|
{ |
|
|
|
insertOrderCouponList.Add(new OrderCoupon() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
SkuId = orderCouponJToken.Value<string>("skuId"), |
|
|
|
OrderId = orderId, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
CouponType = couponType, |
|
|
|
CouponPrice = orderCouponJToken.Value<decimal>("couponPrice") |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
//var orderCouponJArray = (JArray)orderJToken["couponDetailList"];
|
|
|
|
//if (orderCouponJArray.HasValues)
|
|
|
|
//{
|
|
|
|
// foreach (var orderCouponJToken in orderCouponJArray)
|
|
|
|
// {
|
|
|
|
// var couponType = orderCouponJToken.Value<string>("couponType");
|
|
|
|
// if (string.IsNullOrEmpty(couponType))
|
|
|
|
// continue;
|
|
|
|
// //dbOrder.PreferentialAmount += orderCouponJToken.Value<decimal>("couponPrice");
|
|
|
|
// preferentialAmount += orderCouponJToken.Value<decimal>("couponPrice");
|
|
|
|
// if (!dbOrderCouponList.Any(oc => oc.OrderId == orderId))
|
|
|
|
// {
|
|
|
|
// insertOrderCouponList.Add(new OrderCoupon()
|
|
|
|
// {
|
|
|
|
// Id = idGenerator.NewLong(),
|
|
|
|
// SkuId = orderCouponJToken.Value<string>("skuId"),
|
|
|
|
// OrderId = orderId,
|
|
|
|
// CreateTime = DateTime.Now,
|
|
|
|
// CouponType = couponType,
|
|
|
|
// CouponPrice = orderCouponJToken.Value<decimal>("couponPrice")
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
#region 订单状态转换
|
|
|
|
var orderState = ConvertOrderState(orderJToken, dbOrder.StorageType); |
|
|
@ -723,7 +722,7 @@ namespace BBWY.Server.Business |
|
|
|
var orderCostPurchaseAmount = 0M; |
|
|
|
var orderDeliveryExpressFreight = 0M; //发货总运费,sku购买数量第二个开始半价
|
|
|
|
|
|
|
|
var avgPreferential = preferentialAmount / orderSkuJArray.Count(); |
|
|
|
//var avgPreferential = preferentialAmount / orderSkuJArray.Count();
|
|
|
|
|
|
|
|
#region 扣减库存
|
|
|
|
foreach (var orderSkuJToken in orderSkuJArray) |
|
|
@ -731,17 +730,28 @@ namespace BBWY.Server.Business |
|
|
|
var orderSkuId = orderSkuJToken.Value<string>("skuId"); |
|
|
|
var itemTotal = orderSkuJToken.Value<int>("itemTotal"); //sku购买数量
|
|
|
|
|
|
|
|
#region sku拆分明细
|
|
|
|
decimal? skuShouldPay = orderSkuCFDetailList.FirstOrDefault(x => x.OrderId == orderId && x.SkuId == orderSkuId)?.ShouldPay; |
|
|
|
if (skuShouldPay == null) |
|
|
|
skuShouldPay = insertOrderSkuList.FirstOrDefault(x => x.OrderId == orderId && x.SkuId == orderSkuId)?.ShouldPay; |
|
|
|
if (skuShouldPay == null) |
|
|
|
skuShouldPay = dbOrderSkuList.FirstOrDefault(x => x.OrderId == orderId && x.SkuId == orderSkuId)?.ShouldPay; |
|
|
|
|
|
|
|
decimal? coupon = orderSkuCFDetailList.FirstOrDefault(x => x.OrderId == orderId && x.SkuId == orderSkuId)?.Coupon; |
|
|
|
if (coupon == null) |
|
|
|
coupon = insertOrderSkuList.FirstOrDefault(x => x.OrderId == orderId && x.SkuId == orderSkuId)?.Coupon; |
|
|
|
if (coupon == null) |
|
|
|
coupon = dbOrderSkuList.FirstOrDefault(x => x.OrderId == orderId && x.SkuId == orderSkuId)?.Coupon; |
|
|
|
|
|
|
|
decimal? pingtaiCoupon = orderSkuCFDetailList.FirstOrDefault(x => x.OrderId == orderId && |
|
|
|
x.SkuId == orderSkuId)?.PingTaiChengDanYouHuiQuan; |
|
|
|
if (pingtaiCoupon == null) |
|
|
|
pingtaiCoupon = insertOrderSkuList.FirstOrDefault(x => x.OrderId == orderId && x.SkuId == orderSkuId)?.PingTaiChengDanYouHuiQuan; |
|
|
|
if (pingtaiCoupon == null) |
|
|
|
pingtaiCoupon = dbOrderSkuList.FirstOrDefault(x => x.OrderId == orderId && x.SkuId == orderSkuId)?.PingTaiChengDanYouHuiQuan; |
|
|
|
|
|
|
|
decimal? venderFee = orderSkuCFDetailList.FirstOrDefault(x => x.OrderId == orderId && |
|
|
|
x.SkuId == orderSkuId)?.VenderFee; |
|
|
|
if (venderFee == null) |
|
|
|
venderFee = insertOrderSkuList.FirstOrDefault(x => x.OrderId == orderId && x.SkuId == orderSkuId)?.VenderFee; |
|
|
|
if (venderFee == null) |
|
|
|
venderFee = dbOrderSkuList.FirstOrDefault(x => x.OrderId == orderId && x.SkuId == orderSkuId)?.VenderFee; |
|
|
|
#endregion
|
|
|
|
|
|
|
|
//var itemPrice = orderSkuJToken.Value<decimal>("jdPrice"); //sku单价
|
|
|
|
var isReduceMultiTimes = false; //是否多次扣减库存
|
|
|
@ -801,7 +811,13 @@ namespace BBWY.Server.Business |
|
|
|
//orderCostDetail.SkuGrossProfit = itemPrice * deductionQuantity - avgPreferential -
|
|
|
|
// (orderCostDetail.TotalCost + orderCostDetail.DeliveryExpressFreight) -
|
|
|
|
// itemPrice * deductionQuantity * platformCommissionRatio;
|
|
|
|
orderCostDetail.SkuGrossProfit = ((skuShouldPay ?? 0M) + (coupon ?? 0M)) * deductionQuantity - orderCostDetail.TotalCost - orderCostDetail.DeliveryExpressFreight; |
|
|
|
|
|
|
|
//var koudian = (skuShouldPay.Value - venderFee.Value) * deductionQuantity * platformCommissionRatio;
|
|
|
|
//orderCostDetail.SkuGrossProfit = (skuShouldPay.Value + pingtaiCoupon.Value) * deductionQuantity -
|
|
|
|
// orderCostDetail.TotalCost - orderCostDetail.DeliveryExpressFreight -
|
|
|
|
// koudian;
|
|
|
|
|
|
|
|
orderCostDetail.CalculationSkuGrossProfit(skuShouldPay ?? 0M, pingtaiCoupon ?? 0M, venderFee ?? 0M, platformCommissionRatio); |
|
|
|
insertOrderCostDetailList.Add(orderCostDetail); |
|
|
|
} |
|
|
|
} |
|
|
@ -821,7 +837,7 @@ namespace BBWY.Server.Business |
|
|
|
if (dbOrder.OrderTotalPrice != 0) |
|
|
|
orderCost.CalculationOrderProfitAndCost(dbOrder, null); |
|
|
|
else |
|
|
|
orderCost.CalculationOrderProfitAndCost(orderSellerPrice, freightPrice, null); |
|
|
|
orderCost.CalculationOrderProfitAndCost(dbOrder.OrderPayment, dbOrder.PreferentialAmount, dbOrder.FreightPrice, null); |
|
|
|
|
|
|
|
insertOrderCostList.Add(orderCost); |
|
|
|
#endregion
|
|
|
@ -835,7 +851,7 @@ namespace BBWY.Server.Business |
|
|
|
if (isNewOrder) |
|
|
|
{ |
|
|
|
dbOrder.OrderState = orderState; |
|
|
|
dbOrder.PreferentialAmount = preferentialAmount; |
|
|
|
//dbOrder.PreferentialAmount = preferentialAmount;
|
|
|
|
} |
|
|
|
else if ((orderState != null && orderState != dbOrder.OrderState) || |
|
|
|
buyerRemark != dbOrder.BuyerRemark || |
|
|
|