From 9ecc928926a0013b4092f20c3516f3ff259296bb Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Wed, 22 Jun 2022 06:24:13 +0800 Subject: [PATCH] 1 --- BBWY.Client/Models/Order/OrderDropShipping.cs | 22 +- .../Models/Order/RelationPurchaseOrderSku.cs | 5 + .../ViewModels/Order/OrderListViewModel.cs | 45 ++-- BBWY.Client/Views/Order/OrderList.xaml | 25 +- .../Views/Order/RelationPurchaseOrder.xaml | 236 ++++++++++-------- .../Views/Order/RelationPurchaseOrder.xaml.cs | 66 +++-- BBWY.Client/Views/SelectShop.xaml.cs | 8 - BBWY.Controls/BWindow.cs | 23 +- BBWY.Server.Business/Order/OrderBusiness.cs | 11 +- .../Request/Order/OrderDropShippingRequest.cs | 2 - 10 files changed, 266 insertions(+), 177 deletions(-) diff --git a/BBWY.Client/Models/Order/OrderDropShipping.cs b/BBWY.Client/Models/Order/OrderDropShipping.cs index fd21073b..d985ee44 100644 --- a/BBWY.Client/Models/Order/OrderDropShipping.cs +++ b/BBWY.Client/Models/Order/OrderDropShipping.cs @@ -1,11 +1,15 @@ -namespace BBWY.Client.Models +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace BBWY.Client.Models { - public class OrderDropShipping : NotifyObject + public class OrderDropShipping : NotifyObject, ICloneable { public OrderDropShipping() { - if (PurchaseFreight != 0M) - PurchaseFreightStr = PurchaseFreight.ToString(); + PurchaseFreightStr = PurchaseFreight.ToString(); + RelationPurchaseOrderSkuList = new ObservableCollection(); } public long Id { get; set; } public string OrderId { get; set; } @@ -60,6 +64,16 @@ private void OnAmountChanged() { PurchaseAmount = SkuAmount + PurchaseFreight; + OnPurchaseAmountChanged?.Invoke(); + } + + public Action OnPurchaseAmountChanged { get; set; } + + public object Clone() + { + return this.MemberwiseClone(); } + + public IList RelationPurchaseOrderSkuList { get; set; } } } diff --git a/BBWY.Client/Models/Order/RelationPurchaseOrderSku.cs b/BBWY.Client/Models/Order/RelationPurchaseOrderSku.cs index 87082933..7f417178 100644 --- a/BBWY.Client/Models/Order/RelationPurchaseOrderSku.cs +++ b/BBWY.Client/Models/Order/RelationPurchaseOrderSku.cs @@ -57,6 +57,11 @@ namespace BBWY.Client.Models } } + /// + /// 代发信息Id + /// + public long? OrderDropShippingId { get; set; } + [JsonIgnore] public Action OnSkuAmountChanged { get; set; } diff --git a/BBWY.Client/ViewModels/Order/OrderListViewModel.cs b/BBWY.Client/ViewModels/Order/OrderListViewModel.cs index 1ba031be..1df73a67 100644 --- a/BBWY.Client/ViewModels/Order/OrderListViewModel.cs +++ b/BBWY.Client/ViewModels/Order/OrderListViewModel.cs @@ -221,7 +221,7 @@ namespace BBWY.Client.ViewModels private void LoadOrder(int pageIndex) { IsLoading = true; - Thread.Sleep(random.Next(500, 2000)); + Thread.Sleep(random.Next(0, 1000)); var response = orderService.GetOrderList(SearchOrderId, StartDate, EndDate, @@ -347,25 +347,25 @@ namespace BBWY.Client.ViewModels private void RelationPurchaseOrder_Closed(object sender, EventArgs e) { - var relationPurchaseOrder = sender as RelationPurchaseOrder; - if (relationPurchaseOrder.DialogResult != true) - return; - var orderDropShipping = relationPurchaseOrder.OrderDropShipping; - var relationPurchaseOrderSkuList = relationPurchaseOrder.RelationPurchaseOrderSkuList; - IsLoading = true; - Task.Factory.StartNew(() => orderService.RelationPurchaseOrder(orderDropShipping, relationPurchaseOrderSkuList, globalContext.User.Shop.PlatformCommissionRatio ?? 0.05M)) - .ContinueWith(r => - { - var response = r.Result; - if (!response.Success) - { - IsLoading = false; - App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "关联采购订单")); - return; - } - //LoadOrder(PageIndex); //关联订单刷新订单列表 - RefreshOrder(orderDropShipping.OrderId); - }); + //var relationPurchaseOrder = sender as RelationPurchaseOrder; + //if (relationPurchaseOrder.DialogResult != true) + // return; + //var orderDropShipping = relationPurchaseOrder.OrderDropShipping; + //var relationPurchaseOrderSkuList = relationPurchaseOrder.RelationPurchaseOrderSkuList; + //IsLoading = true; + //Task.Factory.StartNew(() => orderService.RelationPurchaseOrder(orderDropShipping, relationPurchaseOrderSkuList, globalContext.User.Shop.PlatformCommissionRatio ?? 0.05M)) + // .ContinueWith(r => + // { + // var response = r.Result; + // if (!response.Success) + // { + // IsLoading = false; + // App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "关联采购订单")); + // return; + // } + // //LoadOrder(PageIndex); //关联订单刷新订单列表 + // RefreshOrder(orderDropShipping.OrderId); + // }); } private void Sd_Closed(object sender, EventArgs e) @@ -417,7 +417,7 @@ namespace BBWY.Client.ViewModels return; if (order.StorageType == StorageType.代发) { - var relationPurchaseOrder = new RelationPurchaseOrder(order.Id, globalContext.User.Shop.PurchaseAccountList, order.OrderDropShippingList[0], order.ItemList.Select(osku => new RelationPurchaseOrderSku() + var relationPurchaseOrder = new RelationPurchaseOrder(order.Id, globalContext.User.Shop.PurchaseAccountList, order.OrderDropShippingList, order.ItemList.Select(osku => new RelationPurchaseOrderSku() { Logo = osku.Logo, ProductId = osku.ProductId, @@ -425,7 +425,8 @@ namespace BBWY.Client.ViewModels Quantity = osku.ItemTotal, Title = osku.Title, SingleSkuAmount = (order.OrderCostDetailList.FirstOrDefault(ocd => ocd.SkuId == osku.Id)?.SkuAmount / osku.ItemTotal) ?? 0, - SingleSkuAmountStr = ((order.OrderCostDetailList.FirstOrDefault(ocd => ocd.SkuId == osku.Id)?.SkuAmount / osku.ItemTotal) ?? 0).ToString() + SingleSkuAmountStr = ((order.OrderCostDetailList.FirstOrDefault(ocd => ocd.SkuId == osku.Id)?.SkuAmount / osku.ItemTotal) ?? 0).ToString(), + OrderDropShippingId = osku.OrderDropShippingId }).ToList()); relationPurchaseOrder.Closed += RelationPurchaseOrder_Closed; relationPurchaseOrder.ShowDialog(); diff --git a/BBWY.Client/Views/Order/OrderList.xaml b/BBWY.Client/Views/Order/OrderList.xaml index a75c7b69..0664b3eb 100644 --- a/BBWY.Client/Views/Order/OrderList.xaml +++ b/BBWY.Client/Views/Order/OrderList.xaml @@ -291,13 +291,10 @@ - - - - - + + CommandParameter="{Binding Id}" Margin="5,0,0,0"/> - + @@ -356,21 +353,15 @@ - - - - - + - - - - - + diff --git a/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml b/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml index dfaeecbe..500cd995 100644 --- a/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml +++ b/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml @@ -23,122 +23,160 @@ - - + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - + + + - + + + + + + - + + + + + + - - - - + + + + + + + + + + + - + public partial class RelationPurchaseOrder : BWindow { - public OrderDropShipping OrderDropShipping { get; set; } + public IList OrderDropShippingList { get; set; } public IList RelationPurchaseOrderSkuList { get; set; } - public RelationPurchaseOrder(string orderId, IList purchaseAccountList, OrderDropShipping orderDropShipping, IList relationPurchaseOrderSkuList) + public IList PurchaseAccountList { get; set; } + + public string OrderId { get; set; } + + public decimal TotalCost { get => totalCost; set { Set(ref totalCost, value); } } + + private decimal totalCost; + + public RelationPurchaseOrder(string orderId, IList purchaseAccountList, IList orderDropShippingList, IList relationPurchaseOrderSkuList) { InitializeComponent(); this.DataContext = this; - OrderDropShipping = new OrderDropShipping() { OrderId = orderId, BuyerAccount = purchaseAccountList?.FirstOrDefault()?.AccountName }; - if (orderDropShipping != null) + this.PurchaseAccountList = purchaseAccountList; + this.OrderId = orderId; + OrderDropShippingList = new ObservableCollection(); + if (orderDropShippingList != null) { - OrderDropShipping.BuyerAccount = orderDropShipping.BuyerAccount; - OrderDropShipping.PurchaseAmount = orderDropShipping.PurchaseAmount; - OrderDropShipping.PurchaseOrderId = orderDropShipping.PurchaseOrderId; - OrderDropShipping.DeliveryFreight = orderDropShipping.DeliveryFreight; - OrderDropShipping.PurchasePlatform = orderDropShipping.PurchasePlatform; - OrderDropShipping.SellerAccount = orderDropShipping.SellerAccount; - OrderDropShipping.SkuAmount = orderDropShipping.SkuAmount; - OrderDropShipping.PurchaseFreight = orderDropShipping.PurchaseFreight; - OrderDropShipping.PurchaseFreightStr = orderDropShipping.PurchaseFreight.ToString(); + foreach (var ods in orderDropShippingList) + { + var ods1 = ods.Clone() as OrderDropShipping; + ods1.PurchaseFreightStr = ods1.PurchaseFreight.ToString(); + var currentOdsSkuList = relationPurchaseOrderSkuList.Where(rsku => rsku.OrderDropShippingId == ods1.Id); + foreach (var rsku in currentOdsSkuList) + ods.RelationPurchaseOrderSkuList.Add(rsku); + OrderDropShippingList.Add(ods1); + + ods1.OnPurchaseAmountChanged = OnPurchaseAmountChanged; + } } + this.RelationPurchaseOrderSkuList = relationPurchaseOrderSkuList; foreach (var sku in RelationPurchaseOrderSkuList) sku.OnSkuAmountChanged = OnSkuAmountChanged; + + OnPurchaseAmountChanged(); } private void OnSkuAmountChanged() { - OrderDropShipping.SkuAmount = RelationPurchaseOrderSkuList.Sum(sku => sku.SkuAmount); + foreach (var ods in OrderDropShippingList) + ods.SkuAmount = ods.RelationPurchaseOrderSkuList.Sum(sku => sku.SkuAmount); + } + + private void OnPurchaseAmountChanged() + { + TotalCost = OrderDropShippingList.Sum(ods => ods.PurchaseAmount); } private void btn_Save_Click(object sender, System.Windows.RoutedEventArgs e) { - if (string.IsNullOrEmpty(OrderDropShipping.PurchaseOrderId) || - string.IsNullOrEmpty(OrderDropShipping.SellerAccount) || - string.IsNullOrEmpty(OrderDropShipping.BuyerAccount) || - OrderDropShipping.PurchaseAmount == 0) - { - MessageBox.Show("关联订单信息不全", "提示"); - return; - } + //if (string.IsNullOrEmpty(OrderDropShipping.PurchaseOrderId) || + // string.IsNullOrEmpty(OrderDropShipping.SellerAccount) || + // string.IsNullOrEmpty(OrderDropShipping.BuyerAccount) || + // OrderDropShipping.PurchaseAmount == 0) + //{ + // MessageBox.Show("关联订单信息不全", "提示"); + // return; + //} this.DialogResult = true; this.Close(); } diff --git a/BBWY.Client/Views/SelectShop.xaml.cs b/BBWY.Client/Views/SelectShop.xaml.cs index 7a8bb7f8..36ea4651 100644 --- a/BBWY.Client/Views/SelectShop.xaml.cs +++ b/BBWY.Client/Views/SelectShop.xaml.cs @@ -1,16 +1,8 @@ using BBWY.Client.Models; using BBWY.Controls; -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.Shapes; namespace BBWY.Client.Views { diff --git a/BBWY.Controls/BWindow.cs b/BBWY.Controls/BWindow.cs index 346eb9dd..cae55bda 100644 --- a/BBWY.Controls/BWindow.cs +++ b/BBWY.Controls/BWindow.cs @@ -1,4 +1,6 @@ -using System.Reflection; +using System.ComponentModel; +using System.Reflection; +using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -8,7 +10,7 @@ using System.Windows.Shell; namespace BBWY.Controls { [StyleTypedProperty(Property = "Style", StyleTargetType = typeof(BWindow))] - public class BWindow : Window + public class BWindow : Window, INotifyPropertyChanged { public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(BWindow), new PropertyMetadata(new CornerRadius(0))); @@ -155,5 +157,22 @@ namespace BBWY.Controls var filedInfo = typeof(Window).GetField("_showingAsDialog", BindingFlags.Instance | BindingFlags.NonPublic); return filedInfo != null && (bool)filedInfo.GetValue(this); } + + + #region PropertyNotify + public event PropertyChangedEventHandler PropertyChanged; + protected void OnPropertyChanged([CallerMemberName] string propertyName = "") + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + protected bool Set(ref T oldValue, T newValue, [CallerMemberName] string propertyName = "") + { + if (Equals(oldValue, newValue)) + return false; + oldValue = newValue; + OnPropertyChanged(propertyName); + return true; + } + #endregion } } diff --git a/BBWY.Server.Business/Order/OrderBusiness.cs b/BBWY.Server.Business/Order/OrderBusiness.cs index ccb172d1..b90cd770 100644 --- a/BBWY.Server.Business/Order/OrderBusiness.cs +++ b/BBWY.Server.Business/Order/OrderBusiness.cs @@ -947,7 +947,8 @@ namespace BBWY.Server.Business foreach (var relationOrderSku in orderDropShipping.RelationPurchaseOrderSkuList) { #region OrderSku - var updateOrderSku = fsql.Update(relationOrderSku.Id).Set(osku => osku.OrderDropShippingId, orderDropShipping.Id); + var updateOrderSku = fsql.Update().Set(osku => osku.OrderDropShippingId, orderDropShipping.Id) + .Where(osku => osku.SkuId == relationOrderSku.SkuId && osku.OrderId == dbOrder.Id); updateOrderSkuList.Add(updateOrderSku); #endregion @@ -1059,6 +1060,14 @@ namespace BBWY.Server.Business fsql.Insert(insertOrderCostDetailList).ExecuteAffrows(); insertOrderCost?.ExecuteAffrows(); updateOrderCost?.ExecuteAffrows(); + + if (dbOrder.StorageType != Enums.StorageType.代发) + { + fsql.Update(dbOrder.Id) + .Set(o => o.StorageType, Enums.StorageType.代发) + .SetIf(dbOrder.OrderState == Enums.OrderState.等待采购, o => o.OrderState, Enums.OrderState.待出库) + .ExecuteAffrows(); + } }); } diff --git a/BBWY.Server.Model/Dto/Request/Order/OrderDropShippingRequest.cs b/BBWY.Server.Model/Dto/Request/Order/OrderDropShippingRequest.cs index b82fd82d..7ce7c9cc 100644 --- a/BBWY.Server.Model/Dto/Request/Order/OrderDropShippingRequest.cs +++ b/BBWY.Server.Model/Dto/Request/Order/OrderDropShippingRequest.cs @@ -11,8 +11,6 @@ namespace BBWY.Server.Model.Dto public class RelationPurchaseOrderSkuRequestV2 { - public long Id { get; set; } - public string ProductId { get; set; } public string SkuId { get; set; }