You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
4.9 KiB

using BBWYB.Common.Http;
using BBWYB.Common.Models;
using BBWYB.Server.Model;
using BBWYB.Server.Model.Db;
namespace BBWYB.Server.Business
{
public class QiKuManager : IDenpendency
{
private RestApiService restApiService;
private IFreeSql fsql;
public QiKuManager(RestApiService restApiService, IFreeSql fsql)
{
this.restApiService = restApiService;
this.fsql = fsql;
}
/// <summary>
/// 通知齐库
/// <para>支持关联的采购平台以来源SKU为单位通知齐库</para>
/// <para>不支持关联的采购平台以采购单为单位通知齐库</para>
/// </summary>
/// <param name="orderPurchaseInfo"></param>
/// <param name="orderPurchaseRelationInfoList"></param>
/// <param name="orderPurchaseSkuInfoList"></param>
/// <param name="purchaseExpressOrderList"></param>
public void PublishQiKu(OrderPurchaseInfo orderPurchaseInfo,
IList<OrderPurchaseRelationInfo> orderPurchaseRelationInfoList,
IList<OrderPurchaseSkuInfo> orderPurchaseSkuInfoList,
IList<PurchaseExpressOrder> purchaseExpressOrderList)
{
if (orderPurchaseInfo.PurchasePlatform == Enums.Platform.)
PublishQiKuByRelation(orderPurchaseRelationInfoList, orderPurchaseSkuInfoList, purchaseExpressOrderList);
else
PublishQiKuPurchaseExpressOrder(orderPurchaseInfo, purchaseExpressOrderList);
}
private void PublishQiKuByRelation(IList<OrderPurchaseRelationInfo> orderPurchaseRelationInfoList,
IList<OrderPurchaseSkuInfo> orderPurchaseSkuInfoList,
IList<PurchaseExpressOrder> purchaseExpressOrderList)
{
try
{
var relationGroups = orderPurchaseRelationInfoList.GroupBy(opri => opri.SourceSkuId);
foreach (var relationGroup in relationGroups)
{
bool isSignAll = true;
foreach (var relation in relationGroup)
{
var purchaseSku = orderPurchaseSkuInfoList.FirstOrDefault(x => x.PurchaseSkuId == relation.PurchaseSkuId);
if (purchaseSku == null || string.IsNullOrEmpty(purchaseSku.WaybillNo))
{
isSignAll = false;
continue;
}
var purchaseExpressOrder = purchaseExpressOrderList.FirstOrDefault(x => x.WaybillNo == purchaseSku.WaybillNo);
if (purchaseExpressOrder == null || purchaseExpressOrder.ExpressState != "QianShou")
{
isSignAll = false;
continue;
}
}
restApiService.SendRequest("http://qiku.qiyue666.com",
"/Api/PackPurchaseTask/UpdateAvailabilityState",
new
{
availability = isSignAll ? 0 : 1,
orderId = relationGroup.FirstOrDefault().OrderId,
skuId = relationGroup.Key
},
null,
HttpMethod.Post);
}
}
catch (Exception ex)
{
}
}
private void PublishQiKuPurchaseExpressOrder(OrderPurchaseInfo orderPurchaseInfo, IList<PurchaseExpressOrder> purchaseExpressOrderList)
{
try
{
if (string.IsNullOrEmpty(orderPurchaseInfo.BelongSkuIds))
return;
var orderId = purchaseExpressOrderList.FirstOrDefault().OrderId;
var orderSkuList = fsql.Select<OrderSku>().Where(osku => osku.OrderId == orderId).ToList();
var isSignAll = !purchaseExpressOrderList.Any(x => x.ExpressState != "QianShou");
var notifyList = orderSkuList.Where(osku => orderPurchaseInfo.BelongSkuIds.Contains(osku.SkuId)).ToList();
if (notifyList.Count() == 0)
return;
foreach (var notifySku in notifyList)
{
restApiService.SendRequest("http://qiku.qiyue666.com",
"/Api/PackPurchaseTask/UpdateAvailabilityState",
new
{
availability = isSignAll ? 0 : 1,
orderId = notifySku.OrderId,
skuId = notifySku.BelongSkuId
},
null,
HttpMethod.Post);
}
}
catch
{
}
}
}
}