diff --git a/BBWY.Client/APIServices/BillCorrectionService.cs b/BBWY.Client/APIServices/BillCorrectionService.cs new file mode 100644 index 00000000..bed8f61d --- /dev/null +++ b/BBWY.Client/APIServices/BillCorrectionService.cs @@ -0,0 +1,26 @@ +using BBWY.Client.Models; +using BBWY.Common.Http; +using BBWY.Common.Models; +using System; +using System.Collections.Generic; +using System.Net.Http; + +namespace BBWY.Client.APIServices +{ + public class BillCorrectionService : BaseApiService, IDenpendency + { + public BillCorrectionService(RestApiService restApiService, GlobalContext globalContext) : base(restApiService, globalContext) + { + } + + public ApiResponse> GetBillCorrectionOrderList(IList shopIds, DateTime startTime, DateTime endTime) + { + return SendRequest>(globalContext.BBYWApiHost, "api/billCorrection/GetBillCorrectionOrderList", new + { + shopIds, + startTime, + endTime + }, null, HttpMethod.Post); + } + } +} diff --git a/BBWY.Client/Models/APIModel/Response/BillCorrection/BillCorrectionOrderResponse.cs b/BBWY.Client/Models/APIModel/Response/BillCorrection/BillCorrectionOrderResponse.cs new file mode 100644 index 00000000..c17197cc --- /dev/null +++ b/BBWY.Client/Models/APIModel/Response/BillCorrection/BillCorrectionOrderResponse.cs @@ -0,0 +1,74 @@ +using System; + +namespace BBWY.Client.Models +{ + public class BillCorrectionOrderResponse + { + /// + /// 订单号 + /// + public string OrderId { get; set; } + + /// + /// 订单状态 + /// + public OrderState? OrderState { get; set; } + + /// + /// 订单开始日期 + /// + public DateTime? StartTime { get; set; } + + /// + /// 发货类型 + /// + public StorageType? StorageType { get; set; } + + /// + /// 销售运费 + /// + public decimal DeliveryExpressFreight { get; set; } = 0.00M; + + /// + /// Sku成本(商品成本) + /// + public decimal SkuAmount { get; set; } = 0.00M; + + /// + /// 采购运费 + /// + public decimal PurchaseFreight { get; set; } = 0.00M; + + /// + /// 头程运费 + /// + public decimal FirstFreight { get; set; } = 0.00M; + + /// + /// 入仓操作费 + /// + public decimal InStorageAmount { get; set; } = 0.00M; + + /// + /// 出仓操作费 + /// + public decimal OutStorageAmount { get; set; } = 0.00M; + + /// + /// 耗材费 + /// + public decimal ConsumableAmount { get; set; } = 0.00M; + + /// + /// 仓储费 + /// + public decimal StorageAmount { get; set; } = 0.00M; + + /// + /// 售后费用 + /// + public decimal AfterTotalCost { get; set; } + + public string WaybillNo { get; set; } + } +} diff --git a/BBWY.Client/Models/BillCorrection/BillCorrectionOrder.cs b/BBWY.Client/Models/BillCorrection/BillCorrectionOrder.cs new file mode 100644 index 00000000..ef9977a1 --- /dev/null +++ b/BBWY.Client/Models/BillCorrection/BillCorrectionOrder.cs @@ -0,0 +1,88 @@ +using System; + +namespace BBWY.Client.Models +{ + public class BillCorrectionOrder : NotifyObject + { + private string changedContent; + + private decimal newDeliveryExpressFreight; + + /// + /// 订单号 + /// + public string OrderId { get; set; } + + /// + /// 订单状态 + /// + public OrderState? OrderState { get; set; } + + /// + /// 订单开始日期 + /// + public DateTime? StartTime { get; set; } + + /// + /// 发货类型 + /// + public StorageType? StorageType { get; set; } + + /// + /// 销售运费 + /// + public decimal DeliveryExpressFreight { get; set; } = 0.00M; + + /// + /// Sku成本(商品成本) + /// + public decimal SkuAmount { get; set; } = 0.00M; + + /// + /// 采购运费 + /// + public decimal PurchaseFreight { get; set; } = 0.00M; + + /// + /// 头程运费 + /// + public decimal FirstFreight { get; set; } = 0.00M; + + /// + /// 入仓操作费 + /// + public decimal InStorageAmount { get; set; } = 0.00M; + + /// + /// 出仓操作费 + /// + public decimal OutStorageAmount { get; set; } = 0.00M; + + /// + /// 耗材费 + /// + public decimal ConsumableAmount { get; set; } = 0.00M; + + /// + /// 仓储费 + /// + public decimal StorageAmount { get; set; } = 0.00M; + + /// + /// 售后费用 + /// + public decimal AfterTotalCost { get; set; } + + /// + /// 矫正内容 + /// + public string ChangedContent { get => changedContent; set { Set(ref changedContent, value); } } + + /// + /// 新销售运费 + /// + public decimal NewDeliveryExpressFreight { get => newDeliveryExpressFreight; set { Set(ref newDeliveryExpressFreight, value); } } + + public string WaybillNo { get; set; } + } +} diff --git a/BBWY.Client/Models/MappingProfile.cs b/BBWY.Client/Models/MappingProfile.cs index 7ddf4128..865a7a5d 100644 --- a/BBWY.Client/Models/MappingProfile.cs +++ b/BBWY.Client/Models/MappingProfile.cs @@ -29,6 +29,7 @@ namespace BBWY.Client.Models CreateMap(); CreateMap(); CreateMap(); + CreateMap(); } } } diff --git a/BBWY.Client/ViewModels/BillCoreection/BillCorrectionViewModel.cs b/BBWY.Client/ViewModels/BillCorrection/BillCorrectionViewModel.cs similarity index 69% rename from BBWY.Client/ViewModels/BillCoreection/BillCorrectionViewModel.cs rename to BBWY.Client/ViewModels/BillCorrection/BillCorrectionViewModel.cs index 1e1aefa8..4f67a08e 100644 --- a/BBWY.Client/ViewModels/BillCoreection/BillCorrectionViewModel.cs +++ b/BBWY.Client/ViewModels/BillCorrection/BillCorrectionViewModel.cs @@ -1,8 +1,11 @@ -using BBWY.Client.Models; +using BBWY.Client.APIServices; +using BBWY.Client.Models; using BBWY.Client.Views.BillCorrection; using BBWY.Common.Models; +using BBWY.Common.Trigger; using GalaSoft.MvvmLight.Command; using Microsoft.Win32; +using Newtonsoft.Json; using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; @@ -11,17 +14,21 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; +using System.Threading.Tasks; using System.Windows; using System.Windows.Input; +using BBWY.Common.Extensions; namespace BBWY.Client.ViewModels { public class BillCorrectionViewModel : BaseVM, IDenpendency { - private bool isShowShopKeyword; + private BillCorrectionService billCorrectionService; private string searchShopKeyWord; + private DelayTrigger delayTrigger; + private bool isLoading; - public GlobalContext GlobalContext { get; set; } + private GlobalContext globalContext; public DateTime StartDate { get; set; } @@ -37,31 +44,72 @@ namespace BBWY.Client.ViewModels /// public List SaleFreightBillList { get; set; } + + + public IList ShopList { get; set; } + /// - /// 导入快递账单 + /// 店铺搜索关键词 /// - public ICommand ImportSaleFreightBillCommand { get; set; } + public string SearchShopKeyWord + { + get => searchShopKeyWord; + set + { + if (Set(ref searchShopKeyWord, value)) + { + delayTrigger.SetKey(value); + } + } + } /// - /// 是否显示店铺搜索关键词 + /// 导入快递账单 /// - public bool IsShowShopKeyword { get => isShowShopKeyword; set { Set(ref isShowShopKeyword, value); } } - - public IList ShopList { get; set; } + public ICommand ImportSaleFreightBillCommand { get; set; } /// - /// 店铺搜索关键词 + /// 查询订单 /// - public string SearchShopKeyWord { get => searchShopKeyWord; set { Set(ref searchShopKeyWord, value); } } + public ICommand SearchBillCorrectionOrderCommand { get; set; } + public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } } + + public IList OrderList { get; set; } - public BillCorrectionViewModel(GlobalContext globalContext) + public BillCorrectionViewModel(GlobalContext globalContext, BillCorrectionService billCorrectionService) { - this.GlobalContext = globalContext; + this.billCorrectionService = billCorrectionService; + this.globalContext = globalContext; + var shopList = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(globalContext.User.ShopList)); + this.ShopList = new ObservableCollection(shopList); SaleFreightBillFileList = new ObservableCollection(); SaleFreightBillList = new List(); StartDate = DateTime.Now.Date.AddDays((DateTime.Now.Day - 1) * -1).AddMonths(-1); EndDate = StartDate.AddMonths(1).AddDays(-1); + delayTrigger = new DelayTrigger(500); + delayTrigger.OnExecute = OnSearchShopKeyWordChanged; + OrderList = new ObservableCollection(); + ImportSaleFreightBillCommand = new RelayCommand(ImportSaleFreightBill); + SearchBillCorrectionOrderCommand = new RelayCommand(SearchBillCorrectionOrder); + } + + private void OnSearchShopKeyWordChanged(string key) + { + foreach (var s in this.ShopList) + s.IsSelected = false; + + App.Current.Dispatcher.Invoke(() => + { + this.ShopList.Clear(); + + var keyWordShopList = string.IsNullOrEmpty(key) ? globalContext.User.ShopList : globalContext.User.ShopList.Where(s => s.ShopName.Contains(key)); + if (keyWordShopList.Count() > 0) + { + foreach (var shop in keyWordShopList) + ShopList.Add(shop); + } + }); } private void ImportSaleFreightBill(string expressName) @@ -241,5 +289,49 @@ namespace BBWY.Client.ViewModels } return list; } + + /// + /// 查询 + /// + private void SearchBillCorrectionOrder() + { + IsLoading = true; + OrderList.Clear(); + var shopIds = ShopList.Where(s => s.IsSelected).Select(s => s.ShopId).ToList(); + Task.Factory.StartNew(() => billCorrectionService.GetBillCorrectionOrderList(shopIds, StartDate, EndDate)) + .ContinueWith(t => + { + IsLoading = false; + var response = t.Result; + if (!response.Success) + { + App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "提示")); + return; + } + if (response.Data == null || response.Data.Count() == 0) + return; + + var list = response.Data.Map>(); + + App.Current.Dispatcher.BeginInvoke((Action)delegate + { + foreach (var order in list) + { + if (string.IsNullOrEmpty(order.WaybillNo)) + continue; + var billModel = SaleFreightBillList.FirstOrDefault(b => b.BillNo == order.WaybillNo); + if (billModel == null) + continue; + + if (billModel.Amount != order.DeliveryExpressFreight) + { + order.NewDeliveryExpressFreight = billModel.Amount; + order.ChangedContent = $"销售运费 {order.DeliveryExpressFreight} -> {order.NewDeliveryExpressFreight}"; + } + OrderList.Add(order); + } + }); + }); + } } } diff --git a/BBWY.Client/ViewModels/MainViewModel.cs b/BBWY.Client/ViewModels/MainViewModel.cs index d9b2cc84..a6e122f2 100644 --- a/BBWY.Client/ViewModels/MainViewModel.cs +++ b/BBWY.Client/ViewModels/MainViewModel.cs @@ -207,13 +207,13 @@ namespace BBWY.Client.ViewModels throw new Exception(response.Msg); departmentList = response.Data.Map>(); - if (GlobalContext.User.TeamName == "刷单组") - { + //if (GlobalContext.User.TeamName == "刷单组") + //{ var shopList = new List(); foreach (var d in departmentList) shopList.AddRange(d.ShopList); GlobalContext.User.ShopList = shopList; - } + //} } else { diff --git a/BBWY.Client/Views/BillCorrection/BillCorrectionView.xaml b/BBWY.Client/Views/BillCorrection/BillCorrectionView.xaml index 75d19127..3234bf10 100644 --- a/BBWY.Client/Views/BillCorrection/BillCorrectionView.xaml +++ b/BBWY.Client/Views/BillCorrection/BillCorrectionView.xaml @@ -7,6 +7,7 @@ xmlns:c="clr-namespace:BBWY.Controls;assembly=BBWY.Controls" xmlns:cmodel="clr-namespace:BBWY.Client.Models" xmlns:sys="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d" + xmlns:hc="https://handyorg.github.io/handycontrol" DataContext="{Binding BillCorrection,Source={StaticResource Locator}}" d:DesignHeight="1080" d:DesignWidth="1920" Title="BillCorrectionView"> @@ -39,9 +40,29 @@ + + + + + + + + + + + + + - + diff --git a/BBWY.Server.API/Controllers/BillCorrectionController.cs b/BBWY.Server.API/Controllers/BillCorrectionController.cs new file mode 100644 index 00000000..fb0561af --- /dev/null +++ b/BBWY.Server.API/Controllers/BillCorrectionController.cs @@ -0,0 +1,28 @@ +using BBWY.Server.Business; +using BBWY.Server.Model.Dto; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; + +namespace BBWY.Server.API.Controllers +{ + public class BillCorrectionController : BaseApiController + { + private BillCorrectionBusiness billCorrectionBusiness; + public BillCorrectionController(IHttpContextAccessor httpContextAccessor, BillCorrectionBusiness billCorrectionBusiness) : base(httpContextAccessor) + { + this.billCorrectionBusiness = billCorrectionBusiness; + } + + /// + /// 获取待矫正费用订单 + /// + /// + /// + [HttpPost] + public IList GetBillCorrectionOrderList([FromBody] QueryBillCorrectionOrderRequest request) + { + return billCorrectionBusiness.GetBillCorrectionOrderList(request); + } + } +} diff --git a/BBWY.Server.Business/BillCorrection/BillCorrectionBusiness.cs b/BBWY.Server.Business/BillCorrection/BillCorrectionBusiness.cs new file mode 100644 index 00000000..b6fcce2f --- /dev/null +++ b/BBWY.Server.Business/BillCorrection/BillCorrectionBusiness.cs @@ -0,0 +1,77 @@ +using BBWY.Common.Models; +using BBWY.Server.Model.Db; +using BBWY.Server.Model.Dto; +using System.Collections.Generic; +using Yitter.IdGenerator; +using System.Linq; + +namespace BBWY.Server.Business +{ + public class BillCorrectionBusiness : BaseBusiness, IDenpendency + { + public BillCorrectionBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator) : base(fsql, nLogManager, idGenerator) + { + + } + + public IList GetBillCorrectionOrderList(QueryBillCorrectionOrderRequest request) + { + request.EndTime = request.EndTime.Date.AddDays(1).AddSeconds(-1); + var orderList = fsql.Select() + .Where(o => request.ShopIds.Contains(o.ShopId) && o.StartTime >= request.StartTime && o.StartTime <= request.EndTime) + .OrderBy(o => o.StartTime) + .ToList(o => new BillCorrectionOrderResponse + { + OrderId = o.Id, + StartTime = o.StartTime, + StorageType = o.StorageType, + OrderState = o.OrderState, + WaybillNo = o.WaybillNo + }); + + var orderIds = orderList.Select(o => o.OrderId).ToList(); + + var orderCostDetailList = fsql.Select() + .Where(ocd => orderIds.Contains(ocd.OrderId)) + .GroupBy(ocd => ocd.OrderId) + .ToList(g => new + { + OrderId = g.Key, + DeliveryExpressFreight = g.Sum(g.Value.DeliveryExpressFreight), + SkuAmount = g.Sum(g.Value.SkuAmount), + PurchaseFreight = g.Sum(g.Value.PurchaseFreight), + FirstFreight = g.Sum(g.Value.FirstFreight), + InStorageAmount = g.Sum(g.Value.InStorageAmount), + OutStorageAmount = g.Sum(g.Value.OutStorageAmount), + ConsumableAmount = g.Sum(g.Value.ConsumableAmount), + StorageAmount = g.Sum(g.Value.StorageAmount) + }); + + var afterOrderList = fsql.Select() + .Where(aso => orderIds.Contains(aso.OrderId)) + .GroupBy(aso => aso.OrderId) + .ToList(g => new + { + OrderId = g.Key, + AfterTotalCost = g.Sum(g.Value.AfterTotalCost) + }); + + foreach (var order in orderList) + { + var orderCostDetail = orderCostDetailList.FirstOrDefault(ocd => ocd.OrderId == order.OrderId); + var afterOrder = afterOrderList.FirstOrDefault(aso => aso.OrderId == order.OrderId); + + order.DeliveryExpressFreight = orderCostDetail?.DeliveryExpressFreight ?? 0M; + order.SkuAmount = orderCostDetail?.SkuAmount ?? 0M; + order.PurchaseFreight = orderCostDetail?.PurchaseFreight ?? 0M; + order.FirstFreight = orderCostDetail?.FirstFreight ?? 0M; + order.InStorageAmount = orderCostDetail?.InStorageAmount ?? 0M; + order.OutStorageAmount = orderCostDetail?.OutStorageAmount ?? 0M; + order.ConsumableAmount = orderCostDetail?.ConsumableAmount ?? 0M; + order.StorageAmount = orderCostDetail?.StorageAmount ?? 0M; + order.AfterTotalCost = afterOrder?.AfterTotalCost ?? 0M; + } + return orderList; + } + } +} diff --git a/BBWY.Server.Model/Dto/Request/BillCorrection/QueryBillCorrectionOrderRequest.cs b/BBWY.Server.Model/Dto/Request/BillCorrection/QueryBillCorrectionOrderRequest.cs new file mode 100644 index 00000000..65aaa482 --- /dev/null +++ b/BBWY.Server.Model/Dto/Request/BillCorrection/QueryBillCorrectionOrderRequest.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace BBWY.Server.Model.Dto +{ + public class QueryBillCorrectionOrderRequest + { + public IList ShopIds { get; set; } + + public DateTime StartTime { get; set; } + + public DateTime EndTime { get; set; } + } +} diff --git a/BBWY.Server.Model/Dto/Response/BillCorrection/BillCorrectionOrderResponse.cs b/BBWY.Server.Model/Dto/Response/BillCorrection/BillCorrectionOrderResponse.cs new file mode 100644 index 00000000..19e1794f --- /dev/null +++ b/BBWY.Server.Model/Dto/Response/BillCorrection/BillCorrectionOrderResponse.cs @@ -0,0 +1,74 @@ +using System; + +namespace BBWY.Server.Model.Dto +{ + public class BillCorrectionOrderResponse + { + /// + /// 订单号 + /// + public string OrderId { get; set; } + + /// + /// 订单状态 + /// + public Enums.OrderState? OrderState { get; set; } + + /// + /// 订单开始日期 + /// + public DateTime? StartTime { get; set; } + + /// + /// 发货类型 + /// + public Enums.StorageType? StorageType { get; set; } + + /// + /// 销售运费 + /// + public decimal DeliveryExpressFreight { get; set; } = 0.00M; + + /// + /// Sku成本(商品成本) + /// + public decimal SkuAmount { get; set; } = 0.00M; + + /// + /// 采购运费 + /// + public decimal PurchaseFreight { get; set; } = 0.00M; + + /// + /// 头程运费 + /// + public decimal FirstFreight { get; set; } = 0.00M; + + /// + /// 入仓操作费 + /// + public decimal InStorageAmount { get; set; } = 0.00M; + + /// + /// 出仓操作费 + /// + public decimal OutStorageAmount { get; set; } = 0.00M; + + /// + /// 耗材费 + /// + public decimal ConsumableAmount { get; set; } = 0.00M; + + /// + /// 仓储费 + /// + public decimal StorageAmount { get; set; } = 0.00M; + + /// + /// 售后费用 + /// + public decimal AfterTotalCost { get; set; } + + public string WaybillNo { get; set; } + } +}