|
|
@ -1,10 +1,12 @@ |
|
|
|
using BBWY.Common.Http; |
|
|
|
using BBWY.Common.Models; |
|
|
|
using BBWY.Server.Business.Extensions; |
|
|
|
using BBWY.Server.Business.PlatformSDK.DataExtension; |
|
|
|
using BBWY.Server.Model; |
|
|
|
using BBWY.Server.Model.Db; |
|
|
|
using BBWY.Server.Model.Dto; |
|
|
|
using FreeSql; |
|
|
|
using Microsoft.Extensions.Caching.Memory; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Newtonsoft.Json.Linq; |
|
|
@ -22,13 +24,16 @@ namespace BBWY.Server.Business |
|
|
|
{ |
|
|
|
private IDictionary<Enums.Platform, Action<JArray, long, string, string, string, string, decimal>> syncOrderMethodDic; |
|
|
|
|
|
|
|
private IMemoryCache memoryCache; |
|
|
|
|
|
|
|
public OrderSyncBusiness(RestApiService restApiService, |
|
|
|
IOptions<GlobalConfig> options, |
|
|
|
ILogger logger, |
|
|
|
IFreeSql fsql, |
|
|
|
IIdGenerator idGenerator, |
|
|
|
TaskSchedulerManager taskSchedulerManager, |
|
|
|
VenderBusiness venderBusiness) : base(restApiService, |
|
|
|
VenderBusiness venderBusiness, |
|
|
|
IMemoryCache memoryCache) : base(restApiService, |
|
|
|
options, |
|
|
|
logger, |
|
|
|
fsql, |
|
|
@ -36,6 +41,7 @@ namespace BBWY.Server.Business |
|
|
|
taskSchedulerManager, |
|
|
|
venderBusiness) |
|
|
|
{ |
|
|
|
this.memoryCache = memoryCache; |
|
|
|
syncOrderMethodDic = new Dictionary<Enums.Platform, Action<JArray, long, string, string, string, string, decimal>>() |
|
|
|
{ |
|
|
|
{ Enums.Platform.京东, SyncJDOrder } |
|
|
@ -210,6 +216,7 @@ namespace BBWY.Server.Business |
|
|
|
var orderId = orderJToken.Value<string>("orderId"); |
|
|
|
var dbOrder = dbOrderList.FirstOrDefault(o => o.Id == orderId); |
|
|
|
var isNewOrder = dbOrder == null; |
|
|
|
SDCalculationCostRequest sDCalculationCostRequest = null; //SD信息埋点
|
|
|
|
|
|
|
|
#region 订单基本信息
|
|
|
|
var buyerRemark = orderJToken.Value<string>("orderRemark"); |
|
|
@ -241,6 +248,19 @@ namespace BBWY.Server.Business |
|
|
|
StoreId = orderJToken.Value<string>("storeId") |
|
|
|
}; |
|
|
|
|
|
|
|
if (memoryCache.TryGetValue(orderId, out sDCalculationCostRequest)) |
|
|
|
{ |
|
|
|
dbOrder.StorageType = Enums.StorageType.SD; |
|
|
|
dbOrder.SDType = sDCalculationCostRequest.SDType; |
|
|
|
dbOrder.Flag = sDCalculationCostRequest.Flag; |
|
|
|
if (!string.IsNullOrEmpty(sDCalculationCostRequest.VenderRemark)) |
|
|
|
dbOrder.VenderRemark = sDCalculationCostRequest.VenderRemark; |
|
|
|
dbOrder.SDKey = sDCalculationCostRequest.SDKey; |
|
|
|
dbOrder.SDPayBillNo = sDCalculationCostRequest.SDPayBillNo; |
|
|
|
dbOrder.SDOperator = sDCalculationCostRequest.SDOperator; |
|
|
|
dbOrder.SDPayChannel = sDCalculationCostRequest.SDPayChannel; |
|
|
|
} |
|
|
|
|
|
|
|
if (dbOrder.StoreOrder.Contains("京仓")) |
|
|
|
dbOrder.StorageType = Enums.StorageType.京仓; |
|
|
|
else if (dbOrder.StoreOrder.Contains("云仓")) |
|
|
@ -401,7 +421,6 @@ namespace BBWY.Server.Business |
|
|
|
|
|
|
|
#region 扣减库存, 计算成本
|
|
|
|
if (dbOrder.StorageType != null && |
|
|
|
dbOrder.StorageType != Enums.StorageType.SD && |
|
|
|
dbOrder.StorageType != Enums.StorageType.代发 && |
|
|
|
orderState != null && |
|
|
|
orderState != Enums.OrderState.待付款 && |
|
|
@ -410,8 +429,26 @@ namespace BBWY.Server.Business |
|
|
|
var orderCost = dbOrderCostList.FirstOrDefault(oc => oc.OrderId == dbOrder.Id); |
|
|
|
if (orderCost == null) |
|
|
|
{ |
|
|
|
//再查询一次数据库,以防同步开始执行后被人为操作扣减库存,造成重复扣减库存
|
|
|
|
if (!fsql.Select<OrderCost>(dbOrder.Id).Any()) |
|
|
|
if (isNewOrder && dbOrder.StorageType == Enums.StorageType.SD && sDCalculationCostRequest != null) |
|
|
|
{ |
|
|
|
//检查SD埋点
|
|
|
|
if (sDCalculationCostRequest.PlatformCommissionRatio == 0M) |
|
|
|
sDCalculationCostRequest.PlatformCommissionRatio = 0.05M; |
|
|
|
orderCost = new OrderCost() |
|
|
|
{ |
|
|
|
OrderId = sDCalculationCostRequest.OrderId, |
|
|
|
PlatformCommissionRatio = sDCalculationCostRequest.PlatformCommissionRatio, |
|
|
|
PreferentialAmount = dbOrder.PreferentialAmount, |
|
|
|
Profit = 0, |
|
|
|
DeliveryExpressFreight = sDCalculationCostRequest.DeliveryExpressFreight, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
IsManualEdited = true, |
|
|
|
SDCommissionAmount = sDCalculationCostRequest.SDCommissionAmount |
|
|
|
}; |
|
|
|
orderCost.CalculationSDOrderProfitAndCost(dbOrder, null); |
|
|
|
insertOrderCostList.Add(orderCost); |
|
|
|
} |
|
|
|
else if (!fsql.Select<OrderCost>(dbOrder.Id).Any()) //再查询一次数据库,以防同步开始执行后被人为操作扣减库存,造成重复扣减库存
|
|
|
|
{ |
|
|
|
var orderSkuJArray = orderJToken["itemInfoList"].Where(skuJToken => skuJToken.Value<decimal>("jdPrice") != 0M); |
|
|
|
if (orderSkuJArray != null && orderSkuJArray.Count() > 0) |
|
|
@ -491,12 +528,13 @@ namespace BBWY.Server.Business |
|
|
|
DeliveryExpressFreight = orderDeliveryExpressFreight, |
|
|
|
CreateTime = DateTime.Now |
|
|
|
}; |
|
|
|
orderCost.PlatformCommissionAmount = dbOrder.OrderSellerPrice * orderCost.PlatformCommissionRatio; |
|
|
|
orderCost.Profit = dbOrder.OrderSellerPrice + |
|
|
|
dbOrder.FreightPrice - |
|
|
|
orderCost.PurchaseAmount - |
|
|
|
orderCost.DeliveryExpressFreight - |
|
|
|
orderCost.PlatformCommissionAmount; |
|
|
|
orderCost.CalculationOrderProfitAndCost(dbOrder, null); |
|
|
|
//orderCost.PlatformCommissionAmount = dbOrder.OrderSellerPrice * orderCost.PlatformCommissionRatio;
|
|
|
|
//orderCost.Profit = dbOrder.OrderSellerPrice +
|
|
|
|
// dbOrder.FreightPrice -
|
|
|
|
// orderCost.PurchaseAmount -
|
|
|
|
// orderCost.DeliveryExpressFreight -
|
|
|
|
// orderCost.PlatformCommissionAmount;
|
|
|
|
insertOrderCostList.Add(orderCost); |
|
|
|
#endregion
|
|
|
|
} |
|
|
@ -526,6 +564,16 @@ namespace BBWY.Server.Business |
|
|
|
updateOrderList.Add(updateSql); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 删除SD埋点
|
|
|
|
try |
|
|
|
{ |
|
|
|
if (sDCalculationCostRequest != null) |
|
|
|
memoryCache.Remove(orderId); |
|
|
|
} |
|
|
|
catch { } |
|
|
|
#endregion
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#region 补齐sku logo
|
|
|
|