|
|
@ -1,8 +1,12 @@ |
|
|
|
using BBWY.Common.Models; |
|
|
|
using BBWY.Server.Model.Db; |
|
|
|
using BBWY.Server.Model.Dto; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using Yitter.IdGenerator; |
|
|
|
|
|
|
|
namespace BBWY.Server.Business |
|
|
@ -10,9 +14,16 @@ namespace BBWY.Server.Business |
|
|
|
public class BatchPurchaseBusiness : BaseBusiness, IDenpendency |
|
|
|
{ |
|
|
|
private ProductBusiness productBusiness; |
|
|
|
public BatchPurchaseBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator, ProductBusiness productBusiness) : base(fsql, nLogManager, idGenerator) |
|
|
|
private IEnumerable<PlatformSDKBusiness> platformSDKBusinessList; |
|
|
|
|
|
|
|
public BatchPurchaseBusiness(IFreeSql fsql, |
|
|
|
NLogManager nLogManager, |
|
|
|
IIdGenerator idGenerator, |
|
|
|
ProductBusiness productBusiness, |
|
|
|
IEnumerable<PlatformSDKBusiness> platformSDKBusinessList) : base(fsql, nLogManager, idGenerator) |
|
|
|
{ |
|
|
|
this.productBusiness = productBusiness; |
|
|
|
this.platformSDKBusinessList = platformSDKBusinessList; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -93,6 +104,81 @@ namespace BBWY.Server.Business |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
public PreviewOrderResponse PreviewOrderRequest(BatchPurchasePreviewOrderRequest request) |
|
|
|
{ |
|
|
|
/* |
|
|
|
记录报价日志 |
|
|
|
*/ |
|
|
|
|
|
|
|
if (request.ProductParamList == null || request.ProductParamList.Count() == 0) |
|
|
|
throw new BusinessException("缺少商品参数"); |
|
|
|
if (request.ConsigneeRequest == null || |
|
|
|
string.IsNullOrEmpty(request.ConsigneeRequest.Address) || |
|
|
|
string.IsNullOrEmpty(request.ConsigneeRequest.Mobile) || |
|
|
|
string.IsNullOrEmpty(request.ConsigneeRequest.ContactName)) |
|
|
|
throw new BusinessException("缺少收货人信息"); |
|
|
|
if (request.PurchaseAccountList == null || request.PurchaseAccountList.Count() == 0) |
|
|
|
throw new BusinessException("缺少采购账号"); |
|
|
|
|
|
|
|
var purchaserGroups = request.ProductParamList.GroupBy(p => p.PurchaserId); |
|
|
|
var carIds = new List<object>(); |
|
|
|
var errorBuilder = new StringBuilder(); |
|
|
|
var freightAmount = 0M; |
|
|
|
var productAmount = 0M; |
|
|
|
var totalAmount = 0M; |
|
|
|
|
|
|
|
|
|
|
|
foreach (var purchaserGroup in purchaserGroups) |
|
|
|
{ |
|
|
|
var productParamList = purchaserGroup.ToList(); |
|
|
|
try |
|
|
|
{ |
|
|
|
var purchasePlatform = productParamList.FirstOrDefault().PurchasePlatform; |
|
|
|
var purchaseAccount = request.PurchaseAccountList.FirstOrDefault(pa => pa.PurchasePlatformId == purchasePlatform); |
|
|
|
|
|
|
|
var platformSDKBusiness = platformSDKBusinessList.FirstOrDefault(p => p.Platform == purchasePlatform); |
|
|
|
var previewOrderResponse = platformSDKBusiness.PreviewOrder(new PreviewOrderReuqest() |
|
|
|
{ |
|
|
|
AppKey = purchaseAccount.AppKey, |
|
|
|
AppSecret = purchaseAccount.AppSecret, |
|
|
|
AppToken = purchaseAccount.AppToken, |
|
|
|
Consignee = request.ConsigneeRequest, |
|
|
|
Platform = purchasePlatform, |
|
|
|
PurchaseOrderMode = request.PurchaseOrderMode, |
|
|
|
CargoParamList = productParamList.Select(p => new CargoParamRequest() |
|
|
|
{ |
|
|
|
ProductId = p.PurchaseProductId, |
|
|
|
SkuId = p.PuchaseSkuId, |
|
|
|
Quantity = p.Quantity, |
|
|
|
SpecId = p.PurchaseSpecId |
|
|
|
}).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 }); |
|
|
|
|
|
|
|
freightAmount += previewOrderResponse.FreightAmount; |
|
|
|
productAmount += previewOrderResponse.ProductAmount; |
|
|
|
totalAmount += previewOrderResponse.TotalAmount; |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
errorBuilder.AppendLine($"采购商:{productParamList.FirstOrDefault().PurchaserName}"); |
|
|
|
errorBuilder.AppendLine($"店铺SkuId:{string.Join(",", productParamList.Select(p => p.BelongSkuId))}"); |
|
|
|
errorBuilder.AppendLine(ex.Message); |
|
|
|
throw new BusinessException(errorBuilder.ToString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new PreviewOrderResponse() |
|
|
|
{ |
|
|
|
Extensions = JsonConvert.SerializeObject(carIds), |
|
|
|
FreightAmount = freightAmount, |
|
|
|
ProductAmount = productAmount, |
|
|
|
TotalAmount = totalAmount |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|