shanji 2 years ago
parent
commit
b73e638527
  1. 12
      BBWY.Client/Views/BatchPurchase/BatchCreateNewPurchaseOrder.xaml
  2. 4
      BBWY.Client/Views/BatchPurchase/BatchPurchaseAddProductSku.xaml
  3. 13
      BBWY.Server.API/Controllers/BatchPurchaseController.cs
  4. 88
      BBWY.Server.Business/PurchaseOrderV2/BatchPurchase/BatchPurchaseBusiness.cs
  5. 28
      BBWY.Server.Model/Dto/Request/PurchaseOrderV2/BatchPurchase/BatchPurchasePreviewOrderRequest.cs

12
BBWY.Client/Views/BatchPurchase/BatchCreateNewPurchaseOrder.xaml

@ -51,8 +51,8 @@
<ColumnDefinition Width="80"/> <ColumnDefinition Width="80"/>
<ColumnDefinition Width="90"/> <ColumnDefinition Width="90"/>
<ColumnDefinition Width="70"/> <ColumnDefinition Width="70"/>
<ColumnDefinition Width="80"/> <ColumnDefinition Width="60"/>
<ColumnDefinition Width="80"/> <ColumnDefinition Width="60"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Text="店铺商品信息" Style="{StaticResource middleTextBlock}"/> <TextBlock Text="店铺商品信息" Style="{StaticResource middleTextBlock}"/>
<TextBlock Text="采购商品信息" Style="{StaticResource middleTextBlock}" Grid.Column="1"/> <TextBlock Text="采购商品信息" Style="{StaticResource middleTextBlock}" Grid.Column="1"/>
@ -94,7 +94,7 @@
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/> <ColumnDefinition Width="300"/>
<ColumnDefinition Width="1*"/> <ColumnDefinition Width="1*"/>
<ColumnDefinition Width="80"/> <ColumnDefinition Width="60"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@ -153,7 +153,7 @@
<ColumnDefinition Width="80"/> <ColumnDefinition Width="80"/>
<ColumnDefinition Width="90"/> <ColumnDefinition Width="90"/>
<ColumnDefinition Width="70"/> <ColumnDefinition Width="70"/>
<ColumnDefinition Width="80"/> <ColumnDefinition Width="60"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid> <Grid>
@ -231,8 +231,8 @@
Height="18" Height="18"
Command="{Binding DataContext.SubtractQuantityCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}" Command="{Binding DataContext.SubtractQuantityCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}"
CommandParameter="{Binding }"/> CommandParameter="{Binding }"/>
<c:BTextBox Text="{Binding ItemTotal}" Margin="5,0" VerticalAlignment="Center" <c:BTextBox Text="{Binding ItemTotal,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Margin="5,0" VerticalAlignment="Center"
Width="40" Width="40" HorizontalContentAlignment="Center" Padding="0,0,3,0"
DisableBgColor="{StaticResource TextBox.Disable.BgColor}"/> DisableBgColor="{StaticResource TextBox.Disable.BgColor}"/>
<c:BButton Content="+" Background="White" Foreground="Black" <c:BButton Content="+" Background="White" Foreground="Black"
BorderBrush="{StaticResource Border.Brush}" BorderBrush="{StaticResource Border.Brush}"

4
BBWY.Client/Views/BatchPurchase/BatchPurchaseAddProductSku.xaml

@ -153,8 +153,8 @@
Height="18" Height="18"
Command="{Binding DataContext.SubtractQuantityCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}}" Command="{Binding DataContext.SubtractQuantityCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}}"
CommandParameter="{Binding }"/> CommandParameter="{Binding }"/>
<c:BTextBox Text="{Binding Quantity}" Margin="5,0" VerticalAlignment="Center" <c:BTextBox Text="{Binding Quantity,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Margin="5,0" VerticalAlignment="Center"
Width="40" Width="40" HorizontalContentAlignment="Center" Padding="0,0,3,0"
DisableBgColor="{StaticResource TextBox.Disable.BgColor}"/> DisableBgColor="{StaticResource TextBox.Disable.BgColor}"/>
<c:BButton Content="+" Background="White" Foreground="Black" <c:BButton Content="+" Background="White" Foreground="Black"
BorderBrush="{StaticResource Border.Brush}" BorderBrush="{StaticResource Border.Brush}"

13
BBWY.Server.API/Controllers/BatchPurchaseController.cs

@ -21,9 +21,20 @@ namespace BBWY.Server.API.Controllers
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public IList<ProductSkuWithSchemeResponse> GetProductSkuAndSchemeList([FromBody]SearchProductSkuAndSchemeRequest request) public IList<ProductSkuWithSchemeResponse> GetProductSkuAndSchemeList([FromBody] SearchProductSkuAndSchemeRequest request)
{ {
return batchPurchaseBusiness.GetProductSkuAndSchemeList(request); return batchPurchaseBusiness.GetProductSkuAndSchemeList(request);
} }
/// <summary>
/// 预览订单价格
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost]
public PreviewOrderResponse PreviewOrderRequest([FromBody] BatchPurchasePreviewOrderRequest request)
{
return batchPurchaseBusiness.PreviewOrderRequest(request);
}
} }
} }

88
BBWY.Server.Business/PurchaseOrderV2/BatchPurchase/BatchPurchaseBusiness.cs

@ -1,8 +1,12 @@
using BBWY.Common.Models; using BBWY.Common.Models;
using BBWY.Server.Model.Db; using BBWY.Server.Model.Db;
using BBWY.Server.Model.Dto; using BBWY.Server.Model.Dto;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using Yitter.IdGenerator; using Yitter.IdGenerator;
namespace BBWY.Server.Business namespace BBWY.Server.Business
@ -10,9 +14,16 @@ namespace BBWY.Server.Business
public class BatchPurchaseBusiness : BaseBusiness, IDenpendency public class BatchPurchaseBusiness : BaseBusiness, IDenpendency
{ {
private ProductBusiness productBusiness; 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.productBusiness = productBusiness;
this.platformSDKBusinessList = platformSDKBusinessList;
} }
/// <summary> /// <summary>
@ -93,6 +104,81 @@ namespace BBWY.Server.Business
return list; 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
};
}
} }
} }

28
BBWY.Server.Model/Dto/Request/PurchaseOrderV2/BatchPurchase/BatchPurchasePreviewOrderRequest.cs

@ -0,0 +1,28 @@
using BBWY.Server.Model.Db;
using System.Collections.Generic;
namespace BBWY.Server.Model.Dto
{
public class BatchPurchasePreviewOrderRequest
{
public Enums.PurchaseOrderMode PurchaseOrderMode { get; set; }
public IList<PurchaseAccount> PurchaseAccountList { get; set; }
public ConsigneeRequest ConsigneeRequest { get; set; }
public IList<BatchPurchasePreviewOrderProductParamRequest> ProductParamList { get; set; }
}
public class BatchPurchasePreviewOrderProductParamRequest
{
public string PurchaseProductId { get; set; }
public string PuchaseSkuId { get; set; }
public string PurchaseSpecId { get; set; }
public int Quantity { get; set; }
public string PurchaserId { get; set; }
public string PurchaserName { get; set; }
public Enums.Platform PurchasePlatform { get; set; }
public string BelongSkuId { get; set; }
}
}
Loading…
Cancel
Save