|
|
@ -1,4 +1,5 @@ |
|
|
|
using BBWY.Common.Models; |
|
|
|
using BBWY.Server.Model; |
|
|
|
using BBWY.Server.Model.Db; |
|
|
|
using BBWY.Server.Model.Dto; |
|
|
|
using Newtonsoft.Json; |
|
|
@ -104,6 +105,12 @@ namespace BBWY.Server.Business |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 预览订单
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <exception cref="BusinessException"></exception>
|
|
|
|
public PreviewOrderResponse PreviewOrder(BatchPurchasePreviewOrderRequest request) |
|
|
|
{ |
|
|
|
/* |
|
|
@ -120,7 +127,7 @@ namespace BBWY.Server.Business |
|
|
|
if (request.PurchaseAccountList == null || request.PurchaseAccountList.Count() == 0) |
|
|
|
throw new BusinessException("缺少采购账号"); |
|
|
|
|
|
|
|
var purchaserGroups = request.ProductParamList.GroupBy(p => p.PurchaserId); |
|
|
|
var skuGroups = request.ProductParamList.GroupBy(p => p.BelongSkuId); |
|
|
|
var carIds = new List<object>(); |
|
|
|
var errorBuilder = new StringBuilder(); |
|
|
|
var freightAmount = 0M; |
|
|
@ -128,9 +135,9 @@ namespace BBWY.Server.Business |
|
|
|
var totalAmount = 0M; |
|
|
|
|
|
|
|
|
|
|
|
foreach (var purchaserGroup in purchaserGroups) |
|
|
|
foreach (var skuGroup in skuGroups) |
|
|
|
{ |
|
|
|
var productParamList = purchaserGroup.ToList(); |
|
|
|
var productParamList = skuGroup.ToList(); |
|
|
|
try |
|
|
|
{ |
|
|
|
var purchasePlatform = productParamList.FirstOrDefault().PurchasePlatform; |
|
|
@ -154,10 +161,10 @@ namespace BBWY.Server.Business |
|
|
|
}).ToList() |
|
|
|
}); |
|
|
|
|
|
|
|
if (purchasePlatform == Model.Enums.Platform.拳探) |
|
|
|
carIds.Add(new { PurchaserId = purchaserGroup.Key, CardId = previewOrderResponse.Extensions }); |
|
|
|
else if (purchasePlatform == Model.Enums.Platform.阿里巴巴) |
|
|
|
carIds.Add(new { PurchaserId = purchaserGroup.Key, OrderTradeTypeCode = previewOrderResponse.OrderTradeType?.Code }); |
|
|
|
if (purchasePlatform == Enums.Platform.拳探) |
|
|
|
carIds.Add(new { BelongSkuId = skuGroup.Key, CardId = previewOrderResponse.Extensions }); |
|
|
|
else if (purchasePlatform == Enums.Platform.阿里巴巴) |
|
|
|
carIds.Add(new { BelongSkuId = skuGroup.Key, OrderTradeTypeCode = previewOrderResponse.OrderTradeType?.Code }); |
|
|
|
|
|
|
|
freightAmount += previewOrderResponse.FreightAmount; |
|
|
|
productAmount += previewOrderResponse.ProductAmount; |
|
|
@ -166,7 +173,7 @@ namespace BBWY.Server.Business |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
errorBuilder.AppendLine($"采购商:{productParamList.FirstOrDefault().PurchaserName}"); |
|
|
|
errorBuilder.AppendLine($"店铺SkuId:{string.Join(",", productParamList.Select(p => p.BelongSkuId))}"); |
|
|
|
errorBuilder.AppendLine($"店铺SkuId:{skuGroup.Key}"); |
|
|
|
errorBuilder.AppendLine(ex.Message); |
|
|
|
throw new BusinessException(errorBuilder.ToString()); |
|
|
|
} |
|
|
@ -181,9 +188,160 @@ namespace BBWY.Server.Business |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
public void BatchCreateOrder() |
|
|
|
{ |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 创建订单
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request"></param>
|
|
|
|
public BatchCreareOrderResponse BatchCreateOrder(BatchPurchaseCreateOrderRequest request) |
|
|
|
{ |
|
|
|
/* |
|
|
|
下单报价日志 |
|
|
|
*/ |
|
|
|
|
|
|
|
if (request.ProductParamList == null || request.ProductParamList.Count() == 0) |
|
|
|
throw new BusinessException("缺少商品参数"); |
|
|
|
if (request.Consignee == null || |
|
|
|
string.IsNullOrEmpty(request.Consignee.Address) || |
|
|
|
string.IsNullOrEmpty(request.Consignee.Mobile) || |
|
|
|
string.IsNullOrEmpty(request.Consignee.ContactName)) |
|
|
|
throw new BusinessException("缺少收货人信息"); |
|
|
|
if (request.PurchaseAccountList == null || request.PurchaseAccountList.Count() == 0) |
|
|
|
throw new BusinessException("缺少采购账号"); |
|
|
|
|
|
|
|
var successSkuIdList = new List<string>(); |
|
|
|
var failSkuList = new List<BatchCreareOrderFailDetail>(); |
|
|
|
|
|
|
|
var extJArray = JsonConvert.DeserializeObject<JArray>(request.Extensions); |
|
|
|
var skuGroups = request.ProductParamList.GroupBy(p => p.BelongSkuId); |
|
|
|
|
|
|
|
foreach (var skuGroup in skuGroups) |
|
|
|
{ |
|
|
|
var productParamList = skuGroup.ToList(); |
|
|
|
try |
|
|
|
{ |
|
|
|
var firstProductParam = productParamList.FirstOrDefault(); |
|
|
|
|
|
|
|
|
|
|
|
var purchaseAccount = request.PurchaseAccountList.FirstOrDefault(pa => pa.PurchasePlatformId == firstProductParam.PurchasePlatform); |
|
|
|
var platformSDKBusiness = platformSDKBusinessList.FirstOrDefault(p => p.Platform == v.PurchasePlatform); |
|
|
|
string tradeMode = "", cardId = ""; |
|
|
|
|
|
|
|
var extJson = extJArray.FirstOrDefault(j => j.Value<string>("BelongSkuId") == skuGroup.Key); |
|
|
|
if (firstProductParam.PurchasePlatform == Enums.Platform.拳探) |
|
|
|
cardId = extJson.Value<string>("CardId"); |
|
|
|
else if (firstProductParam.PurchasePlatform == Enums.Platform.阿里巴巴) |
|
|
|
tradeMode = extJson.Value<string>("OrderTradeTypeCode"); |
|
|
|
|
|
|
|
var createOrderResponse = platformSDKBusinessList.FirstOrDefault(p => p.Platform == firstProductParam.PurchasePlatform) |
|
|
|
.FastCreateOrder(new CreateOnlinePurchaseOrderRequest() |
|
|
|
{ |
|
|
|
AppKey = purchaseAccount.AppKey, |
|
|
|
AppSecret = purchaseAccount.AppSecret, |
|
|
|
AppToken = purchaseAccount.AppToken, |
|
|
|
Platform = firstProductParam.PurchasePlatform, |
|
|
|
Consignee = request.Consignee, |
|
|
|
PurchaseOrderMode = request.PurchaseOrderMode, |
|
|
|
Remark = request.Remark, |
|
|
|
SourceShopName = request.ShopName, |
|
|
|
SourceSku = skuGroup.Key, |
|
|
|
CargoParamList = productParamList.Select(p => new CargoParamRequest() |
|
|
|
{ |
|
|
|
ProductId = p.PurchaseProductId, |
|
|
|
SkuId = p.PurchaseSkuId, |
|
|
|
Quantity = p.Quantity, |
|
|
|
SpecId = p.PurchaseSpecId |
|
|
|
}).ToList(), |
|
|
|
TradeMode = tradeMode, |
|
|
|
Extensions = cardId |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var purchaseOrderSimpleInfo = platformSDKBusinessList.FirstOrDefault(p => p.Platform == firstProductParam.PurchasePlatform).GetOrderSimpleInfo(new GetOrderInfoRequest() |
|
|
|
{ |
|
|
|
AppKey = purchaseAccount.AppKey, |
|
|
|
AppSecret = purchaseAccount.AppSecret, |
|
|
|
AppToken = purchaseAccount.AppToken, |
|
|
|
OrderId = createOrderResponse.PurchaseOrderId, |
|
|
|
Platform = firstProductParam.PurchasePlatform |
|
|
|
}); |
|
|
|
|
|
|
|
var purchaseOrderV2 = new PurchaseOrderV2() |
|
|
|
{ |
|
|
|
Id = createOrderResponse.PurchaseOrderId, |
|
|
|
ShopId = request.ShopId, |
|
|
|
OrderState = createOrderResponse.IsPay ? Enums.PurchaseOrderState.待发货 : Enums.PurchaseOrderState.待付款, |
|
|
|
PurchasePlatform = firstProductParam.PurchasePlatform, |
|
|
|
ConsigneeContactName = request.Consignee.ContactName, |
|
|
|
ConsigneeMobile = request.Consignee.Mobile, |
|
|
|
ConsigneeProvince = request.Consignee.Province, |
|
|
|
ConsigneeCity = request.Consignee.City, |
|
|
|
ConsigneeCounty = request.Consignee.County, |
|
|
|
ConsigneeTown = request.Consignee.Town, |
|
|
|
ConsigneeAddress = request.Consignee.Address, |
|
|
|
PurchaserId = firstProductParam.PurchaserId, |
|
|
|
PurchaserName = firstProductParam.PurchaserName, |
|
|
|
PurchaseAccountId = purchaseAccount.Id, |
|
|
|
PurchaseAmount = purchaseOrderSimpleInfo.TotalAmount, |
|
|
|
ProductAmount = purchaseOrderSimpleInfo.ProductAmount, |
|
|
|
PurchaseFreight = purchaseOrderSimpleInfo.FreightAmount, |
|
|
|
Remark = request.Remark, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
PurchaseMethod = Enums.PurchaseMethod.线上采购, |
|
|
|
PurchaseOrderMode = request.PurchaseOrderMode |
|
|
|
}; |
|
|
|
if (createOrderResponse.IsPay) |
|
|
|
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.Insert(purchaseOrderV2).ExecuteAffrows(); |
|
|
|
fsql.Insert(purchaseOrderSku).ExecuteAffrows(); |
|
|
|
}); |
|
|
|
successSkuIdList.Add(skuGroup.Key); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
//var errorBuilder = new StringBuilder();
|
|
|
|
//errorBuilder.AppendLine($"采购商:{productParamList.FirstOrDefault().PurchaserName}");
|
|
|
|
//errorBuilder.AppendLine($"店铺SkuId:{skuGroup.Key}");
|
|
|
|
//errorBuilder.AppendLine(ex.Message);
|
|
|
|
|
|
|
|
failSkuList.Add(new BatchCreareOrderFailDetail() |
|
|
|
{ |
|
|
|
SkuId = skuGroup.Key, |
|
|
|
ErrorMsg = ex.Message |
|
|
|
}); |
|
|
|
|
|
|
|
//throw new BusinessException(errorBuilder.ToString());
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new BatchCreareOrderResponse() |
|
|
|
{ |
|
|
|
FailSkuList = failSkuList, |
|
|
|
SuccessSkuIdList = successSkuIdList |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|