shanji 3 years ago
parent
commit
ee81e86839
  1. 2
      BBWY.Client/Models/APIModel/Response/BillCorrection/BillCorrectionOrderResponse.cs
  2. 2
      BBWY.Client/Models/BillCorrection/BillCorrectionOrder.cs
  3. 149
      BBWY.Client/ViewModels/BillCorrection/BillCorrectionViewModel.cs
  4. 92
      BBWY.Client/Views/BillCorrection/BillCorrectionView.xaml
  5. 75
      BBWY.Server.Business/BillCorrection/BillCorrectionBusiness.cs
  6. 9
      BBWY.Server.Model/Dto/Request/BillCorrection/BillCorrectionRequest.cs
  7. 2
      BBWY.Server.Model/Dto/Response/BillCorrection/BillCorrectionOrderResponse.cs

2
BBWY.Client/Models/APIModel/Response/BillCorrection/BillCorrectionOrderResponse.cs

@ -9,6 +9,8 @@ namespace BBWY.Client.Models
/// </summary>
public string OrderId { get; set; }
public long ShopId { get; set; }
/// <summary>
/// 订单状态
/// </summary>

2
BBWY.Client/Models/BillCorrection/BillCorrectionOrder.cs

@ -13,6 +13,8 @@ namespace BBWY.Client.Models
/// </summary>
public string OrderId { get; set; }
public long ShopId { get; set; }
/// <summary>
/// 订单状态
/// </summary>

149
BBWY.Client/ViewModels/BillCorrection/BillCorrectionViewModel.cs

@ -27,6 +27,11 @@ namespace BBWY.Client.ViewModels
private string searchShopKeyWord;
private DelayTrigger delayTrigger;
private bool isLoading;
private KVModel selectedLocalFilterOperation;
private bool isEnableCanCorrectionOrder;
private StorageType? selectedStorageType;
private string searchLocalOrderId;
private Shop selectedLocalShop;
private GlobalContext globalContext;
@ -48,6 +53,8 @@ namespace BBWY.Client.ViewModels
public IList<Shop> ShopList { get; set; }
public IList<Shop> LocalShopList { get; set; }
/// <summary>
/// 店铺搜索关键词
/// </summary>
@ -73,21 +80,50 @@ namespace BBWY.Client.ViewModels
/// </summary>
public ICommand SearchBillCorrectionOrderCommand { get; set; }
/// <summary>
/// 清空数据
/// </summary>
public ICommand ClearCommand { get; set; }
/// <summary>
/// 矫正费用
/// </summary>
public ICommand CorrectCommand { get; set; }
public ICommand SearchLocalCommand { get; set; }
public ICommand ClearLocalConditionCommand { get; set; }
/// <summary>
/// 保存
/// </summary>
public ICommand SaveCommand { get; set; }
public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } }
public IList<BillCorrectionOrder> OrderList { get; set; }
public IList<BillCorrectionOrder> LocalOrderList { get; set; }
public IList<KVModel> LocalFilterOperationList { get; set; }
public KVModel SelectedLocalFilterOperation { get => selectedLocalFilterOperation; set { Set(ref selectedLocalFilterOperation, value); } }
public bool IsEnableCanCorrectionOrder { get => isEnableCanCorrectionOrder; set { Set(ref isEnableCanCorrectionOrder, value); } }
public StorageType? SelectedStorageType { get => selectedStorageType; set { Set(ref selectedStorageType, value); } }
public string SearchLocalOrderId { get => searchLocalOrderId; set { Set(ref searchLocalOrderId, value); } }
public Shop SelectedLocalShop { get => selectedLocalShop; set { Set(ref selectedLocalShop, value); } }
public BillCorrectionViewModel(GlobalContext globalContext, BillCorrectionService billCorrectionService)
{
this.billCorrectionService = billCorrectionService;
this.globalContext = globalContext;
var shopList = JsonConvert.DeserializeObject<List<Shop>>(JsonConvert.SerializeObject(globalContext.User.ShopList));
this.ShopList = new ObservableCollection<Shop>(shopList);
this.LocalShopList = new ObservableCollection<Shop>();
SaleFreightBillFileList = new ObservableCollection<string>();
SaleFreightBillList = new List<BillModel>();
StartDate = DateTime.Now.Date.AddDays((DateTime.Now.Day - 1) * -1).AddMonths(-1);
@ -95,10 +131,20 @@ namespace BBWY.Client.ViewModels
delayTrigger = new DelayTrigger(500);
delayTrigger.OnExecute = OnSearchShopKeyWordChanged;
OrderList = new ObservableCollection<BillCorrectionOrder>();
LocalOrderList = new ObservableCollection<BillCorrectionOrder>();
LocalFilterOperationList = new List<KVModel>()
{
new KVModel(){ Key="保留",Value="save" },
new KVModel(){ Key="过滤",Value="filter"}
};
ImportSaleFreightBillCommand = new RelayCommand<string>(ImportSaleFreightBill);
SearchBillCorrectionOrderCommand = new RelayCommand(SearchBillCorrectionOrder);
CorrectCommand = new RelayCommand(Correct);
ClearCommand = new RelayCommand(Clear);
SearchLocalCommand = new RelayCommand(SearchLocalOrderList);
ClearLocalConditionCommand = new RelayCommand(ClearLocalCondition);
SaveCommand = new RelayCommand(Save);
SelectedLocalFilterOperation = LocalFilterOperationList[0];
}
private void OnSearchShopKeyWordChanged(string key)
@ -302,9 +348,19 @@ namespace BBWY.Client.ViewModels
/// </summary>
private void SearchBillCorrectionOrder()
{
IsLoading = true;
OrderList.Clear();
var shopIds = ShopList.Where(s => s.IsSelected).Select(s => s.ShopId).ToList();
LocalShopList.Clear();
var selectShops = ShopList.Where(s => s.IsSelected).ToList();
if (selectShops.Count() == 0)
{
MessageBox.Show("至少选择一个店铺", "提示");
return;
}
IsLoading = true;
foreach (var shop in LocalShopList)
LocalShopList.Add(shop);
SelectedLocalShop = null;
var shopIds = selectShops.Select(s => s.ShopId).ToList();
Task.Factory.StartNew(() => billCorrectionService.GetBillCorrectionOrderList(shopIds, StartDate, EndDate))
.ContinueWith(t =>
{
@ -337,15 +393,102 @@ namespace BBWY.Client.ViewModels
//}
OrderList.Add(order);
}
SearchLocalOrderList();
});
});
}
private void SearchLocalOrderList()
{
LocalOrderList.Clear();
var where = OrderList.Where(o => true);
if (SelectedLocalShop != null)
where = where.Where(o => o.ShopId == SelectedLocalShop.ShopId);
if (SelectedStorageType != null)
where = where.Where(o => o.StorageType == SelectedStorageType);
if (!string.IsNullOrEmpty(SearchLocalOrderId))
where = where.Where(o => o.OrderId == SearchLocalOrderId);
if (IsEnableCanCorrectionOrder)
{
if (SelectedLocalFilterOperation.Value == "save")
where = where.Where(o => !string.IsNullOrEmpty(o.ChangedContent));
else
where = where.Where(o => string.IsNullOrEmpty(o.ChangedContent));
}
var list = where.ToList();
foreach (var o in list)
LocalOrderList.Add(o);
}
/// <summary>
/// 矫正费用
/// </summary>
private void Correct()
{
if (OrderList.Count() == 0)
{
MessageBox.Show("缺少待矫正订单");
return;
}
if (SaleFreightBillList.Count() == 0)
{
MessageBox.Show("缺少运费账单");
return;
}
foreach (var order in OrderList)
{
//矫正销售运费
if (!string.IsNullOrEmpty(order.WaybillNo))
{
var expressBillModel = SaleFreightBillList.FirstOrDefault(b => b.BillNo == order.WaybillNo);
if (expressBillModel != null && expressBillModel.Amount != order.DeliveryExpressFreight)
{
order.NewDeliveryExpressFreight = expressBillModel.Amount;
order.ChangedContent = $"销售运费{order.DeliveryExpressFreight}->{order.NewDeliveryExpressFreight} ";
}
}
//矫正入仓操作
//矫正出仓操作
}
}
private void Clear()
{
SaleFreightBillFileList.Clear();
SaleFreightBillList.Clear();
OrderList.Clear();
LocalOrderList.Clear();
SelectedStorageType = null;
IsEnableCanCorrectionOrder = false;
SearchShopKeyWord = string.Empty;
SearchLocalOrderId = string.Empty;
SelectedLocalShop = null;
SelectedLocalFilterOperation = LocalFilterOperationList[0];
}
private void ClearLocalCondition()
{
SelectedStorageType = null;
IsEnableCanCorrectionOrder = false;
SearchLocalOrderId = string.Empty;
SelectedLocalShop = null;
SearchLocalOrderList();
}
private void Save()
{
var saveOrderList = OrderList.Where(o => !string.IsNullOrEmpty(o.ChangedContent));
if (saveOrderList.Count() == 0)
{
MessageBox.Show("没有需要矫正的订单", "提示");
return;
}
}
}

92
BBWY.Client/Views/BillCorrection/BillCorrectionView.xaml

@ -10,7 +10,8 @@
xmlns:hc="https://handyorg.github.io/handycontrol"
DataContext="{Binding BillCorrection,Source={StaticResource Locator}}"
d:DesignHeight="1080" d:DesignWidth="1920"
Title="BillCorrectionView">
Title="BillCorrectionView"
Foreground="{StaticResource Text.Color}">
<Page.Resources>
<ObjectDataProvider x:Key="storageTypeProvider" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
@ -28,6 +29,8 @@
<RowDefinition Height="5"/>
<RowDefinition Height="40"/>
<RowDefinition Height="5"/>
<RowDefinition Height="40"/>
<RowDefinition Height="5"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Background="{StaticResource Border.Background}" Padding="5,0">
@ -149,20 +152,99 @@
<Border Background="{StaticResource Border.Background}" Padding="5,0" Grid.Row="4">
<Grid>
<StackPanel Orientation="Horizontal">
<TextBlock Text="发货类型" VerticalAlignment="Center"/>
<ComboBox Margin="5,0,0,0" ItemsSource="{Binding Source={StaticResource storageTypeProvider}}"
<TextBlock Text="店铺名称" VerticalAlignment="Center"/>
<ComboBox Margin="5,0,0,0"
DisplayMemberPath="ShopName"
ItemsSource="{Binding LocalShopList}"
SelectedItem="{Binding SelectedLocalShop,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Height="25" VerticalContentAlignment="Center"/>
<TextBlock Text="发货类型" VerticalAlignment="Center" Margin="5,0,0,0"/>
<ComboBox Margin="5,0,0,0"
ItemsSource="{Binding Source={StaticResource storageTypeProvider}}"
SelectedItem="{Binding SelectedStorageType,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Height="25" VerticalContentAlignment="Center"/>
<TextBlock Text="订单号" VerticalAlignment="Center" Margin="5,0,0,0"/>
<c:BTextBox Width="150" Height="25" Margin="5,0,0,0"/>
<c:BTextBox Width="150" Height="25" Margin="5,0,0,0"
Text="{Binding SearchLocalOrderId,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<c:BButton Content="结果搜索" Padding="10,0" Command="{Binding SearchLocalCommand}"/>
<c:BButton Content="清空条件" Padding="10,0" Command="{Binding ClearLocalConditionCommand}" Background="{StaticResource Text.Pink}"/>
<c:BButton Content="导出Excel" Padding="10,0" Background="#02A7F0" Command="{Binding ExportCommand}"/>
<c:BButton Content="导出Excel" Padding="10,0" Background="#02A7F0" Command="{Binding ExportCommand}" Visibility="Collapsed"/>
<c:BButton Content="保存" Padding="10,0" Background="#1CC2A2" Command="{Binding SaveCommand}"/>
</StackPanel>
</Grid>
</Border>
<StackPanel Orientation="Horizontal" Grid.Row="6">
<TextBlock Text="筛选" VerticalAlignment="Center" Margin="5,0,0,0"/>
<ComboBox ItemsSource="{Binding LocalFilterOperationList}"
SelectedItem="{Binding SelectedLocalFilterOperation,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Height="25" Margin="5,0,0,0"
VerticalContentAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Key}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<CheckBox Content="可矫正订单" Margin="5,0,0,0" IsChecked="{Binding IsEnableCanCorrectionOrder}"/>
</StackPanel>
<DataGrid Grid.Row="8"
ItemsSource="{Binding LocalOrderList}"
BorderThickness="1,1,0,0"
BorderBrush="{StaticResource Border.Brush}"
VirtualizingPanel.IsVirtualizing="True"
Foreground="{StaticResource Text.Color}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding StartTime,StringFormat=yyyy-MM-dd HH:mm:ss}" Header="下单时间" Width="130"
ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<!--<DataGridTextColumn Binding="{Binding OrderId}" Header="订单号" Width="100"
ElementStyle="{StaticResource verticalCenterTextBlock}"/>-->
<DataGridTemplateColumn Width="100" Header="订单号">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding OrderId}" VerticalAlignment="Center"
BorderThickness="0"
Background="Transparent"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding StorageType}" Header="发货类型" Width="60"
ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Binding="{Binding SkuAmount}" Header="采购货款" Width="60"
ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Binding="{Binding PurchaseFreight}" Header="采购运费" Width="60"
ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Binding="{Binding FirstFreight}" Header="头程运费" Width="60"
ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Binding="{Binding StorageAmount}" Header="仓储费" Width="60"
ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Binding="{Binding ConsumableAmount}" Header="耗才费" Width="60"
ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Binding="{Binding InStorageAmount}" Header="入仓操作费" Width="70"
ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Binding="{Binding OutStorageAmount}" Header="出仓操作费" Width="70"
ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Binding="{Binding DeliveryExpressFreight}" Header="销售运费" Width="60"
ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Binding="{Binding AfterTotalCost}" Header="售后费用" Width="60"
ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTemplateColumn Header="订单状态" Width="60">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding OrderState}"
Foreground="{Binding OrderState,ConverterParameter=已取消:Red:Gray,Converter={StaticResource objConverter}}"
VerticalAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding ChangedContent}" Header="矫正内容" Width="*"
ElementStyle="{StaticResource verticalCenterTextBlock}"
Foreground="Green"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Grid>
</Page>

75
BBWY.Server.Business/BillCorrection/BillCorrectionBusiness.cs

@ -4,6 +4,8 @@ using BBWY.Server.Model.Dto;
using System.Collections.Generic;
using Yitter.IdGenerator;
using System.Linq;
using FreeSql;
using BBWY.Server.Business.Extensions;
namespace BBWY.Server.Business
{
@ -26,13 +28,15 @@ namespace BBWY.Server.Business
StartTime = o.StartTime,
StorageType = o.StorageType,
OrderState = o.OrderState,
WaybillNo = o.WaybillNo
WaybillNo = o.WaybillNo,
ShopId = o.ShopId
});
var orderIds = orderList.Select(o => o.OrderId).ToList();
var sdOrderIds = orderList.Where(o => o.StorageType == Model.Enums.StorageType.SD).Select(o => o.OrderId).ToArray();
var orderCostDetailList = fsql.Select<OrderCostDetail>()
.Where(ocd => orderIds.Contains(ocd.OrderId))
.Where(ocd => orderIds.Contains(ocd.OrderId) && ocd.IsEnabled == true)
.GroupBy(ocd => ocd.OrderId)
.ToList(g => new
{
@ -47,6 +51,8 @@ namespace BBWY.Server.Business
StorageAmount = g.Sum(g.Value.StorageAmount)
});
var sdOrderCostList = fsql.Select<OrderCost>(sdOrderIds).ToList();
var afterOrderList = fsql.Select<AfterSaleOrder>()
.Where(aso => orderIds.Contains(aso.OrderId))
.GroupBy(aso => aso.OrderId)
@ -70,8 +76,73 @@ namespace BBWY.Server.Business
order.ConsumableAmount = orderCostDetail?.ConsumableAmount ?? 0M;
order.StorageAmount = orderCostDetail?.StorageAmount ?? 0M;
order.AfterTotalCost = afterOrder?.AfterTotalCost ?? 0M;
if (order.StorageType == Model.Enums.StorageType.SD)
{
var sdOrderCost = sdOrderCostList.FirstOrDefault(oc => oc.OrderId == order.OrderId);
order.DeliveryExpressFreight = sdOrderCost?.DeliveryExpressFreight ?? 0M;
}
}
return orderList;
}
public void CorrectOrder(IList<BillCorrectionRequest> requestList)
{
var orderIds = requestList.Select(r => r.OrderId).ToArray();
var orderList = fsql.Select<Order>(orderIds).ToList();
var orderCostList = fsql.Select<OrderCost>(orderIds).ToList();
var orderCostDetailList = fsql.Select<OrderCostDetail>().Where(ocd => orderIds.Contains(ocd.OrderId) && ocd.IsEnabled == true).ToList();
var afterOrderList = fsql.Select<AfterSaleOrder>().Where(aso => orderIds.Contains(aso.OrderId)).ToList();
IList<IUpdate<OrderCost>> updateOrderCostList = new List<IUpdate<OrderCost>>();
IList<IUpdate<OrderCostDetail>> updateOrderCostDetailList = new List<IUpdate<OrderCostDetail>>();
foreach (var billCorrectionRequest in requestList)
{
var order = orderList.FirstOrDefault(o => o.Id == billCorrectionRequest.OrderId);
if (order == null)
continue;
var orderCost = orderCostList.FirstOrDefault(oc => oc.OrderId == billCorrectionRequest.OrderId);
if (orderCost == null)
continue;
var currentOrderCostDetailList = orderCostDetailList.Where(ocd => ocd.OrderId == billCorrectionRequest.OrderId).ToList();
if (currentOrderCostDetailList.Count() == 0 && order.StorageType != Model.Enums.StorageType.SD)
continue;
var currentOrderAfterOrderList = afterOrderList.Where(aso => aso.OrderId == billCorrectionRequest.OrderId).ToList();
orderCost.DeliveryExpressFreight = billCorrectionRequest.NewDeliveryExpressFreight;
if (order.StorageType != Model.Enums.StorageType.SD)
{
orderCost.CalculationOrderProfitAndCost(order, currentOrderAfterOrderList);
var singleDeliveryExpressFreight = billCorrectionRequest.NewDeliveryExpressFreight / currentOrderCostDetailList.Count();
foreach (var ocd in currentOrderCostDetailList)
{
ocd.DeliveryExpressFreight = singleDeliveryExpressFreight;
var updateOrderCostDetail = fsql.Update<OrderCostDetail>(ocd.Id)
.Set(dbOcd => dbOcd.DeliveryExpressFreight, ocd.DeliveryExpressFreight);
updateOrderCostDetailList.Add(updateOrderCostDetail);
}
}
else
{
orderCost.CalculationSDOrderProfitAndCost(order, afterOrderList);
}
var updateOrderCost = fsql.Update<OrderCost>(orderCost.OrderId).Set(oc => oc.DeliveryExpressFreight, orderCost.DeliveryExpressFreight)
.Set(oc => oc.Profit, orderCost.Profit);
updateOrderCostList.Add(updateOrderCost);
}
fsql.Transaction(() =>
{
foreach (var update in updateOrderCostList)
update.ExecuteAffrows();
foreach (var update in updateOrderCostDetailList)
update.ExecuteAffrows();
});
}
}
}

9
BBWY.Server.Model/Dto/Request/BillCorrection/BillCorrectionRequest.cs

@ -0,0 +1,9 @@
namespace BBWY.Server.Model.Dto
{
public class BillCorrectionRequest
{
public string OrderId { get; set; }
public decimal NewDeliveryExpressFreight { get; set; }
}
}

2
BBWY.Server.Model/Dto/Response/BillCorrection/BillCorrectionOrderResponse.cs

@ -9,6 +9,8 @@ namespace BBWY.Server.Model.Dto
/// </summary>
public string OrderId { get; set; }
public long ShopId { get; set; }
/// <summary>
/// 订单状态
/// </summary>

Loading…
Cancel
Save