From 9e5e456d772bf7c95db5d6166abb8b88cd46faac Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Wed, 10 May 2023 23:02:53 +0800 Subject: [PATCH] =?UTF-8?q?B=E7=AB=AF=E6=94=B9=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BBWYB.Client/APIServices/OrderService.cs | 26 ++++++++- BBWYB.Client/APIServices/ProductService.cs | 4 +- .../APIServices/PurchaseOrderService.cs | 6 +- BBWYB.Client/APIServices/PurchaseService.cs | 10 ++-- BBWYB.Client/APIServices/ShopService.cs | 2 +- BBWYB.Client/App.xaml.cs | 2 +- BBWYB.Client/GlobalContext.cs | 2 +- .../ViewModels/Order/EditPriceViewModel.cs | 56 ++++++++++++++++++- .../ViewModels/Order/OrderViewModel.cs | 13 +++++ BBWYB.Client/Views/Order/EditPrice.xaml | 53 ++++++++++++++++++ BBWYB.Client/Views/Order/EditPrice.xaml.cs | 30 ++++++++++ .../Views/Purchase/OnlinePurchase.xaml.cs | 5 +- 12 files changed, 187 insertions(+), 22 deletions(-) diff --git a/BBWYB.Client/APIServices/OrderService.cs b/BBWYB.Client/APIServices/OrderService.cs index e69664a..ab5a78b 100644 --- a/BBWYB.Client/APIServices/OrderService.cs +++ b/BBWYB.Client/APIServices/OrderService.cs @@ -2,6 +2,8 @@ using BBWYB.Common.Http; using BBWYB.Common.Models; using System; +using System.Collections.Generic; +using System.Linq; using System.Net.Http; namespace BBWYB.Client.APIServices @@ -27,7 +29,7 @@ namespace BBWYB.Client.APIServices long? shopId, bool excludeCanceled) { - return SendRequest(globalContext.BBYWApiHost, "api/order/getorderlist", new + return SendRequest(globalContext.BBWYApiHost, "api/order/getorderlist", new { orderId, shopId, @@ -47,7 +49,7 @@ namespace BBWYB.Client.APIServices public ApiResponse CancelOrder(string orderId, string remark) { - return SendRequest(globalContext.BBYWApiHost, "api/order/CancelOrder", new + return SendRequest(globalContext.BBWYApiHost, "api/order/CancelOrder", new { orderId, remark, @@ -57,5 +59,25 @@ namespace BBWYB.Client.APIServices globalContext.User.Shop.Platform }, null, HttpMethod.Post); } + + public ApiResponse EditPrice(string orderId, IList orderSkuList) + { + return SendRequest(globalContext.BBWYApiHost, "api/order/EditPrice", new + { + orderId, + EditItems = orderSkuList.Select(osku => new + { + OrderSkuId = osku.Id, + SkuId = osku.SkuId, + Price = osku.NewPrice, + Freight = osku.FreightAmount, + Quantity = osku.ItemTotal + }), + globalContext.User.Shop.AppKey, + globalContext.User.Shop.AppSecret, + globalContext.User.Shop.AppToken, + globalContext.User.Shop.Platform + }, null, HttpMethod.Post); + } } } diff --git a/BBWYB.Client/APIServices/ProductService.cs b/BBWYB.Client/APIServices/ProductService.cs index 4062c4f..8f2f133 100644 --- a/BBWYB.Client/APIServices/ProductService.cs +++ b/BBWYB.Client/APIServices/ProductService.cs @@ -12,7 +12,7 @@ namespace BBWYB.Client.APIServices public ApiResponse GetProductList(string spu, string productName, string productItem, int pageIndex) { - return SendRequest(globalContext.BBYWApiHost, + return SendRequest(globalContext.BBWYApiHost, "api/product/GetProductList", new { @@ -31,7 +31,7 @@ namespace BBWYB.Client.APIServices public ApiResponse GetProductSkuList(string spu, string sku) { - return SendRequest(globalContext.BBYWApiHost, + return SendRequest(globalContext.BBWYApiHost, "api/product/GetProductSkuList", new { diff --git a/BBWYB.Client/APIServices/PurchaseOrderService.cs b/BBWYB.Client/APIServices/PurchaseOrderService.cs index a7e9909..d2b79e9 100644 --- a/BBWYB.Client/APIServices/PurchaseOrderService.cs +++ b/BBWYB.Client/APIServices/PurchaseOrderService.cs @@ -65,7 +65,7 @@ namespace BBWYB.Client.APIServices public ApiResponse PreviewPurchaseOrder(Consignee consignee, IList productSkuWithSchemeList, PurchaseOrderMode purchaseOrderMode) { var cargoParamGroupList = CombineCargoParamGroup(productSkuWithSchemeList); - return SendRequest(globalContext.BBYWApiHost, "api/PurchaseOrder/PreviewPurchaseOrder", new + return SendRequest(globalContext.BBWYApiHost, "api/PurchaseOrder/PreviewPurchaseOrder", new { purchaseOrderMode, consignee, @@ -94,7 +94,7 @@ namespace BBWYB.Client.APIServices string extensions) { var cargoParamGroupList = CombineCargoParamGroup(productSkuWithSchemeList); - return SendRequest(globalContext.BBYWApiHost, "api/purchaseOrder/CreatePurchaseOrder", new + return SendRequest(globalContext.BBWYApiHost, "api/purchaseOrder/CreatePurchaseOrder", new { purchaseOrderMode, consignee, @@ -118,7 +118,7 @@ namespace BBWYB.Client.APIServices /// public ApiResponse> GetAuditPurchaseOrderList(IList shopIdList, DateTime startDate, DateTime endDate) { - return SendRequest>(globalContext.BBYWApiHost, "Api/PurchaseOrder/GetAuditPurchaseOrderList", new + return SendRequest>(globalContext.BBWYApiHost, "Api/PurchaseOrder/GetAuditPurchaseOrderList", new { startDate, endDate, diff --git a/BBWYB.Client/APIServices/PurchaseService.cs b/BBWYB.Client/APIServices/PurchaseService.cs index a215106..49e2ccc 100644 --- a/BBWYB.Client/APIServices/PurchaseService.cs +++ b/BBWYB.Client/APIServices/PurchaseService.cs @@ -25,7 +25,7 @@ namespace BBWYB.Client.APIServices long? schemeId = null, Platform? purchasePlatform = null) { - return SendRequest>(globalContext.BBYWApiHost, + return SendRequest>(globalContext.BBWYApiHost, "api/PurchaseScheme/GetPurchaseSchemeList", new { @@ -47,7 +47,7 @@ namespace BBWYB.Client.APIServices /// public ApiResponse> GetSharePurchaser(IList skuIdList, long shopId) { - return SendRequest>(globalContext.BBYWApiHost, + return SendRequest>(globalContext.BBWYApiHost, "api/PurchaseScheme/GetSharePurchaser", new { skuIdList, shopId }, null, @@ -56,7 +56,7 @@ namespace BBWYB.Client.APIServices public ApiResponse EditPurchaseScheme(IList addPurchaseSchemeList, IList editPurchaseSchemeList) { - return SendRequest(globalContext.BBYWApiHost, + return SendRequest(globalContext.BBWYApiHost, "api/purchasescheme/EditPurchaseScheme", new { @@ -69,7 +69,7 @@ namespace BBWYB.Client.APIServices public ApiResponse DeletePurchaser(string productId, string purchaserId) { - return SendRequest(globalContext.BBYWApiHost, + return SendRequest(globalContext.BBWYApiHost, "api/purchasescheme/DeletePurchaser", new { productId, purchaserId }, null, @@ -78,7 +78,7 @@ namespace BBWYB.Client.APIServices public ApiResponse DeletePurchaseScheme(long schemeId) { - return SendRequest(globalContext.BBYWApiHost, $"api/purchasescheme/DeletePurchaseScheme/{schemeId}", null, null, HttpMethod.Delete); + return SendRequest(globalContext.BBWYApiHost, $"api/purchasescheme/DeletePurchaseScheme/{schemeId}", null, null, HttpMethod.Delete); } } } diff --git a/BBWYB.Client/APIServices/ShopService.cs b/BBWYB.Client/APIServices/ShopService.cs index 20ee41d..170588c 100644 --- a/BBWYB.Client/APIServices/ShopService.cs +++ b/BBWYB.Client/APIServices/ShopService.cs @@ -12,7 +12,7 @@ namespace BBWYB.Client.APIServices public ApiResponse SaveShopSetting(long shopId, PurchaseAccount purchaseAccount) { - return SendRequest(globalContext.BBYWApiHost, "api/vender/SaveShopSetting", new + return SendRequest(globalContext.BBWYApiHost, "api/vender/SaveShopSetting", new { shopId, PurchaseAccountId = purchaseAccount.Id, diff --git a/BBWYB.Client/App.xaml.cs b/BBWYB.Client/App.xaml.cs index bcd661a..1b0f3e3 100644 --- a/BBWYB.Client/App.xaml.cs +++ b/BBWYB.Client/App.xaml.cs @@ -59,7 +59,7 @@ namespace BBWYB.Client var applicationPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var builder = new ConfigurationBuilder().SetBasePath(applicationPath).AddJsonFile("appsettings.json", false, true); Configuration = builder.Build(); - gl.BBYWApiHost = Configuration.GetSection("BBWYApiHost").Value; + gl.BBWYApiHost = Configuration.GetSection("BBWYApiHost").Value; gl.MDSApiHost = Configuration.GetSection("MDSApiHost").Value; IServiceCollection serviceCollection = new ServiceCollection(); diff --git a/BBWYB.Client/GlobalContext.cs b/BBWYB.Client/GlobalContext.cs index 613328e..eac8ac1 100644 --- a/BBWYB.Client/GlobalContext.cs +++ b/BBWYB.Client/GlobalContext.cs @@ -24,7 +24,7 @@ namespace BBWYB.Client //public IJdClient JdClient { get; set; } #region APIHost - public string BBYWApiHost { get; set; } + public string BBWYApiHost { get; set; } public string MDSApiHost { get; set; } #endregion diff --git a/BBWYB.Client/ViewModels/Order/EditPriceViewModel.cs b/BBWYB.Client/ViewModels/Order/EditPriceViewModel.cs index 6d11ee9..31af7ab 100644 --- a/BBWYB.Client/ViewModels/Order/EditPriceViewModel.cs +++ b/BBWYB.Client/ViewModels/Order/EditPriceViewModel.cs @@ -1,5 +1,9 @@ -using BBWYB.Client.Models; +using BBWYB.Client.APIServices; +using BBWYB.Client.Models; +using BBWYB.Client.Views.Order; using CommunityToolkit.Mvvm.Input; +using CommunityToolkit.Mvvm.Messaging; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -10,21 +14,27 @@ namespace BBWYB.Client.ViewModels { public class EditPriceViewModel : BaseVM { + private OrderService orderService; + public IList OrderSkuList { get; set; } private Order order; private decimal freightAmount; private bool isResponseFreightChanged; public ICommand DistributFreightCommand { get; set; } + public ICommand SaveCommand { get; set; } + public decimal FreightAmount { get => freightAmount; set { SetProperty(ref freightAmount, value); } } - public EditPriceViewModel() + public EditPriceViewModel(OrderService orderService) { OrderSkuList = new ObservableCollection(); DistributFreightCommand = new RelayCommand(DistributFreight); + SaveCommand = new RelayCommand(Save); + this.orderService = orderService; } - private void SetData(Order order) + public void SetData(Order order) { this.order = order; foreach (var orderSku in order.ItemList) @@ -67,6 +77,46 @@ namespace BBWYB.Client.ViewModels if (!isResponseFreightChanged) return; + isResponseFreightChanged = false; + var waitDistributFreight = FreightAmount - OrderSkuList.Where(osku => !osku.IsResponseFreightChanged).Sum(osku => osku.FreightAmount); + var waitDistributSkuList = OrderSkuList.Where(osku => osku.IsResponseFreightChanged); + var totalItemCount = waitDistributSkuList.Sum(osku => osku.ItemTotal); + foreach (var orderSku in waitDistributSkuList) + { + var quantityRatio = 1M * orderSku.ItemTotal / totalItemCount; + var currentFreightAmount = waitDistributFreight * quantityRatio; + orderSku.FreightAmount = currentFreightAmount; + orderSku.IsResponseFreightChanged = true; + } + isResponseFreightChanged = true; + } + + private void Save() + { + if (FreightAmount <= 0) + { + MessageBox.Show("运费不正确", "提示"); + return; + } + if (OrderSkuList.Any(osku => osku.FreightAmount <= 0 || osku.NewPrice <= 0)) + { + MessageBox.Show("运费或单价不正确", "提示"); + return; + } + if (Math.Abs(FreightAmount - OrderSkuList.Sum(osku => osku.FreightAmount)) > 1) + { + MessageBox.Show("运费超出误差范围", "提示"); + return; + } + + var response = orderService.EditPrice(this.order.Id, OrderSkuList); + if (!response.Success) + { + MessageBox.Show(response.Msg, "提示"); + return; + } + WeakReferenceMessenger.Default.Send(new Message_EditPrice_Close(null)); + } } } diff --git a/BBWYB.Client/ViewModels/Order/OrderViewModel.cs b/BBWYB.Client/ViewModels/Order/OrderViewModel.cs index 9a5189a..8016484 100644 --- a/BBWYB.Client/ViewModels/Order/OrderViewModel.cs +++ b/BBWYB.Client/ViewModels/Order/OrderViewModel.cs @@ -62,6 +62,10 @@ namespace BBWYB.Client.ViewModels public ICommand CancelOrderCommand { get; set; } + public ICommand EditPriceCommand { get; set; } + + + public OrderViewModel(GlobalContext globalContext, OrderService orderService) { OrderList = new ObservableCollection(); @@ -84,6 +88,7 @@ namespace BBWYB.Client.ViewModels }); OnlinePurchaseCommand = new RelayCommand(OnlinePurchase); CancelOrderCommand = new RelayCommand(CancelOrder); + EditPriceCommand = new RelayCommand(OpenEditPrice); PageIndex = 1; PageSize = 10; EndDate = DateTime.Now; @@ -236,6 +241,14 @@ namespace BBWYB.Client.ViewModels RefreshOrder(orderId); }); } + private void OpenEditPrice(Order order) + { + var edit = new EditPrice(order); + if (edit.ShowDialog() == true) + { + RefreshOrder(order.Id); + } + } } } diff --git a/BBWYB.Client/Views/Order/EditPrice.xaml b/BBWYB.Client/Views/Order/EditPrice.xaml index ed182a4..70c3850 100644 --- a/BBWYB.Client/Views/Order/EditPrice.xaml +++ b/BBWYB.Client/Views/Order/EditPrice.xaml @@ -57,6 +57,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BBWYB.Client/Views/Order/EditPrice.xaml.cs b/BBWYB.Client/Views/Order/EditPrice.xaml.cs index 018940e..b127fce 100644 --- a/BBWYB.Client/Views/Order/EditPrice.xaml.cs +++ b/BBWYB.Client/Views/Order/EditPrice.xaml.cs @@ -1,4 +1,7 @@ using BBWYB.Client.Models; +using BBWYB.Client.ViewModels; +using CommunityToolkit.Mvvm.Messaging; +using CommunityToolkit.Mvvm.Messaging.Messages; using SJ.Controls; namespace BBWYB.Client.Views.Order @@ -11,6 +14,33 @@ namespace BBWYB.Client.Views.Order public EditPrice(Models.Order order) { InitializeComponent(); + (this.DataContext as EditPriceViewModel).SetData(order); + this.Loaded += EditPrice_Loaded; + this.Unloaded += EditPrice_Unloaded; + } + + private void EditPrice_Unloaded(object sender, System.Windows.RoutedEventArgs e) + { + WeakReferenceMessenger.Default.UnregisterAll(this); + } + + private void EditPrice_Loaded(object sender, System.Windows.RoutedEventArgs e) + { + WeakReferenceMessenger.Default.Register(this, (o, x) => + { + this.Dispatcher.Invoke(() => + { + this.DialogResult = true; + this.Close(); + }); + }); + } + } + + public class Message_EditPrice_Close : ValueChangedMessage + { + public Message_EditPrice_Close(object value) : base(value) + { } } } diff --git a/BBWYB.Client/Views/Purchase/OnlinePurchase.xaml.cs b/BBWYB.Client/Views/Purchase/OnlinePurchase.xaml.cs index 96b5bdd..d1bd782 100644 --- a/BBWYB.Client/Views/Purchase/OnlinePurchase.xaml.cs +++ b/BBWYB.Client/Views/Purchase/OnlinePurchase.xaml.cs @@ -31,10 +31,7 @@ namespace BBWYB.Client.Views.Purchase //Messenger.Default.Register(this, "OnlinePurchase_Close", (x) => this.Dispatcher.Invoke(() => this.Close())); WeakReferenceMessenger.Default.Register(this, (o, x) => { - this.Dispatcher.Invoke(() => - { - this.Dispatcher.Invoke(() => this.Close()); - }); + this.Dispatcher.Invoke(() => this.Close()); }); } }