From b6056aa3fb975878732ced5d8b8b8eb8a44d6c5b Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Tue, 1 Aug 2023 23:42:02 +0800 Subject: [PATCH] 10162 --- BBWY.Client/APIServices/OrderService.cs | 32 +++ BBWY.Client/GlobalContext.cs | 2 +- .../Response/Order/ExportOrderSkuResponse.cs | 46 ++++ BBWY.Client/ViewModels/MainViewModel.cs | 3 +- .../Order/ExportOrderSkuViewModel.cs | 202 ++++++++++++++++++ BBWY.Client/ViewModels/ViewModelLocator.cs | 9 + .../Views/Order/ExportOrderSkuView.xaml | 167 +++++++++++++++ .../Views/Order/ExportOrderSkuView.xaml.cs | 26 +++ 8 files changed, 485 insertions(+), 2 deletions(-) create mode 100644 BBWY.Client/Models/APIModel/Response/Order/ExportOrderSkuResponse.cs create mode 100644 BBWY.Client/ViewModels/Order/ExportOrderSkuViewModel.cs create mode 100644 BBWY.Client/Views/Order/ExportOrderSkuView.xaml create mode 100644 BBWY.Client/Views/Order/ExportOrderSkuView.xaml.cs diff --git a/BBWY.Client/APIServices/OrderService.cs b/BBWY.Client/APIServices/OrderService.cs index 78fe11a0..fadd1f85 100644 --- a/BBWY.Client/APIServices/OrderService.cs +++ b/BBWY.Client/APIServices/OrderService.cs @@ -278,5 +278,37 @@ namespace BBWY.Client.APIServices shop.AppToken }, null, HttpMethod.Post); } + + public ApiResponse QueryOrderSkuList(DateTime startDate, + DateTime endDate, + int? purchasePlatform, + IList shopIds, + int pageIndex, + int pageSize) + { + return SendRequest(globalContext.BBYWApiHost, "api/order/queryorderskulist", new + { + shopIds, + purchasePlatform, + startTime = startDate, + endTime = endDate, + pageIndex, + pageSize + }, null, HttpMethod.Post); + } + + public ApiResponse> ExportOrderSkuList(DateTime startDate, + DateTime endDate, + int? purchasePlatform, + IList shopIds) + { + return SendRequest>(globalContext.BBYWApiHost, "api/order/exportorderskulist", new + { + shopIds, + purchasePlatform, + startTime = startDate, + endTime = endDate + }, null, HttpMethod.Post); + } } } diff --git a/BBWY.Client/GlobalContext.cs b/BBWY.Client/GlobalContext.cs index ed414065..f244d15a 100644 --- a/BBWY.Client/GlobalContext.cs +++ b/BBWY.Client/GlobalContext.cs @@ -13,7 +13,7 @@ namespace BBWY.Client { ShopServiceGroupList = new List(); ShopServiceGroupLowerList = new List(); - ClientVersion = "10161"; + ClientVersion = "10162"; } private User user; diff --git a/BBWY.Client/Models/APIModel/Response/Order/ExportOrderSkuResponse.cs b/BBWY.Client/Models/APIModel/Response/Order/ExportOrderSkuResponse.cs new file mode 100644 index 00000000..42b45ba4 --- /dev/null +++ b/BBWY.Client/Models/APIModel/Response/Order/ExportOrderSkuResponse.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; + +namespace BBWY.Client.Models +{ + public class ExportOrderSkuResponse + { + public string OrderId { get; set; } + + public DateTime? StartTime { get; set; } + + public long ShopId { get; set; } + + public string ShopName { get; set; } + + public string Spu { get; set; } + + public string Sku { get; set; } + + public StorageType? StorageType { get; set; } + + public decimal? PurchaseSkuAmount { get; set; } + + public decimal? PurchaseFreight { get; set; } + + public decimal? PurchaseAmount { get { return PurchaseSkuAmount + PurchaseFreight; } } + + public decimal? SkuPrice { get; set; } + + public int? ItemTotal { get; set; } + + public string SpuName { get; set; } + + public override string ToString() + { + return $"{StartTime},{ShopName},{OrderId},{Spu},{Sku},{StorageType},{PurchaseAmount},{SkuPrice},{ItemTotal},{SpuName}"; + } + } + + public class ExportOrderSkuListResponse + { + public long Count { get; set; } + + public IList ItemList { get; set; } + } +} diff --git a/BBWY.Client/ViewModels/MainViewModel.cs b/BBWY.Client/ViewModels/MainViewModel.cs index 30820a6f..42fb8215 100644 --- a/BBWY.Client/ViewModels/MainViewModel.cs +++ b/BBWY.Client/ViewModels/MainViewModel.cs @@ -228,7 +228,8 @@ namespace BBWY.Client.ViewModels ChildList = new List() { new MenuModel(){ Name="采购审计",Url="/Views/FinancialTerminal/ProcurementAudit.xaml" }, - new MenuModel(){ Name="费用矫正",Url="/Views/BillCorrection/BillCorrectionView.xaml" } + new MenuModel(){ Name="费用矫正",Url="/Views/BillCorrection/BillCorrectionView.xaml" }, + new MenuModel(){ Name="订单导出",Url="/Views/Order/ExportOrderSkuView.xaml" } } })); } diff --git a/BBWY.Client/ViewModels/Order/ExportOrderSkuViewModel.cs b/BBWY.Client/ViewModels/Order/ExportOrderSkuViewModel.cs new file mode 100644 index 00000000..ac8146f4 --- /dev/null +++ b/BBWY.Client/ViewModels/Order/ExportOrderSkuViewModel.cs @@ -0,0 +1,202 @@ +using BBWY.Client.APIServices; +using BBWY.Client.Models; +using BBWY.Common.Models; +using BBWY.Controls; +using GalaSoft.MvvmLight.Command; +using Microsoft.Win32; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; + +namespace BBWY.Client.ViewModels +{ + public class ExportOrderSkuViewModel : BaseVM, IDenpendency + { + private DateTime startDate; + private DateTime endDate; + + private GlobalContext globalContext; + private KVModel selectedPlatform; + private int pageIndex; + private int pageSize; + private long totalCount; + private bool isLoading; + + private OrderService orderService; + + public IList DepartmentList { get; set; } + + public IList ShopList { get; set; } + + public IList PlatformList { get; set; } + + public IList ExportSkuList { get; set; } + + public DateTime StartDate { get => startDate; set { Set(ref startDate, value); } } + public DateTime EndDate { get => endDate; set { Set(ref endDate, value); } } + + public KVModel SelectedPlatform { get => selectedPlatform; set { Set(ref selectedPlatform, value); } } + + public ICommand SearchCommand { get; set; } + + public ICommand ExportCommand { get; set; } + + public ICommand OrderPageIndexChangedCommand { get; set; } + + public int PageIndex { get => pageIndex; set { Set(ref pageIndex, value); } } + public int PageSize { get => pageSize; set { Set(ref pageSize, value); } } + + public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } } + + public long TotalCount { get => totalCount; set { Set(ref totalCount, value); } } + + public ExportOrderSkuViewModel(GlobalContext globalContext, OrderService orderService) + { + this.orderService = orderService; + + DepartmentList = new ObservableCollection(); + ShopList = new ObservableCollection(); + PlatformList = new ObservableCollection(); + ExportSkuList = new ObservableCollection(); + SearchCommand = new RelayCommand(Search); + ExportCommand = new RelayCommand(Export); + OrderPageIndexChangedCommand = new RelayCommand(p => + { + //this.PageIndex = p.PageIndex; + Task.Factory.StartNew(() => SearchCore(p.PageIndex)); + }); + + var platformEnumValues = Enum.GetValues(typeof(Platform)); + foreach (var ev in platformEnumValues) + { + var p = (Platform)ev; + PlatformList.Add(new KVModel() + { + Key = p.ToString(), + Value = ((int)p).ToString() + }); + } + + this.globalContext = globalContext; + LoadDepartment(); + StartDate = DateTime.Now.Date; + EndDate = DateTime.Now.Date; + PageIndex = 1; + PageSize = 20; + } + + private void LoadDepartment() + { + var dlist = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(globalContext.User.DepartmentList)); + foreach (var d in dlist) + { + d.IsSelected = false; + DepartmentList.Add(d); + d.OnIsSelectedChanged = OnDeparmentSelectionChanged; + } + ShopList.Clear(); + } + + private void OnDeparmentSelectionChanged() + { + ShopList.Clear(); + foreach (var d in DepartmentList) + { + if (!d.IsSelected) + continue; + foreach (var s in d.ShopList) + { + s.IsSelected = false; + ShopList.Add(s); + } + } + } + + private void Search() + { + PageIndex = 1; + Task.Factory.StartNew(() => SearchCore(PageIndex)); + } + + private void SearchCore(int pageIndex) + { + IsLoading = true; + int? purchasePlatform = null; + if (SelectedPlatform != null) + purchasePlatform = int.Parse(SelectedPlatform.Value); + var response = orderService.QueryOrderSkuList(StartDate, + EndDate, + purchasePlatform, + ShopList.Where(s => s.IsSelected).Select(s => s.ShopId).ToList(), + pageIndex, + PageSize); + IsLoading = false; + TotalCount = 0; + if (!response.Success) + { + App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "提示")); + return; + } + TotalCount = response.Data.Count; + App.Current.Dispatcher.Invoke(() => + { + ExportSkuList.Clear(); + foreach (var item in response.Data.ItemList) + ExportSkuList.Add(item); + }); + + } + + private void Export() + { + var sfd = new SaveFileDialog() { Filter = "csv files(*.csv)|*.csv" }; + if (sfd.ShowDialog() != true) + return; + + var ssaveFileName = sfd.FileName; + + int? purchasePlatform = null; + if (SelectedPlatform != null) + purchasePlatform = int.Parse(SelectedPlatform.Value); + IsLoading = true; + Task.Factory.StartNew(() => orderService.ExportOrderSkuList(StartDate, + EndDate, + purchasePlatform, + ShopList.Where(s => s.IsSelected).Select(s => s.ShopId).ToList())).ContinueWith(t => + { + var response = t.Result; + + if (!response.Success) + { + IsLoading = false; + App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "提示")); + return; + } + + try + { + var list = response.Data.Select(x => x.ToString()).ToList(); + list.Insert(0, "开始时间,店铺名称,订单Id,SPU,SKU,仓储类型,采购成本(货款+运费),单价,数量,商品标题"); + System.IO.File.WriteAllLines(ssaveFileName, list, Encoding.UTF8); + App.Current.Dispatcher.Invoke(() => MessageBox.Show("导出完成", "导出")); + } + catch (Exception ex) + { + App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "导出")); + return; + } + finally + { + IsLoading = false; + } + }); + + } + } +} diff --git a/BBWY.Client/ViewModels/ViewModelLocator.cs b/BBWY.Client/ViewModels/ViewModelLocator.cs index 73bd50ee..d71620b0 100644 --- a/BBWY.Client/ViewModels/ViewModelLocator.cs +++ b/BBWY.Client/ViewModels/ViewModelLocator.cs @@ -367,6 +367,15 @@ namespace BBWY.Client.ViewModels } } + public ExportOrderSkuViewModel ExportOrderSkuVM + { + get + { + using var s = sp.CreateScope(); + return s.ServiceProvider.GetRequiredService(); + } + } + //public ShopSealBoxListViewModel ShopSealBoxListVM //{ // get diff --git a/BBWY.Client/Views/Order/ExportOrderSkuView.xaml b/BBWY.Client/Views/Order/ExportOrderSkuView.xaml new file mode 100644 index 00000000..9e147d35 --- /dev/null +++ b/BBWY.Client/Views/Order/ExportOrderSkuView.xaml @@ -0,0 +1,167 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BBWY.Client/Views/Order/ExportOrderSkuView.xaml.cs b/BBWY.Client/Views/Order/ExportOrderSkuView.xaml.cs new file mode 100644 index 00000000..9ad5dfe9 --- /dev/null +++ b/BBWY.Client/Views/Order/ExportOrderSkuView.xaml.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BBWY.Client.Views.Order +{ + /// + /// ExportOrderSkuView.xaml 的交互逻辑 + /// + public partial class ExportOrderSkuView : Page + { + public ExportOrderSkuView() + { + InitializeComponent(); + } + } +}