diff --git a/BBWYB.Client/App.xaml.cs b/BBWYB.Client/App.xaml.cs index 5a4d83d..bcd661a 100644 --- a/BBWYB.Client/App.xaml.cs +++ b/BBWYB.Client/App.xaml.cs @@ -75,6 +75,7 @@ namespace BBWYB.Client serviceCollection.BatchRegisterServices(new Assembly[] { Assembly.Load("BBWYB.Client") }, typeof(IDenpendency)); serviceCollection.AddTransient(); serviceCollection.AddTransient(); + serviceCollection.AddTransient(); serviceCollection.AddMapper(new MappingProfile()); ServiceProvider = serviceCollection.BuildServiceProvider(); base.OnStartup(e); diff --git a/BBWYB.Client/Models/APIModel/Response/Order/OrderSkuResponse.cs b/BBWYB.Client/Models/APIModel/Response/Order/OrderSkuResponse.cs index 90b3bc0..e811252 100644 --- a/BBWYB.Client/Models/APIModel/Response/Order/OrderSkuResponse.cs +++ b/BBWYB.Client/Models/APIModel/Response/Order/OrderSkuResponse.cs @@ -1,41 +1,42 @@ -using System; +using CommunityToolkit.Mvvm.ComponentModel; +using System; namespace BBWYB.Client.Models { - public class OrderSkuResponse + public class OrderSkuResponse : ObservableObject { - public long Id { get; set; } + public long Id { get; set; } - public DateTime? CreateTime { get; set; } + public DateTime? CreateTime { get; set; } - /// - /// 销售数量 - /// - public int ItemTotal { get; set; } + /// + /// 销售数量 + /// + public int ItemTotal { get; set; } - /// - /// Logo - /// + /// + /// Logo + /// - public string Logo { get; set; } + public string Logo { get; set; } - public string OrderId { get; set; } + public string OrderId { get; set; } - /// - /// 销售单价 - /// - public decimal? Price { get; set; } + /// + /// 销售单价 + /// + public decimal? Price { get; set; } - public string ProductId { get; set; } + public string ProductId { get; set; } - public string SkuId { get; set; } + public string SkuId { get; set; } - /// - /// Sku标题 - /// - public string Title { get; set; } - } + /// + /// Sku标题 + /// + public string Title { get; set; } + } } diff --git a/BBWYB.Client/Models/Order/OrderSkuEditPrice.cs b/BBWYB.Client/Models/Order/OrderSkuEditPrice.cs new file mode 100644 index 0000000..929b0a2 --- /dev/null +++ b/BBWYB.Client/Models/Order/OrderSkuEditPrice.cs @@ -0,0 +1,30 @@ +using System; + +namespace BBWYB.Client.Models +{ + public class OrderSkuEditPrice : OrderSku + { + private decimal newPrice; + private decimal freightAmount; + private bool isResponseFreightChanged; + + public decimal NewPrice { get => newPrice; set { SetProperty(ref newPrice, value); } } + + public decimal FreightAmount + { + get => freightAmount; + set + { + if (SetProperty(ref freightAmount, value)) + { + IsResponseFreightChanged = false; + OnFreightChanged?.Invoke(); + } + } + } + + public bool IsResponseFreightChanged { get => isResponseFreightChanged; set { SetProperty(ref isResponseFreightChanged, value); } } + + public Action OnFreightChanged { get; set; } + } +} diff --git a/BBWYB.Client/ViewModels/Order/EditPriceViewModel.cs b/BBWYB.Client/ViewModels/Order/EditPriceViewModel.cs new file mode 100644 index 0000000..6d11ee9 --- /dev/null +++ b/BBWYB.Client/ViewModels/Order/EditPriceViewModel.cs @@ -0,0 +1,72 @@ +using BBWYB.Client.Models; +using CommunityToolkit.Mvvm.Input; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows; +using System.Windows.Input; + +namespace BBWYB.Client.ViewModels +{ + public class EditPriceViewModel : BaseVM + { + public IList OrderSkuList { get; set; } + private Order order; + private decimal freightAmount; + private bool isResponseFreightChanged; + + public ICommand DistributFreightCommand { get; set; } + public decimal FreightAmount { get => freightAmount; set { SetProperty(ref freightAmount, value); } } + + public EditPriceViewModel() + { + OrderSkuList = new ObservableCollection(); + DistributFreightCommand = new RelayCommand(DistributFreight); + } + + private void SetData(Order order) + { + this.order = order; + foreach (var orderSku in order.ItemList) + { + OrderSkuList.Add(new OrderSkuEditPrice() + { + Id = orderSku.Id, + Logo = orderSku.Logo, + Title = orderSku.Title, + SkuId = orderSku.SkuId, + Price = orderSku.Price, + NewPrice = orderSku.Price ?? 0, + ItemTotal = orderSku.ItemTotal, + OnFreightChanged = OnFreightChanged + }); + } + } + + private void DistributFreight() + { + if (FreightAmount <= 0) + { + MessageBox.Show("运费不正确", "提示"); + return; + } + isResponseFreightChanged = false; + var totalItemCount = OrderSkuList.Sum(s => s.ItemTotal); + foreach (var orderSku in OrderSkuList) + { + var quantityRatio = 1M * orderSku.ItemTotal / totalItemCount; + var currentFreightAmount = FreightAmount * quantityRatio; + orderSku.FreightAmount = currentFreightAmount; + orderSku.IsResponseFreightChanged = true; + } + isResponseFreightChanged = true; + } + + private void OnFreightChanged() + { + if (!isResponseFreightChanged) + return; + + } + } +} diff --git a/BBWYB.Client/ViewModels/ViewModelLocator.cs b/BBWYB.Client/ViewModels/ViewModelLocator.cs index 3a288df..16d3362 100644 --- a/BBWYB.Client/ViewModels/ViewModelLocator.cs +++ b/BBWYB.Client/ViewModels/ViewModelLocator.cs @@ -97,5 +97,16 @@ namespace BBWYB.Client.ViewModels } } } + + public EditPriceViewModel EditPrice + { + get + { + using (var s = sp.CreateScope()) + { + return s.ServiceProvider.GetRequiredService(); + } + } + } } } diff --git a/BBWYB.Client/Views/Order/EditPrice.xaml b/BBWYB.Client/Views/Order/EditPrice.xaml new file mode 100644 index 0000000..ed182a4 --- /dev/null +++ b/BBWYB.Client/Views/Order/EditPrice.xaml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BBWYB.Client/Views/Order/EditPrice.xaml.cs b/BBWYB.Client/Views/Order/EditPrice.xaml.cs new file mode 100644 index 0000000..018940e --- /dev/null +++ b/BBWYB.Client/Views/Order/EditPrice.xaml.cs @@ -0,0 +1,16 @@ +using BBWYB.Client.Models; +using SJ.Controls; + +namespace BBWYB.Client.Views.Order +{ + /// + /// EditPrice.xaml 的交互逻辑 + /// + public partial class EditPrice : BWindow + { + public EditPrice(Models.Order order) + { + InitializeComponent(); + } + } +} diff --git a/BBWYB.Server.Business/Order/OrderBusiness.cs b/BBWYB.Server.Business/Order/OrderBusiness.cs index 91b1805..3781ba1 100644 --- a/BBWYB.Server.Business/Order/OrderBusiness.cs +++ b/BBWYB.Server.Business/Order/OrderBusiness.cs @@ -232,5 +232,64 @@ namespace BBWYB.Server.Business new Dictionary() { { "Authorization", $"{mdsToken}" } }, HttpMethod.Post); } + + public void EditPrice(OP_EditPriceRequest request) + { + var client = opPlatformClientFactory.GetClient((AdapterEnums.PlatformType)request.Platform); + client.EditPrice(new OP_EditPriceRequest() + { + AppKey = request.AppKey, + AppSecret = request.AppSecret, + AppToken = request.AppToken, + OrderId = request.OrderId, + EditItems = request.EditItems + }); + + var orderListResponse = client.GetOrderList(new OP_QueryOrderRequest() + { + AppKey = request.AppKey, + AppSecret = request.AppSecret, + AppToken = request.AppToken, + OrderId = request.OrderId, + PageIndex = 1, + PageSize = 1, + SortTimeField = AdapterEnums.SortTimeField.Modify, + SortType = AdapterEnums.SortType.Desc + }); + + var order = orderListResponse.Items.FirstOrDefault(); + var orderCost = fsql.Select(request.OrderId).ToOne(); + + //orderCost.Profit = dbOrder.OrderTotalPrice - + // orderCost.PurchaseAmount - + // orderCost.DeliveryExpressFreight; // -orderCost.PlatformCommissionAmount + + IList> updates_orderSku = new List>(); + foreach (var orderSku in order.OrderSkuList) + { + updates_orderSku.Add(fsql.Update(orderSku.Id).Set(osku => osku.Price, orderSku.SkuPrice)); + } + + fsql.Transaction(() => + { + fsql.Update(request.OrderId).Set(o => o.OrderTotalPrice, order.OrderTotalAmount) + .Set(o => o.OrderSellerPrice, order.OrderProductAmount) + .Set(o => o.FreightPrice, order.FreightAmount) + .ExecuteAffrows(); + if (orderCost != null) + fsql.Update(request.OrderId).Set(oc => oc.Profit, order.OrderTotalAmount - orderCost.PurchaseAmount - orderCost.DeliveryExpressFreight) + .ExecuteAffrows(); + + if (updates_orderSku.Count() > 0) + { + foreach (var update in updates_orderSku) + update.ExecuteAffrows(); + } + }); + + #region 通知C端 + + #endregion + } } } diff --git a/BBWYB.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs b/BBWYB.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs index deb9957..0ae2c13 100644 --- a/BBWYB.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs +++ b/BBWYB.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs @@ -293,8 +293,7 @@ namespace BBWYB.Server.Business PurchaseAmount = totalPurchaseAmount }; //orderCost.PlatformCommissionAmount = dbOrder.OrderSellerPrice * orderCost.PlatformCommissionRatio; - orderCost.Profit = dbOrder.OrderSellerPrice + - dbOrder.FreightPrice - + orderCost.Profit = dbOrder.OrderTotalPrice - orderCost.PurchaseAmount - orderCost.DeliveryExpressFreight; // -orderCost.PlatformCommissionAmount if (!isRepurchase) diff --git a/SDKAdapter/OperationPlatform/Client/Base/OP_PlatformClient.cs b/SDKAdapter/OperationPlatform/Client/Base/OP_PlatformClient.cs index e0c59ac..ffbc8f7 100644 --- a/SDKAdapter/OperationPlatform/Client/Base/OP_PlatformClient.cs +++ b/SDKAdapter/OperationPlatform/Client/Base/OP_PlatformClient.cs @@ -46,5 +46,10 @@ namespace SDKAdapter.OperationPlatform.Client { throw new NotImplementedException(); } + + public virtual void EditPrice(OP_EditPriceRequest request) + { + throw new NotImplementedException(); + } } } diff --git a/SDKAdapter/OperationPlatform/Client/Impl/OP_QuanTanClient.cs b/SDKAdapter/OperationPlatform/Client/Impl/OP_QuanTanClient.cs index e3cdd59..43e9de9 100644 --- a/SDKAdapter/OperationPlatform/Client/Impl/OP_QuanTanClient.cs +++ b/SDKAdapter/OperationPlatform/Client/Impl/OP_QuanTanClient.cs @@ -155,7 +155,9 @@ namespace SDKAdapter.OperationPlatform.Client Quantity = qtosku.Quantity, SkuLogo = qtosku.SkuInfo.Image, SkuPrice = qtosku.SkuInfo.Price, - SkuTitle = qtosku.SkuInfo.Title + SkuTitle = qtosku.SkuInfo.Title, + ProductAmount = qtosku.ProductPrice, + FreightAmount = qtosku.PostagePrice }).ToList(), DeliveryResponse = new OP_OrderDeliveryResponse() { @@ -199,5 +201,23 @@ namespace SDKAdapter.OperationPlatform.Client if (qtResponse.Status != 200) throw new Exception(qtResponse.Message); } + + public override void EditPrice(OP_EditPriceRequest request) + { + var qtResponse = supplier_OrderClient.EditPrice(new QuanTan_Supplier_EditPriceRequest() + { + editAdmin = request.AppToken, + orderId = request.OrderId, + orderProduct = request.EditItems.Select(item => new QuanTan_Supplier_EditPriceSkuRequest() + { + orderProductId = item.OrderSkuId, + postagePrice = item.Freight, + price = item.Price + }).ToList() + }, request.AppKey, request.AppSecret); + + if (qtResponse.Status != 200) + throw new Exception(qtResponse.Message); + } } } diff --git a/SDKAdapter/OperationPlatform/Models/Request/Order/OP_EditPriceRequest.cs b/SDKAdapter/OperationPlatform/Models/Request/Order/OP_EditPriceRequest.cs new file mode 100644 index 0000000..9cbe0b2 --- /dev/null +++ b/SDKAdapter/OperationPlatform/Models/Request/Order/OP_EditPriceRequest.cs @@ -0,0 +1,35 @@ +namespace SDKAdapter.OperationPlatform.Models +{ + public class OP_EditPriceRequest : BasePlatformRequest + { + public string OrderId { get; set; } + + public IList EditItems { get; set; } + } + + public class OP_EditPriceSkuRequest + { + /// + /// 订单Sku商品Id + /// + public string OrderSkuId { get; set; } + + + public string SkuId { get; set; } + + /// + /// 单价 + /// + public decimal Price { get; set; } + + /// + /// 数量 + /// + public int Quantity { get; set; } + + /// + /// 运费 + /// + public decimal Freight { get; set; } + } +} diff --git a/SDKAdapter/OperationPlatform/Models/Response/Order/OP_EditPriceResponse.cs b/SDKAdapter/OperationPlatform/Models/Response/Order/OP_EditPriceResponse.cs new file mode 100644 index 0000000..adccbc9 --- /dev/null +++ b/SDKAdapter/OperationPlatform/Models/Response/Order/OP_EditPriceResponse.cs @@ -0,0 +1,22 @@ +namespace SDKAdapter.OperationPlatform.Models +{ + public class OP_EditPriceResponse + { + public string OrderId { get; set; } + + /// + /// 订单总价 + /// + public decimal OrderTotalAmount { get; set; } + + /// + /// 订单货款 + /// + public decimal OrderProductAmount { get; set; } + + /// + /// 运费 + /// + public decimal FreightAmount { get; set; } + } +} diff --git a/SDKAdapter/OperationPlatform/Models/Response/Order/OP_OrderProductSkuResponse.cs b/SDKAdapter/OperationPlatform/Models/Response/Order/OP_OrderProductSkuResponse.cs index b2c246d..1bab393 100644 --- a/SDKAdapter/OperationPlatform/Models/Response/Order/OP_OrderProductSkuResponse.cs +++ b/SDKAdapter/OperationPlatform/Models/Response/Order/OP_OrderProductSkuResponse.cs @@ -31,5 +31,9 @@ /// 购买数量 /// public int Quantity { get; set; } + + public decimal ProductAmount { get; set; } + + public decimal FreightAmount { get; set; } } }