|
@ -129,7 +129,7 @@ namespace BBWY.Server.Business |
|
|
if (request.PurchaseAccountList == null || request.PurchaseAccountList.Count() == 0) |
|
|
if (request.PurchaseAccountList == null || request.PurchaseAccountList.Count() == 0) |
|
|
throw new BusinessException("缺少采购账号"); |
|
|
throw new BusinessException("缺少采购账号"); |
|
|
|
|
|
|
|
|
var skuGroups = request.ProductParamList.GroupBy(p => p.BelongSkuId); |
|
|
var purchaseGroups = request.ProductParamList.GroupBy(p => p.PurchaserId); |
|
|
var extJArray = new List<object>(); |
|
|
var extJArray = new List<object>(); |
|
|
var errorBuilder = new StringBuilder(); |
|
|
var errorBuilder = new StringBuilder(); |
|
|
var freightAmount = 0M; |
|
|
var freightAmount = 0M; |
|
@ -137,9 +137,9 @@ namespace BBWY.Server.Business |
|
|
var totalAmount = 0M; |
|
|
var totalAmount = 0M; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var skuGroup in skuGroups) |
|
|
foreach (var purchaseGroup in purchaseGroups) |
|
|
{ |
|
|
{ |
|
|
var productParamList = skuGroup.ToList(); |
|
|
var productParamList = purchaseGroup.ToList(); |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
var purchasePlatform = productParamList.FirstOrDefault().PurchasePlatform; |
|
|
var purchasePlatform = productParamList.FirstOrDefault().PurchasePlatform; |
|
@ -167,9 +167,9 @@ namespace BBWY.Server.Business |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
if (purchasePlatform == Enums.Platform.拳探) |
|
|
if (purchasePlatform == Enums.Platform.拳探) |
|
|
extJArray.Add(new { BelongSkuId = skuGroup.Key, CardId = previewOrderResponse.Extensions }); |
|
|
extJArray.Add(new { PurchaserId = purchaseGroup.Key, CardId = previewOrderResponse.Extensions }); |
|
|
else if (purchasePlatform == Enums.Platform.阿里巴巴) |
|
|
else if (purchasePlatform == Enums.Platform.阿里巴巴) |
|
|
extJArray.Add(new { BelongSkuId = skuGroup.Key, OrderTradeTypeCode = previewOrderResponse.OrderTradeType?.Code }); |
|
|
extJArray.Add(new { PurchaserId = purchaseGroup.Key, OrderTradeTypeCode = previewOrderResponse.OrderTradeType?.Code }); |
|
|
|
|
|
|
|
|
freightAmount += previewOrderResponse.FreightAmount; |
|
|
freightAmount += previewOrderResponse.FreightAmount; |
|
|
productAmount += previewOrderResponse.ProductAmount; |
|
|
productAmount += previewOrderResponse.ProductAmount; |
|
@ -178,7 +178,6 @@ namespace BBWY.Server.Business |
|
|
catch (Exception ex) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
errorBuilder.AppendLine($"采购商:{productParamList.FirstOrDefault().PurchaserName}"); |
|
|
errorBuilder.AppendLine($"采购商:{productParamList.FirstOrDefault().PurchaserName}"); |
|
|
errorBuilder.AppendLine($"店铺SkuId:{skuGroup.Key}"); |
|
|
|
|
|
errorBuilder.AppendLine(ex.Message); |
|
|
errorBuilder.AppendLine(ex.Message); |
|
|
throw new BusinessException(errorBuilder.ToString()); |
|
|
throw new BusinessException(errorBuilder.ToString()); |
|
|
} |
|
|
} |
|
@ -217,38 +216,40 @@ namespace BBWY.Server.Business |
|
|
var failSkuList = new List<BatchCreareOrderFailDetail>(); |
|
|
var failSkuList = new List<BatchCreareOrderFailDetail>(); |
|
|
|
|
|
|
|
|
var extJArray = JsonConvert.DeserializeObject<JArray>(request.Extensions); |
|
|
var extJArray = JsonConvert.DeserializeObject<JArray>(request.Extensions); |
|
|
var skuGroups = request.ProductParamList.GroupBy(p => p.BelongSkuId); |
|
|
var purchaseGroups = request.ProductParamList.GroupBy(p => p.PurchaserId); |
|
|
|
|
|
|
|
|
foreach (var skuGroup in skuGroups) |
|
|
foreach (var purchaseGroup in purchaseGroups) |
|
|
{ |
|
|
{ |
|
|
var productParamList = skuGroup.ToList(); |
|
|
var productParamList = purchaseGroup.ToList(); |
|
|
|
|
|
var belongSkuGroups = productParamList.GroupBy(p => p.BelongSkuId); |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
var firstProductParam = productParamList.FirstOrDefault(); |
|
|
var purchasePlatform = productParamList.FirstOrDefault().PurchasePlatform; |
|
|
|
|
|
var purchaserId = productParamList.FirstOrDefault().PurchaserId; |
|
|
|
|
|
var purchaserName = productParamList.FirstOrDefault().PurchaserName; |
|
|
|
|
|
|
|
|
var purchaseAccount = request.PurchaseAccountList.FirstOrDefault(pa => pa.PurchasePlatformId == firstProductParam.PurchasePlatform); |
|
|
var purchaseAccount = request.PurchaseAccountList.FirstOrDefault(pa => pa.PurchasePlatformId == purchasePlatform); |
|
|
var platformSDKBusiness = platformSDKBusinessList.FirstOrDefault(p => p.Platform == firstProductParam.PurchasePlatform); |
|
|
var platformSDKBusiness = platformSDKBusinessList.FirstOrDefault(p => p.Platform == purchasePlatform); |
|
|
string tradeMode = "", cardId = ""; |
|
|
string tradeMode = "", cardId = ""; |
|
|
|
|
|
|
|
|
var extJson = extJArray.FirstOrDefault(j => j.Value<string>("BelongSkuId") == skuGroup.Key); |
|
|
var extJson = extJArray.FirstOrDefault(j => j.Value<string>("PurchaserId") == purchaseGroup.Key); |
|
|
if (firstProductParam.PurchasePlatform == Enums.Platform.拳探) |
|
|
if (purchasePlatform == Enums.Platform.拳探) |
|
|
cardId = extJson.Value<string>("CardId"); |
|
|
cardId = extJson.Value<string>("CardId"); |
|
|
else if (firstProductParam.PurchasePlatform == Enums.Platform.阿里巴巴) |
|
|
else if (purchasePlatform == Enums.Platform.阿里巴巴) |
|
|
tradeMode = extJson.Value<string>("OrderTradeTypeCode"); |
|
|
tradeMode = extJson.Value<string>("OrderTradeTypeCode"); |
|
|
|
|
|
|
|
|
var createOrderResponse = platformSDKBusinessList.FirstOrDefault(p => p.Platform == firstProductParam.PurchasePlatform) |
|
|
var createOrderResponse = platformSDKBusinessList.FirstOrDefault(p => p.Platform == purchasePlatform) |
|
|
.FastCreateOrder(new CreateOnlinePurchaseOrderRequest() |
|
|
.FastCreateOrder(new CreateOnlinePurchaseOrderRequest() |
|
|
{ |
|
|
{ |
|
|
AppKey = purchaseAccount.AppKey, |
|
|
AppKey = purchaseAccount.AppKey, |
|
|
AppSecret = purchaseAccount.AppSecret, |
|
|
AppSecret = purchaseAccount.AppSecret, |
|
|
AppToken = purchaseAccount.AppToken, |
|
|
AppToken = purchaseAccount.AppToken, |
|
|
Platform = firstProductParam.PurchasePlatform, |
|
|
Platform = purchasePlatform, |
|
|
Consignee = request.Consignee, |
|
|
Consignee = request.Consignee, |
|
|
PurchaseOrderMode = request.PurchaseOrderMode, |
|
|
PurchaseOrderMode = request.PurchaseOrderMode, |
|
|
Remark = request.Remark, |
|
|
Remark = request.Remark, |
|
|
SourceShopName = request.ShopName, |
|
|
SourceShopName = request.ShopName, |
|
|
SourceSku = skuGroup.Key, |
|
|
SourceSku = string.Join(",", belongSkuGroups.Select(g => g.Key)), |
|
|
CargoParamList = productParamList.Select(p => new CargoParamRequest() |
|
|
CargoParamList = productParamList.Select(p => new CargoParamRequest() |
|
|
{ |
|
|
{ |
|
|
ProductId = p.PurchaseProductId, |
|
|
ProductId = p.PurchaseProductId, |
|
@ -260,24 +261,55 @@ namespace BBWY.Server.Business |
|
|
Extensions = cardId |
|
|
Extensions = cardId |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var purchaseOrderSimpleInfo = platformSDKBusinessList.FirstOrDefault(p => p.Platform == purchasePlatform).GetOrderSimpleInfo(new GetOrderInfoRequest() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var purchaseOrderSimpleInfo = platformSDKBusinessList.FirstOrDefault(p => p.Platform == firstProductParam.PurchasePlatform).GetOrderSimpleInfo(new GetOrderInfoRequest() |
|
|
|
|
|
{ |
|
|
{ |
|
|
AppKey = purchaseAccount.AppKey, |
|
|
AppKey = purchaseAccount.AppKey, |
|
|
AppSecret = purchaseAccount.AppSecret, |
|
|
AppSecret = purchaseAccount.AppSecret, |
|
|
AppToken = purchaseAccount.AppToken, |
|
|
AppToken = purchaseAccount.AppToken, |
|
|
OrderId = createOrderResponse.PurchaseOrderId, |
|
|
OrderId = createOrderResponse.PurchaseOrderId, |
|
|
Platform = firstProductParam.PurchasePlatform |
|
|
Platform = purchasePlatform |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<PurchaseOrderSku> insertPurchaseOrderSkuList = new List<PurchaseOrderSku>(); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var belongSkuGroup in belongSkuGroups) |
|
|
|
|
|
{ |
|
|
|
|
|
var firstProductParam = belongSkuGroup.FirstOrDefault(); |
|
|
|
|
|
var currentOrderSkuProductAmount = 0M; //采购成本
|
|
|
|
|
|
currentOrderSkuProductAmount = purchaseOrderSimpleInfo.ItemList.Where(p => belongSkuGroup.Any(p1 => p1.PurchaseSkuId == p.SkuId)) |
|
|
|
|
|
?.Sum(p => p.ProductAmount) ?? 0M; |
|
|
|
|
|
|
|
|
|
|
|
var currentOrderSkuFreightAmount = purchaseOrderSimpleInfo.FreightAmount / belongSkuGroups.Count(); //采购运费(按sku数均分)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var purchaseOrderSku = new PurchaseOrderSku() |
|
|
|
|
|
{ |
|
|
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
|
|
ShopId = request.ShopId, |
|
|
|
|
|
PurchaseOrderId = createOrderResponse.PurchaseOrderId, |
|
|
|
|
|
ProductId = firstProductParam.BelongProductId, |
|
|
|
|
|
SkuId = firstProductParam.BelongSkuId, |
|
|
|
|
|
Price = firstProductParam.BelongPrice, |
|
|
|
|
|
SkuTitle = firstProductParam.BelongSkuTitle, |
|
|
|
|
|
Logo = firstProductParam.BelongLogo, |
|
|
|
|
|
Quantity = firstProductParam.BelongQuantity, |
|
|
|
|
|
PurchaseSchemeId = firstProductParam.BelongPurchaseSchemeId, |
|
|
|
|
|
PurchaseSkuIds = string.Join(",", belongSkuGroup.Select(p => p.PurchaseSkuId).ToList()), |
|
|
|
|
|
PurchaseAmount = currentOrderSkuProductAmount + currentOrderSkuFreightAmount, |
|
|
|
|
|
ProductAmount = currentOrderSkuProductAmount, |
|
|
|
|
|
PurchaseFreight = currentOrderSkuFreightAmount, |
|
|
|
|
|
CreateTime = DateTime.Now |
|
|
|
|
|
}; |
|
|
|
|
|
insertPurchaseOrderSkuList.Add(purchaseOrderSku); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var purchaseOrderV2 = new PurchaseOrderV2() |
|
|
var purchaseOrderV2 = new PurchaseOrderV2() |
|
|
{ |
|
|
{ |
|
|
Id = createOrderResponse.PurchaseOrderId, |
|
|
Id = createOrderResponse.PurchaseOrderId, |
|
|
ShopId = request.ShopId, |
|
|
ShopId = request.ShopId, |
|
|
OrderState = createOrderResponse.IsPay ? Enums.PurchaseOrderState.待发货 : Enums.PurchaseOrderState.待付款, |
|
|
OrderState = createOrderResponse.IsPay ? Enums.PurchaseOrderState.待发货 : Enums.PurchaseOrderState.待付款, |
|
|
PurchasePlatform = firstProductParam.PurchasePlatform, |
|
|
PurchasePlatform = purchasePlatform, |
|
|
ConsigneeContactName = request.Consignee.ContactName, |
|
|
ConsigneeContactName = request.Consignee.ContactName, |
|
|
ConsigneeMobile = request.Consignee.Mobile, |
|
|
ConsigneeMobile = request.Consignee.Mobile, |
|
|
ConsigneeProvince = request.Consignee.Province, |
|
|
ConsigneeProvince = request.Consignee.Province, |
|
@ -285,8 +317,8 @@ namespace BBWY.Server.Business |
|
|
ConsigneeCounty = request.Consignee.County, |
|
|
ConsigneeCounty = request.Consignee.County, |
|
|
ConsigneeTown = request.Consignee.Town, |
|
|
ConsigneeTown = request.Consignee.Town, |
|
|
ConsigneeAddress = request.Consignee.Address, |
|
|
ConsigneeAddress = request.Consignee.Address, |
|
|
PurchaserId = firstProductParam.PurchaserId, |
|
|
PurchaserId = purchaserId, |
|
|
PurchaserName = firstProductParam.PurchaserName, |
|
|
PurchaserName = purchaserName, |
|
|
PurchaseAccountId = purchaseAccount.Id, |
|
|
PurchaseAccountId = purchaseAccount.Id, |
|
|
PurchaseAmount = purchaseOrderSimpleInfo.TotalAmount, |
|
|
PurchaseAmount = purchaseOrderSimpleInfo.TotalAmount, |
|
|
ProductAmount = purchaseOrderSimpleInfo.ProductAmount, |
|
|
ProductAmount = purchaseOrderSimpleInfo.ProductAmount, |
|
@ -299,40 +331,21 @@ namespace BBWY.Server.Business |
|
|
if (createOrderResponse.IsPay) |
|
|
if (createOrderResponse.IsPay) |
|
|
purchaseOrderV2.PayTime = DateTime.Now; |
|
|
purchaseOrderV2.PayTime = DateTime.Now; |
|
|
|
|
|
|
|
|
var purchaseOrderSku = new PurchaseOrderSku() |
|
|
|
|
|
{ |
|
|
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
|
|
ShopId = request.ShopId, |
|
|
|
|
|
PurchaseOrderId = createOrderResponse.PurchaseOrderId, |
|
|
|
|
|
ProductId = firstProductParam.BelongProductId, |
|
|
|
|
|
SkuId = firstProductParam.BelongSkuId, |
|
|
|
|
|
Price = firstProductParam.BelongPrice, |
|
|
|
|
|
SkuTitle = firstProductParam.BelongSkuTitle, |
|
|
|
|
|
Logo = firstProductParam.BelongLogo, |
|
|
|
|
|
Quantity = firstProductParam.BelongQuantity, |
|
|
|
|
|
PurchaseSchemeId = firstProductParam.BelongPurchaseSchemeId, |
|
|
|
|
|
PurchaseSkuIds = string.Join(",", productParamList.Select(p => p.PurchaseSkuId).ToList()), |
|
|
|
|
|
PurchaseAmount = purchaseOrderSimpleInfo.TotalAmount, |
|
|
|
|
|
ProductAmount = purchaseOrderSimpleInfo.ProductAmount, |
|
|
|
|
|
PurchaseFreight = purchaseOrderSimpleInfo.FreightAmount, |
|
|
|
|
|
CreateTime = DateTime.Now |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
fsql.Transaction(() => |
|
|
fsql.Transaction(() => |
|
|
{ |
|
|
{ |
|
|
fsql.Insert(purchaseOrderV2).ExecuteAffrows(); |
|
|
fsql.Insert(purchaseOrderV2).ExecuteAffrows(); |
|
|
fsql.Insert(purchaseOrderSku).ExecuteAffrows(); |
|
|
//fsql.Insert(purchaseOrderSku).ExecuteAffrows();
|
|
|
|
|
|
fsql.Insert(insertPurchaseOrderSkuList).ExecuteAffrows(); |
|
|
}); |
|
|
}); |
|
|
successSkuIdList.Add(skuGroup.Key); |
|
|
successSkuIdList.AddRange(belongSkuGroups.Select(g => g.Key)); |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
failSkuList.Add(new BatchCreareOrderFailDetail() |
|
|
failSkuList.AddRange(belongSkuGroups.Select(g => new BatchCreareOrderFailDetail() |
|
|
{ |
|
|
{ |
|
|
SkuId = skuGroup.Key, |
|
|
SkuId = g.Key, |
|
|
ErrorMsg = ex.Message |
|
|
ErrorMsg = ex.Message |
|
|
}); |
|
|
})); |
|
|
|
|
|
|
|
|
//throw new BusinessException(errorBuilder.ToString());
|
|
|
//throw new BusinessException(errorBuilder.ToString());
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|