|
|
@ -11,6 +11,7 @@ using BBWYB.Server.Model.Db.Mds; |
|
|
|
using BBWYB.Server.Model.Db.MDS; |
|
|
|
using BBWYB.Server.Model.Dto; |
|
|
|
using FreeSql; |
|
|
|
using Microsoft.Extensions.Caching.Memory; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Newtonsoft.Json.Linq; |
|
|
@ -41,6 +42,7 @@ namespace BBWYB.Server.Business |
|
|
|
private Lazy<VenderBusiness> venderBusinessLazy; |
|
|
|
private Lazy<PurchaseSchemeBusiness> purchaseSchemeBusinessLazy; |
|
|
|
private Lazy<TimeLimitRules> timeLimitRulesLazy; |
|
|
|
private Lazy<IMemoryCache> memoryCacheLazy; |
|
|
|
|
|
|
|
private PP_PlatformClientFactory ppPlatformClientFactory => pplatformClientFactoryLazy.Value; |
|
|
|
private TaskSchedulerManager taskSchedulerManager => taskSchedulerManagerLazy.Value; |
|
|
@ -59,8 +61,12 @@ namespace BBWYB.Server.Business |
|
|
|
|
|
|
|
private TimeLimitRules timeLimitRules => timeLimitRulesLazy.Value; |
|
|
|
|
|
|
|
private IMemoryCache memoryCache => memoryCacheLazy.Value; |
|
|
|
|
|
|
|
private IList<Enums.OrderState> cantPurchaseOrderStateList; |
|
|
|
|
|
|
|
private TimeSpan _1688ConcurrentKeyTimeSpan; |
|
|
|
|
|
|
|
public PurchaseOrderBusiness(IFreeSql fsql, |
|
|
|
NLogManager nLogManager, |
|
|
|
IIdGenerator idGenerator, |
|
|
@ -79,12 +85,14 @@ namespace BBWYB.Server.Business |
|
|
|
venderBusinessLazy = new Lazy<VenderBusiness>(() => serviceProvider.GetService<VenderBusiness>()); |
|
|
|
purchaseSchemeBusinessLazy = new Lazy<PurchaseSchemeBusiness>(() => serviceProvider.GetService<PurchaseSchemeBusiness>()); |
|
|
|
timeLimitRulesLazy = new Lazy<TimeLimitRules>(() => serviceProvider.GetService<TimeLimitRules>()); |
|
|
|
memoryCacheLazy = new Lazy<IMemoryCache>(() => serviceProvider.GetService<IMemoryCache>()); |
|
|
|
cantPurchaseOrderStateList = new List<Enums.OrderState>() |
|
|
|
{ |
|
|
|
Enums.OrderState.已取消, |
|
|
|
Enums.OrderState.已完成, |
|
|
|
Enums.OrderState.待付款 |
|
|
|
}; |
|
|
|
_1688ConcurrentKeyTimeSpan = new TimeSpan(0, 1, 0); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -523,49 +531,33 @@ namespace BBWYB.Server.Business |
|
|
|
var allCargoParamList = new List<CargoParamRequest>(); |
|
|
|
request.CargoParamGroupList.ForEach(x => allCargoParamList.AddRange(x.CargoParamList)); |
|
|
|
|
|
|
|
#region 更新采购方案
|
|
|
|
{ |
|
|
|
var cargoParamGroupsBySchemeList = allCargoParamList.GroupBy(c => c.SchemeId); |
|
|
|
foreach (var cargoParamGroupsByScheme in cargoParamGroupsBySchemeList) |
|
|
|
{ |
|
|
|
var schemeId = cargoParamGroupsByScheme.Key; |
|
|
|
var skuId = cargoParamGroupsByScheme.FirstOrDefault().BelongSkuId; |
|
|
|
var skuItemCount = orderSkus.FirstOrDefault(osku => osku.SkuId == skuId)?.ItemTotal ?? 0; |
|
|
|
//#region 更新采购方案
|
|
|
|
//{
|
|
|
|
// var cargoParamGroupsBySchemeList = allCargoParamList.GroupBy(c => c.SchemeId);
|
|
|
|
// foreach (var cargoParamGroupsByScheme in cargoParamGroupsBySchemeList)
|
|
|
|
// {
|
|
|
|
// var schemeId = cargoParamGroupsByScheme.Key;
|
|
|
|
// var skuId = cargoParamGroupsByScheme.FirstOrDefault().BelongSkuId;
|
|
|
|
// var skuItemCount = orderSkus.FirstOrDefault(osku => osku.SkuId == skuId)?.ItemTotal ?? 0;
|
|
|
|
|
|
|
|
//var lastPurchasePriceCost = cargoParamGroupsByScheme.Sum(cargoParam => createdPurchaseOrderItemList.Where(x => x.SkuId == cargoParam.SkuId)
|
|
|
|
// .Select(x => x.Price * (cargoParam.PurchaseRatio ?? 1))
|
|
|
|
// .DefaultIfEmpty(0M)
|
|
|
|
// .First());
|
|
|
|
// //var lastPurchasePriceCost = cargoParamGroupsByScheme.Sum(cargoParam => createdPurchaseOrderItemList.Where(x => x.SkuId == cargoParam.SkuId)
|
|
|
|
// // .Select(x => x.Price * (cargoParam.PurchaseRatio ?? 1))
|
|
|
|
// // .DefaultIfEmpty(0M)
|
|
|
|
// // .First());
|
|
|
|
|
|
|
|
var lastPurchasePriceCost = cargoParamGroupsByScheme.Sum(cargoParam => |
|
|
|
{ |
|
|
|
return (createdPurchaseOrderItemList.FirstOrDefault(x => x.SkuId == cargoParam.SkuId)?.Price ?? 0) * (cargoParam.PurchaseRatio ?? 1); |
|
|
|
}); |
|
|
|
// var lastPurchasePriceCost = cargoParamGroupsByScheme.Sum(cargoParam =>
|
|
|
|
// {
|
|
|
|
// return (createdPurchaseOrderItemList.FirstOrDefault(x => x.SkuId == cargoParam.SkuId)?.Price ?? 0) * (cargoParam.PurchaseRatio ?? 1);
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
var purchasedAmount = insertOrderCostDetails.Where(ocd => ocd.SkuId == skuId).Sum(ocd => ocd.SkuAmount); |
|
|
|
var update = fsql.Update<PurchaseScheme>(schemeId).Set(ps => ps.LastPurchaseTime, DateTime.Now) |
|
|
|
.Set(ps => ps.LastPurchasePriceCost, lastPurchasePriceCost) |
|
|
|
.Set(ps => ps.PurchasedCount + 1) |
|
|
|
.Set(ps => ps.PurchasedItemCount + skuItemCount) |
|
|
|
.Set(ps => ps.PurchasedAmount + purchasedAmount); |
|
|
|
updatePurchaseSchemeList.Add(update); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
//#region 更新采购配件
|
|
|
|
//{
|
|
|
|
// foreach (var cargoParam in allCargoParamList)
|
|
|
|
// {
|
|
|
|
// var createOrderItem = createdPurchaseOrderItemList.FirstOrDefault(x => x.SkuId == cargoParam.SkuId);
|
|
|
|
// if (createOrderItem != null)
|
|
|
|
// {
|
|
|
|
// var update = fsql.Update<PurchaseSchemeProductSku>()
|
|
|
|
// .Set(pss => pss.LastPurchasePriceCost, createOrderItem.Price)
|
|
|
|
// .Where(pss => pss.PurchaseSkuId == cargoParam.SkuId && pss.SkuPurchaseSchemeId == cargoParam.SchemeId);
|
|
|
|
// updatePssList.Add(update);
|
|
|
|
// }
|
|
|
|
// var purchasedAmount = insertOrderCostDetails.Where(ocd => ocd.SkuId == skuId).Sum(ocd => ocd.SkuAmount);
|
|
|
|
// var update = fsql.Update<PurchaseScheme>(schemeId).Set(ps => ps.LastPurchaseTime, DateTime.Now)
|
|
|
|
// .Set(ps => ps.LastPurchasePriceCost, lastPurchasePriceCost)
|
|
|
|
// .Set(ps => ps.PurchasedCount + 1)
|
|
|
|
// .Set(ps => ps.PurchasedItemCount + skuItemCount)
|
|
|
|
// .Set(ps => ps.PurchasedAmount + purchasedAmount);
|
|
|
|
// updatePurchaseSchemeList.Add(update);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//#endregion
|
|
|
@ -2364,25 +2356,56 @@ namespace BBWYB.Server.Business |
|
|
|
//}
|
|
|
|
|
|
|
|
#region 1688CallBack
|
|
|
|
private string Get1688ConcurrentKey(JObject j) |
|
|
|
{ |
|
|
|
var type = j.Value<string>("type").ToUpper(); |
|
|
|
var poId = string.Empty; |
|
|
|
switch (type) |
|
|
|
{ |
|
|
|
case "ORDER_BUYER_VIEW_PART_PART_SENDGOODS": //部分发货
|
|
|
|
case "ORDER_BUYER_VIEW_ANNOUNCE_SENDGOODS": //发货
|
|
|
|
case "ORDER_BUYER_VIEW_ORDER_PRICE_MODIFY": //订单改价
|
|
|
|
case "LOGISTICS_BUYER_VIEW_TRACE": //物流变更
|
|
|
|
case "ORDER_BUYER_VIEW_ORDER_PAY": //支付
|
|
|
|
poId = j["data"].Value<string>("orderId"); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
if (string.IsNullOrEmpty(poId)) |
|
|
|
return string.Empty; |
|
|
|
|
|
|
|
return $"{type}_{poId}"; |
|
|
|
} |
|
|
|
|
|
|
|
public void CallbackFrom1688(string jsonStr) |
|
|
|
{ |
|
|
|
nLogManager.Default().Info(jsonStr); |
|
|
|
var jObject = JObject.Parse(jsonStr); |
|
|
|
var _1688ConcurrentKey = Get1688ConcurrentKey(jObject); |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(_1688ConcurrentKey)) |
|
|
|
{ |
|
|
|
if (memoryCache.TryGetValue<string>(_1688ConcurrentKey, out _)) |
|
|
|
return;//并发key存在,不允执行
|
|
|
|
memoryCache.Set(_1688ConcurrentKey, _1688ConcurrentKey, _1688ConcurrentKeyTimeSpan); |
|
|
|
} |
|
|
|
|
|
|
|
var type = jObject.Value<string>("type").ToUpper(); |
|
|
|
switch (type) |
|
|
|
{ |
|
|
|
case "ORDER_BUYER_VIEW_PART_PART_SENDGOODS": //部分发货
|
|
|
|
case "ORDER_BUYER_VIEW_ANNOUNCE_SENDGOODS": //发货
|
|
|
|
DeliveryCallbackFrom1688(jObject); |
|
|
|
DeliveryCallbackFrom1688(jObject, _1688ConcurrentKey); |
|
|
|
break; |
|
|
|
case "ORDER_BUYER_VIEW_ORDER_PRICE_MODIFY": |
|
|
|
OrderPriceModificationCallbackFrom1688(jObject); //订单改价
|
|
|
|
OrderPriceModificationCallbackFrom1688(jObject, _1688ConcurrentKey); //订单改价
|
|
|
|
break; |
|
|
|
case "LOGISTICS_BUYER_VIEW_TRACE": |
|
|
|
// LogisticsUpdateCallbackFrom1688(jObject);//1688物流信息变更
|
|
|
|
break; |
|
|
|
case "ORDER_BUYER_VIEW_ORDER_PAY": |
|
|
|
OrderPayFrom1688(jObject); |
|
|
|
OrderPayFrom1688(jObject, _1688ConcurrentKey); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
@ -2393,17 +2416,21 @@ namespace BBWYB.Server.Business |
|
|
|
/// 1688发货回调
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="jObject"></param>
|
|
|
|
private void DeliveryCallbackFrom1688(JObject jObject) |
|
|
|
/// <param name="_1688ConcurrentKey">并发key</param>
|
|
|
|
private void DeliveryCallbackFrom1688(JObject jObject, string _1688ConcurrentKey) |
|
|
|
{ |
|
|
|
var purchaseOrderId = jObject["data"].Value<string>("orderId"); |
|
|
|
Task.Factory.StartNew(() => DeliveryCallbackFrom1688(purchaseOrderId), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
|
Task.Factory.StartNew(() => DeliveryCallbackFrom1688(purchaseOrderId, _1688ConcurrentKey), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 1688发货回调
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="purchaseOrderId">采购单</param>
|
|
|
|
private void DeliveryCallbackFrom1688(string purchaseOrderId) |
|
|
|
/// <param name="purchaseOrderId"></param>
|
|
|
|
/// <param name="_1688ConcurrentKey"></param>
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
/// <exception cref="BusinessException"></exception>
|
|
|
|
private void DeliveryCallbackFrom1688(string purchaseOrderId, string _1688ConcurrentKey) |
|
|
|
{ |
|
|
|
string orderId = string.Empty; |
|
|
|
long? shopId = null; |
|
|
@ -2641,22 +2668,28 @@ namespace BBWYB.Server.Business |
|
|
|
{ |
|
|
|
nLogManager.Default().Error(ex, $"DeliveryCallback 回调平台1688,订单号{orderId},采购单号{purchaseOrderId},执行进度[{currentProgress}],采购单物流信息:{wayBillNoResponseInfo}"); |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(_1688ConcurrentKey)) |
|
|
|
memoryCache.Remove(_1688ConcurrentKey); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 1688订单改价回调
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="jObject"></param>
|
|
|
|
private void OrderPriceModificationCallbackFrom1688(JObject jObject) |
|
|
|
/// <param name="_1688ConcurrentKey"></param>
|
|
|
|
private void OrderPriceModificationCallbackFrom1688(JObject jObject, string _1688ConcurrentKey) |
|
|
|
{ |
|
|
|
var purchaseOrderId = jObject["data"].Value<string>("orderId"); |
|
|
|
Task.Factory.StartNew(() => OrderPriceModificationCallback(purchaseOrderId, Enums.Platform.阿里巴巴), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
|
Task.Factory.StartNew(() => OrderPriceModificationCallback(purchaseOrderId, Enums.Platform.阿里巴巴, _1688ConcurrentKey), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
|
} |
|
|
|
|
|
|
|
private void OrderPayFrom1688(JObject jObject) |
|
|
|
private void OrderPayFrom1688(JObject jObject, string _1688ConcurrentKey) |
|
|
|
{ |
|
|
|
var purchaseOrderId = jObject["data"].Value<string>("orderId"); |
|
|
|
Task.Factory.StartNew(() => OrderPayCallback(purchaseOrderId, Enums.Platform.阿里巴巴), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
|
Task.Factory.StartNew(() => OrderPayCallback(purchaseOrderId, Enums.Platform.阿里巴巴, _1688ConcurrentKey), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
@ -2666,14 +2699,21 @@ namespace BBWYB.Server.Business |
|
|
|
/// </summary>
|
|
|
|
/// <param name="purchaseOrderId"></param>
|
|
|
|
/// <param name="callbackPlatform"></param>
|
|
|
|
private void OrderPriceModificationCallback(string purchaseOrderId, Enums.Platform callbackPlatform) |
|
|
|
/// <param name="concurrentKey"></param>
|
|
|
|
private void OrderPriceModificationCallback(string purchaseOrderId, Enums.Platform callbackPlatform, string concurrentKey) |
|
|
|
{ |
|
|
|
OnSomeOnePurchaseOrderChanged(purchaseOrderId, true); |
|
|
|
OnSomeOnePurchaseOrderChanged(purchaseOrderId, true, concurrentKey); |
|
|
|
} |
|
|
|
|
|
|
|
private void OrderPayCallback(string purchaseOrderId, Enums.Platform callbackPlatform) |
|
|
|
/// <summary>
|
|
|
|
/// 订单支付回调
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="purchaseOrderId"></param>
|
|
|
|
/// <param name="callbackPlatform"></param>
|
|
|
|
/// <param name="concurrentKey"></param>
|
|
|
|
private void OrderPayCallback(string purchaseOrderId, Enums.Platform callbackPlatform, string concurrentKey) |
|
|
|
{ |
|
|
|
OnSomeOnePurchaseOrderChanged(purchaseOrderId, false); |
|
|
|
OnSomeOnePurchaseOrderChanged(purchaseOrderId, false, concurrentKey); |
|
|
|
} |
|
|
|
|
|
|
|
public void KuaiDi100Publish(string param) |
|
|
@ -2945,7 +2985,8 @@ namespace BBWYB.Server.Business |
|
|
|
/// </summary>
|
|
|
|
/// <param name="purchaseOrderId">采购单Id</param>
|
|
|
|
/// <param name="keepRunWhenNoEditOrderPirce">当不需要触发订单改价时是否继续走流程</param>
|
|
|
|
public void OnSomeOnePurchaseOrderChanged(string purchaseOrderId, bool keepRunWhenNoEditOrderPirce) |
|
|
|
/// <param name="concurrentKey">并发key</param>
|
|
|
|
public void OnSomeOnePurchaseOrderChanged(string purchaseOrderId, bool keepRunWhenNoEditOrderPirce, string concurrentKey) |
|
|
|
{ |
|
|
|
bool isEditOrderPrice = true; |
|
|
|
try |
|
|
@ -3200,6 +3241,11 @@ namespace BBWYB.Server.Business |
|
|
|
{ |
|
|
|
nLogManager.Default().Error(ex, $"OrderPriceModificationCallback 采购单号{purchaseOrderId}"); |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(concurrentKey)) |
|
|
|
memoryCache.Remove(concurrentKey); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void SendDingDing(string content) |
|
|
|