diff --git a/BBWY.Client/App.xaml.cs b/BBWY.Client/App.xaml.cs index 2dca752c..ed5c0cd0 100644 --- a/BBWY.Client/App.xaml.cs +++ b/BBWY.Client/App.xaml.cs @@ -120,7 +120,8 @@ namespace BBWY.Client serviceCollection.AddTransient<_1688PreviewPurchaseViewModel>(); serviceCollection.AddTransient(); - + serviceCollection.AddTransient(); + serviceCollection.AddTransient(); #region 注册拳探SDK相关类 serviceCollection.AddSingleton(); diff --git a/BBWY.Client/Models/APIModel/Response/BatchPurchase/ProductSkuWithSchemeResponse.cs b/BBWY.Client/Models/APIModel/Response/BatchPurchase/ProductSkuWithSchemeResponse.cs new file mode 100644 index 00000000..675dab4f --- /dev/null +++ b/BBWY.Client/Models/APIModel/Response/BatchPurchase/ProductSkuWithSchemeResponse.cs @@ -0,0 +1,40 @@ +using System; + +namespace BBWY.Client.Models +{ + /// + /// 包含采购方案的Sku商品信息 + /// + public class ProductSkuWithSchemeResponse + { + public string Id { get; set; } + + public string ProductId { get; set; } + + public string SkuId { get; set; } + + public decimal Price { get; set; } + + /// + /// Sku标题 + /// + public string Title { get; set; } + + public string Logo { get; set; } + + /// + /// 京东Sku状态【1:上架 2:下架 4:删除】 + /// + public int State { get; set; } + + public DateTime? CreateTime { get; set; } + + public long PurchaseSchemeId { get; set; } + + public string PurchaserId { get; set; } + + public string PurchaseName { get; set; } + + public Platform? PurchasePlatform { get; set; } + } +} diff --git a/BBWY.Client/Models/BatchPurchase/ProductSkuWithScheme.cs b/BBWY.Client/Models/BatchPurchase/ProductSkuWithScheme.cs new file mode 100644 index 00000000..e4836ff8 --- /dev/null +++ b/BBWY.Client/Models/BatchPurchase/ProductSkuWithScheme.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace BBWY.Client.Models +{ + public class ProductSkuWithScheme : NotifyObject + { + private int quantity; + public string Id { get; set; } + + public string SkuId { get; set; } + + public string ProductId { get; set; } + + public decimal Price { get; set; } + + /// + /// Sku标题 + /// + public string Title { get; set; } + + public string Logo { get; set; } + + /// + /// 京东Sku状态【1:上架 2:下架 4:删除】 + /// + public int State { get; set; } + + public DateTime? CreateTime { get; set; } + + public long PurchaseSchemeId { get; set; } + + public string PurchaserId { get; set; } + + public string PurchaseName { get; set; } + + public Platform? PurchasePlatform { get; set; } + + public int Quantity { get => quantity; set { Set(ref quantity, value); } } + + public IList PurchaseSchemeProductSkuList { get; set; } + + public ProductSkuWithScheme() + { + PurchaseSchemeProductSkuList = new ObservableCollection(); + } + } +} diff --git a/BBWY.Client/ViewModels/BatchPurchase/BatchPurchaseAddProductSkuViewModel.cs b/BBWY.Client/ViewModels/BatchPurchase/BatchPurchaseAddProductSkuViewModel.cs new file mode 100644 index 00000000..53757b1b --- /dev/null +++ b/BBWY.Client/ViewModels/BatchPurchase/BatchPurchaseAddProductSkuViewModel.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace BBWY.Client.ViewModels +{ + public class BatchPurchaseAddProductSkuViewModel : BaseVM + { + } +} diff --git a/BBWY.Client/ViewModels/BatchPurchase/BatchPurchaseCreateNewOrderViewModel.cs b/BBWY.Client/ViewModels/BatchPurchase/BatchPurchaseCreateNewOrderViewModel.cs new file mode 100644 index 00000000..380fd365 --- /dev/null +++ b/BBWY.Client/ViewModels/BatchPurchase/BatchPurchaseCreateNewOrderViewModel.cs @@ -0,0 +1,198 @@ +using BBWY.Client.APIServices; +using BBWY.Client.Models; +using BBWY.Client.Views.BatchPurchase; +using GalaSoft.MvvmLight.Command; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; + +namespace BBWY.Client.ViewModels +{ + public class BatchPurchaseCreateNewOrderViewModel : BaseVM + { + private PurchaseProductAPIService purchaseProductAPIService; + + private bool isLoading; + private decimal productAmount; + private decimal freightAmount; + private decimal totalAmount; + private string contactName; + private string address; + private string mobile; + private string province; + private string city; + private string county; + private string town; + private string prucahseRemark; + private PurchaseOrderMode purchaseOrderMode = PurchaseOrderMode.代发; + public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } } + + public decimal ProductAmount { get => productAmount; set { Set(ref productAmount, value); } } + public decimal FreightAmount { get => freightAmount; set { Set(ref freightAmount, value); } } + public decimal TotalAmount { get => totalAmount; set { Set(ref totalAmount, value); } } + public string ContactName { get => contactName; set { Set(ref contactName, value); } } + public string Address { get => address; set { Set(ref address, value); } } + public string Mobile { get => mobile; set { Set(ref mobile, value); } } + public string Province { get => province; set { Set(ref province, value); } } + public string City { get => city; set { Set(ref city, value); } } + public string County { get => county; set { Set(ref county, value); } } + public string Town { get => town; set { Set(ref town, value); } } + public string PrucahseRemark { get => prucahseRemark; set { Set(ref prucahseRemark, value); } } + + public PurchaseOrderMode PurchaseOrderMode + { + get => purchaseOrderMode; set + { + if (Set(ref purchaseOrderMode, value)) + OnDelayTriggerExecute(Guid.NewGuid().ToString()); + } + } + public IList ProductSkuWithSchemeList { get; set; } + + + public ICommand FastCreateOrderCommand { get; set; } + public ICommand PreviewOrderCommand { get; set; } + public ICommand AddProductSkuCommand { get; set; } + + public BatchPurchaseCreateNewOrderViewModel(PurchaseProductAPIService purchaseProductAPIService) + { + this.purchaseProductAPIService = purchaseProductAPIService; + ProductSkuWithSchemeList = new ObservableCollection(); + + FastCreateOrderCommand = new RelayCommand(FastCreateOrder); + PreviewOrderCommand = new RelayCommand(PreviewOrder); + AddProductSkuCommand = new RelayCommand(AddProductSku); + } + + private void OnDelayTriggerExecute(string key) + { + if (string.IsNullOrEmpty(key)) + { + IsLoading = false; + return; + } + + if (string.IsNullOrEmpty(ContactName) || + string.IsNullOrEmpty(Address) || + string.IsNullOrEmpty(Mobile) || + string.IsNullOrEmpty(Province) || + string.IsNullOrEmpty(City) || + string.IsNullOrEmpty(County)) + { + IsLoading = false; + MessageBox.Show("缺少完整的收货信息", "提示"); + return; + } + + //IsLoading = true; + //Task.Factory.StartNew(() => purchaseOrderService.PreviewPurchaseOrder(new Consignee() + //{ + // Address = Address, + // City = City, + // ContactName = ContactName, + // County = County, + // Mobile = Mobile, + // Province = Province, + // TelePhone = Mobile, + // Town = Town + //}, PurchaseSchemeProductSkuList, purchaseAccount.PurchasePlatformId, purchaseAccount, PurchaseOrderMode)) + // .ContinueWith(t => + // { + // IsLoading = false; + // var r = t.Result; + // if (!r.Success) + // { + // ProductAmount = FreightAmount = TotalAmount = 0; + // tradeMode = string.Empty; + // App.Current.Dispatcher.Invoke(() => MessageBox.Show(r.Msg, "预览订单报价")); + // return; + // } + // ProductAmount = r.Data.ProductAmount; + // FreightAmount = r.Data.FreightAmount; + // TotalAmount = r.Data.TotalAmount; + // tradeMode = r.Data.OrderTradeType?.Code; + // extensions = r.Data.Extensions; + // }); + } + + private void PreviewOrder() + { + OnDelayTriggerExecute(Guid.NewGuid().ToString()); + } + + private void FastCreateOrder() + { + if (IsLoading) + return; + if (TotalAmount == 0) + { + MessageBox.Show("总金额为0不能提交订单", "提示"); + return; + } + if (string.IsNullOrEmpty(Mobile) || + string.IsNullOrEmpty(Address) || + string.IsNullOrEmpty(City) || + string.IsNullOrEmpty(Province) || + string.IsNullOrEmpty(County) || + string.IsNullOrEmpty(Town) || + string.IsNullOrEmpty(ContactName)) + { + MessageBox.Show("收货人信息不全", "下单"); + return; + } + + //IsLoading = true; + //Task.Factory.StartNew(() => purchaseOrderService.FastCreateOrder(new Consignee() + //{ + // Address = Address, + // City = City, + // ContactName = ContactName, + // County = County, + // Mobile = Mobile, + // Province = Province, + // TelePhone = Mobile, + // Town = Town + //}, PurchaseSchemeProductSkuList, + // purchaseAccount.PurchasePlatformId, + // purchaseAccount, + // PurchaseOrderMode, + // tradeMode, + // PrucahseRemark, + // order.Id, + // globalContext.User.Shop.ShopId, + // purchaseAccount.Id, + // purchaseAccount.AccountName, + // purchaseSchemeList[0].PurchaserName, + // purchaser.Id, + // globalContext.User.Shop.PlatformCommissionRatio ?? 0.05M, + // extensions)).ContinueWith(t => + // { + // IsLoading = false; + // var r = t.Result; + // if (!r.Success) + // { + // App.Current.Dispatcher.Invoke(() => MessageBox.Show(r.Msg, "下单")); + // return; + // } + + // //刷新订单列表 + // orderListViewModel.RefreshOrder(order.Id); + + // //关闭当前窗口 + // GalaSoft.MvvmLight.Messaging.Messenger.Default.Send(null, "OnlinePurchase_Close"); + // }); + } + + private void AddProductSku() + { + var addProductSkuWindow = new BatchPurchaseAddProductSku(); + if (addProductSkuWindow.ShowDialog() == true) + { + + } + } + } +} diff --git a/BBWY.Client/ViewModels/BatchPurchase/BatchPurchaseOrderListViewModel.cs b/BBWY.Client/ViewModels/BatchPurchase/BatchPurchaseOrderListViewModel.cs index d7b22ff7..ad5514d4 100644 --- a/BBWY.Client/ViewModels/BatchPurchase/BatchPurchaseOrderListViewModel.cs +++ b/BBWY.Client/ViewModels/BatchPurchase/BatchPurchaseOrderListViewModel.cs @@ -1,4 +1,5 @@ using BBWY.Client.Models; +using BBWY.Client.Views.BatchPurchase; using BBWY.Common.Models; using GalaSoft.MvvmLight.Command; using System; @@ -78,8 +79,12 @@ namespace BBWY.Client.ViewModels } private void OpenCreateNewPurchaseOrderDialog() - { - + { + var createWindow = new BatchCreateNewPurchaseOrder(); + if (createWindow.ShowDialog() == true) + { + InitQueryPurchaseOrder(); //刷新采购单页面 + } } } } diff --git a/BBWY.Client/ViewModels/MainViewModel.cs b/BBWY.Client/ViewModels/MainViewModel.cs index 239e06b3..aa957f9d 100644 --- a/BBWY.Client/ViewModels/MainViewModel.cs +++ b/BBWY.Client/ViewModels/MainViewModel.cs @@ -386,7 +386,8 @@ namespace BBWY.Client.ViewModels vm.WareManager.Refresh(); if (vm.IsCreateWareStock) vm.WareStock.Refresh(); - + if(vm.IsCreateBatchPurchaseOrderList) + vm.BatchPurchaseOrderListVM.Refresh(); try { w2m.Close(); diff --git a/BBWY.Client/ViewModels/ViewModelLocator.cs b/BBWY.Client/ViewModels/ViewModelLocator.cs index 00d7dcc5..822de160 100644 --- a/BBWY.Client/ViewModels/ViewModelLocator.cs +++ b/BBWY.Client/ViewModels/ViewModelLocator.cs @@ -16,8 +16,8 @@ namespace BBWY.Client.ViewModels public bool IsCreateWareStock { get; private set; } public bool IsCreateOrderList { get; private set; } - - + public bool IsCreateBatchPurchaseOrderList { get; private set; } + @@ -112,7 +112,7 @@ namespace BBWY.Client.ViewModels { get { - + using (var s = sp.CreateScope()) { return s.ServiceProvider.GetRequiredService(); @@ -243,9 +243,28 @@ namespace BBWY.Client.ViewModels { get { + IsCreateBatchPurchaseOrderList = true; using var s = sp.CreateScope(); return s.ServiceProvider.GetRequiredService(); } } + + public BatchPurchaseCreateNewOrderViewModel BatchPurchaseCreateNewOrder + { + get + { + using var s = sp.CreateScope(); + return s.ServiceProvider.GetRequiredService(); + } + } + + public BatchPurchaseAddProductSkuViewModel BatchPurchaseAddProductSku + { + get + { + using var s = sp.CreateScope(); + return s.ServiceProvider.GetRequiredService(); + } + } } } diff --git a/BBWY.Client/Views/BatchPurchase/BatchCreateNewPurchaseOrder.xaml b/BBWY.Client/Views/BatchPurchase/BatchCreateNewPurchaseOrder.xaml new file mode 100644 index 00000000..68f92934 --- /dev/null +++ b/BBWY.Client/Views/BatchPurchase/BatchCreateNewPurchaseOrder.xaml @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BBWY.Client/Views/BatchPurchase/BatchCreateNewPurchaseOrder.xaml.cs b/BBWY.Client/Views/BatchPurchase/BatchCreateNewPurchaseOrder.xaml.cs new file mode 100644 index 00000000..37ddd453 --- /dev/null +++ b/BBWY.Client/Views/BatchPurchase/BatchCreateNewPurchaseOrder.xaml.cs @@ -0,0 +1,26 @@ +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.BatchPurchase +{ + /// + /// BatchCreateNewPurchaseOrder.xaml 的交互逻辑 + /// + public partial class BatchCreateNewPurchaseOrder : BWindow + { + public BatchCreateNewPurchaseOrder() + { + InitializeComponent(); + } + } +} diff --git a/BBWY.Client/Views/BatchPurchase/BatchPurchaseAddProductSku.xaml b/BBWY.Client/Views/BatchPurchase/BatchPurchaseAddProductSku.xaml new file mode 100644 index 00000000..a978de68 --- /dev/null +++ b/BBWY.Client/Views/BatchPurchase/BatchPurchaseAddProductSku.xaml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BBWY.Client/Views/BatchPurchase/BatchPurchaseAddProductSku.xaml.cs b/BBWY.Client/Views/BatchPurchase/BatchPurchaseAddProductSku.xaml.cs new file mode 100644 index 00000000..50c90f00 --- /dev/null +++ b/BBWY.Client/Views/BatchPurchase/BatchPurchaseAddProductSku.xaml.cs @@ -0,0 +1,26 @@ +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.BatchPurchase +{ + /// + /// BatchPurchaseAddProductSku.xaml 的交互逻辑 + /// + public partial class BatchPurchaseAddProductSku : BWindow + { + public BatchPurchaseAddProductSku() + { + InitializeComponent(); + } + } +} diff --git a/BBWY.Server.API/Controllers/BatchPurchaseController.cs b/BBWY.Server.API/Controllers/BatchPurchaseController.cs new file mode 100644 index 00000000..8abd8e29 --- /dev/null +++ b/BBWY.Server.API/Controllers/BatchPurchaseController.cs @@ -0,0 +1,29 @@ +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 BatchPurchaseController : BaseApiController + { + private BatchPurchaseBusiness batchPurchaseBusiness; + + public BatchPurchaseController(IHttpContextAccessor httpContextAccessor, BatchPurchaseBusiness batchPurchaseBusiness) : base(httpContextAccessor) + { + this.batchPurchaseBusiness = batchPurchaseBusiness; + } + + /// + /// 获取包含采购方案的sku列表 + /// + /// + /// + [HttpPost] + public IList GetProductSkuAndSchemeList([FromBody]SearchProductSkuAndSchemeRequest request) + { + return batchPurchaseBusiness.GetProductSkuAndSchemeList(request); + } + } +} diff --git a/BBWY.Server.Business/PurchaseOrderV2/BatchPurchase/BatchPurchaseBusiness.cs b/BBWY.Server.Business/PurchaseOrderV2/BatchPurchase/BatchPurchaseBusiness.cs index daa744b5..959b519e 100644 --- a/BBWY.Server.Business/PurchaseOrderV2/BatchPurchase/BatchPurchaseBusiness.cs +++ b/BBWY.Server.Business/PurchaseOrderV2/BatchPurchase/BatchPurchaseBusiness.cs @@ -1,8 +1,6 @@ -using BBWY.Common.Extensions; -using BBWY.Common.Models; +using BBWY.Common.Models; using BBWY.Server.Model.Db; using BBWY.Server.Model.Dto; -using BBWY.Server.Model.Dto.Response.PurchaseOrderV2; using System.Collections.Generic; using System.Linq; using Yitter.IdGenerator; @@ -43,7 +41,6 @@ namespace BBWY.Server.Business var skuIdList = productSkuList.Select(s => s.Id).ToList(); var schemeList = fsql.Select().InnerJoin((ps, p) => ps.PurchaserId == p.Id) .Where((ps, p) => ps.ShopId == request.ShopId) - .Where((ps, p) => ps.PurchasePlatform == request.PurchasePlatform) .Where((ps, p) => skuIdList.Contains(ps.SkuId)) .ToList((ps, p) => new { @@ -53,18 +50,60 @@ namespace BBWY.Server.Business ps.PurchasePlatform, ps.SkuId }); - var pruductSkuSchemeList = productSkuList.Map>(); - foreach (var ps in pruductSkuSchemeList) + var list = new List(); + foreach (var productSku in productSkuList) { - var scheme = schemeList.FirstOrDefault(s => s.SkuId == ps.Id); - if (scheme == null) - continue; - ps.PurchaseSchemeId = scheme.PurchaseSchemeId; - ps.PurchaserId = scheme.PurchaserId; - ps.PurchaseName = scheme.PurchaseName; - ps.PurchasePlatform = scheme.PurchasePlatform; + var currentSchemeList = schemeList.Where(ps => ps.SkuId == productSku.Id).ToList(); + if (currentSchemeList == null || currentSchemeList.Count() == 0) + { + list.Add(new ProductSkuWithSchemeResponse() + { + Id = productSku.Id, + SkuId = productSku.Id, + ProductId = productSku.ProductId, + CreateTime = productSku.CreateTime, + Logo = productSku.Logo, + Price = productSku.Price, + Title = productSku.Title, + State = productSku.State + }); + } + else + { + foreach (var currentScheme in currentSchemeList) + { + list.Add(new ProductSkuWithSchemeResponse() + { + Id = $"{productSku.Id}_{currentScheme.PurchaseSchemeId}", + SkuId = productSku.Id, + ProductId = productSku.ProductId, + CreateTime = productSku.CreateTime, + Logo = productSku.Logo, + Price = productSku.Price, + Title = productSku.Title, + State = productSku.State, + PurchaseName = currentScheme.PurchaseName, + PurchasePlatform = currentScheme.PurchasePlatform, + PurchaserId = currentScheme.PurchaserId, + PurchaseSchemeId = currentScheme.PurchaseSchemeId + }); + } + } } - return pruductSkuSchemeList; + + + //var pruductSkuSchemeList = productSkuList.Map>(); + //foreach (var ps in pruductSkuSchemeList) + //{ + // var scheme = schemeList.FirstOrDefault(s => s.SkuId == ps.Id); + // if (scheme == null) + // continue; + // ps.PurchaseSchemeId = scheme.PurchaseSchemeId; + // ps.PurchaserId = scheme.PurchaserId; + // ps.PurchaseName = scheme.PurchaseName; + // ps.PurchasePlatform = scheme.PurchasePlatform; + //} + return list; } diff --git a/BBWY.Server.Model/Dto/Request/PurchaseOrderV2/BatchPurchase/SearchProductSkuAndSchemeRequest.cs b/BBWY.Server.Model/Dto/Request/PurchaseOrderV2/BatchPurchase/SearchProductSkuAndSchemeRequest.cs index fd767f04..7295673f 100644 --- a/BBWY.Server.Model/Dto/Request/PurchaseOrderV2/BatchPurchase/SearchProductSkuAndSchemeRequest.cs +++ b/BBWY.Server.Model/Dto/Request/PurchaseOrderV2/BatchPurchase/SearchProductSkuAndSchemeRequest.cs @@ -7,7 +7,5 @@ public string Spu { get; set; } public string Sku { get; set; } - - public Enums.Platform PurchasePlatform { get; set; } } } diff --git a/BBWY.Server.Model/Dto/Response/PurchaseOrderV2/BatchPurchase/ProductSkuWithSchemeResponse.cs b/BBWY.Server.Model/Dto/Response/PurchaseOrderV2/BatchPurchase/ProductSkuWithSchemeResponse.cs index bdad83a1..ca140c1c 100644 --- a/BBWY.Server.Model/Dto/Response/PurchaseOrderV2/BatchPurchase/ProductSkuWithSchemeResponse.cs +++ b/BBWY.Server.Model/Dto/Response/PurchaseOrderV2/BatchPurchase/ProductSkuWithSchemeResponse.cs @@ -1,16 +1,40 @@ -namespace BBWY.Server.Model.Dto +using System; + +namespace BBWY.Server.Model.Dto { /// /// 包含采购方案的Sku商品信息 /// - public class ProductSkuWithSchemeResponse : ProductSkuResponse + public class ProductSkuWithSchemeResponse { + public string Id { get; set; } + + public string SkuId { get; set; } + + public string ProductId { get; set; } + + public decimal Price { get; set; } + + /// + /// Sku标题 + /// + public string Title { get; set; } + + public string Logo { get; set; } + + /// + /// 京东Sku状态【1:上架 2:下架 4:删除】 + /// + public int State { get; set; } + + public DateTime? CreateTime { get; set; } + public long PurchaseSchemeId { get; set; } public string PurchaserId { get; set; } public string PurchaseName { get; set; } - public Enums.Platform PurchasePlatform { get; set; } + public Enums.Platform? PurchasePlatform { get; set; } } }