From ee81e86839f0782f1f0dfab88f8c686c6f258606 Mon Sep 17 00:00:00 2001
From: shanj <18996038927@163.com>
Date: Mon, 5 Dec 2022 04:16:45 +0800
Subject: [PATCH] 1
---
.../BillCorrectionOrderResponse.cs | 2 +
.../BillCorrection/BillCorrectionOrder.cs | 2 +
.../BillCorrection/BillCorrectionViewModel.cs | 149 +++++++++++++++++-
.../BillCorrection/BillCorrectionView.xaml | 92 ++++++++++-
.../BillCorrection/BillCorrectionBusiness.cs | 75 ++++++++-
.../BillCorrection/BillCorrectionRequest.cs | 9 ++
.../BillCorrectionOrderResponse.cs | 2 +
7 files changed, 321 insertions(+), 10 deletions(-)
create mode 100644 BBWY.Server.Model/Dto/Request/BillCorrection/BillCorrectionRequest.cs
diff --git a/BBWY.Client/Models/APIModel/Response/BillCorrection/BillCorrectionOrderResponse.cs b/BBWY.Client/Models/APIModel/Response/BillCorrection/BillCorrectionOrderResponse.cs
index c17197cc..42cea562 100644
--- a/BBWY.Client/Models/APIModel/Response/BillCorrection/BillCorrectionOrderResponse.cs
+++ b/BBWY.Client/Models/APIModel/Response/BillCorrection/BillCorrectionOrderResponse.cs
@@ -9,6 +9,8 @@ namespace BBWY.Client.Models
///
public string OrderId { get; set; }
+ public long ShopId { get; set; }
+
///
/// 订单状态
///
diff --git a/BBWY.Client/Models/BillCorrection/BillCorrectionOrder.cs b/BBWY.Client/Models/BillCorrection/BillCorrectionOrder.cs
index ef9977a1..9b69e50d 100644
--- a/BBWY.Client/Models/BillCorrection/BillCorrectionOrder.cs
+++ b/BBWY.Client/Models/BillCorrection/BillCorrectionOrder.cs
@@ -13,6 +13,8 @@ namespace BBWY.Client.Models
///
public string OrderId { get; set; }
+ public long ShopId { get; set; }
+
///
/// 订单状态
///
diff --git a/BBWY.Client/ViewModels/BillCorrection/BillCorrectionViewModel.cs b/BBWY.Client/ViewModels/BillCorrection/BillCorrectionViewModel.cs
index 6ca1fdce..453073f0 100644
--- a/BBWY.Client/ViewModels/BillCorrection/BillCorrectionViewModel.cs
+++ b/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 ShopList { get; set; }
+ public IList LocalShopList { get; set; }
+
///
/// 店铺搜索关键词
///
@@ -73,21 +80,50 @@ namespace BBWY.Client.ViewModels
///
public ICommand SearchBillCorrectionOrderCommand { get; set; }
+ ///
+ /// 清空数据
+ ///
+ public ICommand ClearCommand { get; set; }
+
///
/// 矫正费用
///
public ICommand CorrectCommand { get; set; }
+ public ICommand SearchLocalCommand { get; set; }
+
+ public ICommand ClearLocalConditionCommand { get; set; }
+
+ ///
+ /// 保存
+ ///
+ public ICommand SaveCommand { get; set; }
+
public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } }
public IList OrderList { get; set; }
+ public IList LocalOrderList { get; set; }
+
+ public IList 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>(JsonConvert.SerializeObject(globalContext.User.ShopList));
this.ShopList = new ObservableCollection(shopList);
+ this.LocalShopList = new ObservableCollection();
SaleFreightBillFileList = new ObservableCollection();
SaleFreightBillList = new List();
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();
-
+ LocalOrderList = new ObservableCollection();
+ LocalFilterOperationList = new List()
+ {
+ new KVModel(){ Key="保留",Value="save" },
+ new KVModel(){ Key="过滤",Value="filter"}
+ };
ImportSaleFreightBillCommand = new RelayCommand(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
///
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);
+ }
+
///
/// 矫正费用
///
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;
+ }
+
}
}
diff --git a/BBWY.Client/Views/BillCorrection/BillCorrectionView.xaml b/BBWY.Client/Views/BillCorrection/BillCorrectionView.xaml
index 3234bf10..743a01ec 100644
--- a/BBWY.Client/Views/BillCorrection/BillCorrectionView.xaml
+++ b/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}">
@@ -28,6 +29,8 @@
+
+
@@ -149,20 +152,99 @@
-
-
+
+
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/BBWY.Server.Business/BillCorrection/BillCorrectionBusiness.cs b/BBWY.Server.Business/BillCorrection/BillCorrectionBusiness.cs
index b6fcce2f..965ba98f 100644
--- a/BBWY.Server.Business/BillCorrection/BillCorrectionBusiness.cs
+++ b/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()
- .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(sdOrderIds).ToList();
+
var afterOrderList = fsql.Select()
.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 requestList)
+ {
+ var orderIds = requestList.Select(r => r.OrderId).ToArray();
+
+ var orderList = fsql.Select(orderIds).ToList();
+ var orderCostList = fsql.Select(orderIds).ToList();
+ var orderCostDetailList = fsql.Select().Where(ocd => orderIds.Contains(ocd.OrderId) && ocd.IsEnabled == true).ToList();
+ var afterOrderList = fsql.Select().Where(aso => orderIds.Contains(aso.OrderId)).ToList();
+
+ IList> updateOrderCostList = new List>();
+ IList> updateOrderCostDetailList = new List>();
+
+ 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(ocd.Id)
+ .Set(dbOcd => dbOcd.DeliveryExpressFreight, ocd.DeliveryExpressFreight);
+ updateOrderCostDetailList.Add(updateOrderCostDetail);
+ }
+ }
+ else
+ {
+ orderCost.CalculationSDOrderProfitAndCost(order, afterOrderList);
+ }
+
+ var updateOrderCost = fsql.Update(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();
+ });
+ }
}
}
diff --git a/BBWY.Server.Model/Dto/Request/BillCorrection/BillCorrectionRequest.cs b/BBWY.Server.Model/Dto/Request/BillCorrection/BillCorrectionRequest.cs
new file mode 100644
index 00000000..d59ee5e1
--- /dev/null
+++ b/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; }
+ }
+}
diff --git a/BBWY.Server.Model/Dto/Response/BillCorrection/BillCorrectionOrderResponse.cs b/BBWY.Server.Model/Dto/Response/BillCorrection/BillCorrectionOrderResponse.cs
index 19e1794f..2cdae37c 100644
--- a/BBWY.Server.Model/Dto/Response/BillCorrection/BillCorrectionOrderResponse.cs
+++ b/BBWY.Server.Model/Dto/Response/BillCorrection/BillCorrectionOrderResponse.cs
@@ -9,6 +9,8 @@ namespace BBWY.Server.Model.Dto
///
public string OrderId { get; set; }
+ public long ShopId { get; set; }
+
///
/// 订单状态
///