diff --git a/BBWY.Client/APIServices/OrderService.cs b/BBWY.Client/APIServices/OrderService.cs index 5e7e8a5d..f6c20e06 100644 --- a/BBWY.Client/APIServices/OrderService.cs +++ b/BBWY.Client/APIServices/OrderService.cs @@ -2,6 +2,7 @@ using BBWY.Common.Http; using BBWY.Common.Models; using System; +using System.Collections.Generic; using System.Net.Http; namespace BBWY.Client.APIServices @@ -21,8 +22,12 @@ namespace BBWY.Client.APIServices string productNo, string waybill, string contactName, - int pageIndex, int pageSize, - long shopId) + int pageIndex, + int pageSize, + long shopId, + bool onlyDF, + bool excludeSD, + bool excludeCanceled) { return SendRequest(globalContext.BBYWApiHost, "api/order/getOrderList", new { @@ -36,7 +41,10 @@ namespace BBWY.Client.APIServices sku, productNo, waybill, - contactName + contactName, + onlyDF, + excludeSD, + excludeCanceled }, null, HttpMethod.Post); } @@ -125,5 +133,20 @@ namespace BBWY.Client.APIServices AppToken = globalContext.User.Shop.AppToken }, null, HttpMethod.Post); } + + /// + /// 关联代发订单 + /// + /// + /// + /// + public ApiResponse RelationPurchaseOrder(OrderDropShipping orderDropShipping, IList relationPurchaseOrderSkuList) + { + return SendRequest(globalContext.BBYWApiHost, "api/order/RelationPurchaseOrder", new + { + orderDropShipping, + relationPurchaseOrderSkuList + }, null, HttpMethod.Post); + } } } diff --git a/BBWY.Client/App.xaml.cs b/BBWY.Client/App.xaml.cs index 2c6fa466..6f33d3a5 100644 --- a/BBWY.Client/App.xaml.cs +++ b/BBWY.Client/App.xaml.cs @@ -1,4 +1,5 @@ using BBWY.Client.Models; +using BBWY.Client.ViewModels; using BBWY.Common.Extensions; using BBWY.Common.Http; using BBWY.Common.Models; @@ -42,9 +43,6 @@ namespace BBWY.Client serviceCollection.AddHttpClient(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(gl); - //serviceCollection.AddSingleton(); - //serviceCollection.AddSingleton(); - //serviceCollection.AddSingleton(); serviceCollection.BatchRegisterServices(new Assembly[] { Assembly.Load("BBWY.Client") }, typeof(IDenpendency)); serviceCollection.AddMapper(new MappingProfile()); diff --git a/BBWY.Client/BBWY.Client.csproj b/BBWY.Client/BBWY.Client.csproj index 9a656c9d..0293431a 100644 --- a/BBWY.Client/BBWY.Client.csproj +++ b/BBWY.Client/BBWY.Client.csproj @@ -15,6 +15,13 @@ x64 + + + + + + + @@ -51,8 +58,4 @@ - - - - diff --git a/BBWY.Client/Models/APIModel/Response/Order/OrderDropShippingResponse.cs b/BBWY.Client/Models/APIModel/Response/Order/OrderDropShippingResponse.cs new file mode 100644 index 00000000..cda733ee --- /dev/null +++ b/BBWY.Client/Models/APIModel/Response/Order/OrderDropShippingResponse.cs @@ -0,0 +1,19 @@ +namespace BBWY.Client.Models +{ + public class OrderDropShippingResponse + { + public string OrderId { get; set; } + + public string BuyerAccount { get; set; } + + public decimal DeliveryFreight { get; set; } + + public decimal PurchaseAmount { get; set; } + + public string PurchaseOrderId { get; set; } + + public Platform? PurchasePlatform { get; set; } + + public string SellerAccount { get; set; } + } +} diff --git a/BBWY.Client/Models/APIModel/Response/Order/OrderResponse.cs b/BBWY.Client/Models/APIModel/Response/Order/OrderResponse.cs index 470a7f13..446e7072 100644 --- a/BBWY.Client/Models/APIModel/Response/Order/OrderResponse.cs +++ b/BBWY.Client/Models/APIModel/Response/Order/OrderResponse.cs @@ -134,6 +134,11 @@ namespace BBWY.Client.Models /// 订单成本明细列表 /// public IList OrderCostDetailList { get; set; } + + /// + /// 代发信息 + /// + public OrderDropShippingResponse OrderDropShipping { get; set; } } public class OrderListResponse diff --git a/BBWY.Client/Models/MappingProfile.cs b/BBWY.Client/Models/MappingProfile.cs index d6fdb973..54251f4c 100644 --- a/BBWY.Client/Models/MappingProfile.cs +++ b/BBWY.Client/Models/MappingProfile.cs @@ -6,6 +6,7 @@ namespace BBWY.Client.Models { public MappingProfile() { + CreateMap(); CreateMap(); CreateMap(); CreateMap(); diff --git a/BBWY.Client/Models/Order/Order.cs b/BBWY.Client/Models/Order/Order.cs index 05e08e6e..ab902ed3 100644 --- a/BBWY.Client/Models/Order/Order.cs +++ b/BBWY.Client/Models/Order/Order.cs @@ -156,6 +156,11 @@ namespace BBWY.Client.Models /// public IList OrderCostDetailGroupList { get; set; } + /// + /// 代发信息 + /// + public OrderDropShipping OrderDropShipping { get; set; } + public void ConvertOrderCostDetailToGroup() { if (OrderCostDetailList == null || OrderCostDetailList.Count() == 0) diff --git a/BBWY.Client/Models/Order/OrderDropShipping.cs b/BBWY.Client/Models/Order/OrderDropShipping.cs new file mode 100644 index 00000000..cc552b2a --- /dev/null +++ b/BBWY.Client/Models/Order/OrderDropShipping.cs @@ -0,0 +1,22 @@ +namespace BBWY.Client.Models +{ + public class OrderDropShipping : NotifyObject + { + public string OrderId { get; set; } + public string BuyerAccount { get => buyerAccount; set { Set(ref buyerAccount, value); } } + public string SellerAccount { get => sellerAccount; set { Set(ref sellerAccount, value); } } + public decimal DeliveryFreight { get => deliveryFreight; set { Set(ref deliveryFreight, value); } } + public string PurchaseOrderId { get => purchaseOrderId; set { Set(ref purchaseOrderId, value); } } + public Platform PurchasePlatform { get => purchasePlatform; set { Set(ref purchasePlatform, value); } } + public decimal PurchaseAmount { get => purchaseAmount; set { Set(ref purchaseAmount, value); } } + + private string buyerAccount; + private string sellerAccount; + private decimal deliveryFreight; + private string purchaseOrderId; + private Platform purchasePlatform; + private decimal purchaseAmount; + + + } +} diff --git a/BBWY.Client/Models/Order/RelationPurchaseOrderSku.cs b/BBWY.Client/Models/Order/RelationPurchaseOrderSku.cs new file mode 100644 index 00000000..177f0f43 --- /dev/null +++ b/BBWY.Client/Models/Order/RelationPurchaseOrderSku.cs @@ -0,0 +1,45 @@ +using Newtonsoft.Json; +using System; + +namespace BBWY.Client.Models +{ + public class RelationPurchaseOrderSku : NotifyObject + { + private decimal singleSkuAmount; + private decimal skuAmount; + + public string ProductId { get; set; } + + public string SkuId { get; set; } + + public string Logo { get; set; } + + public int Quantity { get; set; } + + public string Title { get; set; } + + public decimal SingleSkuAmount + { + get => singleSkuAmount; + set + { + if (Set(ref singleSkuAmount, value)) + SkuAmount = SingleSkuAmount * Quantity; + + } + } + + public decimal SkuAmount + { + get => skuAmount; + set + { + if (Set(ref skuAmount, value)) + OnSkuAmountChanged?.Invoke(); + } + } + + [JsonIgnore] + public Action OnSkuAmountChanged { get; set; } + } +} diff --git a/BBWY.Client/ViewModels/MainViewModel.cs b/BBWY.Client/ViewModels/MainViewModel.cs index aa0968e8..5439ffb0 100644 --- a/BBWY.Client/ViewModels/MainViewModel.cs +++ b/BBWY.Client/ViewModels/MainViewModel.cs @@ -124,7 +124,7 @@ namespace BBWY.Client.ViewModels // Platform = Platform.京东, // AppKey = "120EA9EC65AB017567D78CC1139EEEA5", // AppSecret = "866a9877f5f24b03b537483b4defe75d", - // AppToken = "d8433fb2a4994484b5d9e5a5896a6dfdmyjj" //d202f5eaf1c041dbbe2630363c6151eadiwm,8241a17cb2ae4d0db88b47a399dce22edi0m + // AppToken = "d8433fb2a4994484b5d9e5a5896a6dfdmyjj" //10388155 // } //}; diff --git a/BBWY.Client/ViewModels/Order/OrderListViewModel.cs b/BBWY.Client/ViewModels/Order/OrderListViewModel.cs index b3f65666..6738fc4e 100644 --- a/BBWY.Client/ViewModels/Order/OrderListViewModel.cs +++ b/BBWY.Client/ViewModels/Order/OrderListViewModel.cs @@ -35,6 +35,9 @@ namespace BBWY.Client.ViewModels private string searchProductNo; private string searchContactName; private string searchWaybill; + private bool onlyDF; + private bool excludeSD; + private bool excludeCanceled; private Random random; private GlobalContext globalContext; @@ -62,6 +65,10 @@ namespace BBWY.Client.ViewModels public string SearchContactName { get => searchContactName; set { Set(ref searchContactName, value); } } public string SearchWaybill { get => searchWaybill; set { Set(ref searchWaybill, value); } } + public bool OnlyDF { get => onlyDF; set { Set(ref onlyDF, value); } } + public bool ExcludeSD { get => excludeSD; set { Set(ref excludeSD, value); } } + public bool ExcludeCanceled { get => excludeCanceled; set { Set(ref excludeCanceled, value); } } + public ToDayOrderAchievement ToDayOrderAchievement { get; set; } public ICommand SetOrderStateCommand { get; set; } @@ -137,7 +144,7 @@ namespace BBWY.Client.ViewModels private void LoadOrder(int pageIndex) { IsLoading = true; - Thread.Sleep(random.Next(1000, 2000)); + Thread.Sleep(random.Next(500, 2000)); var response = orderService.GetOrderList(SearchOrderId, StartDate, EndDate, @@ -148,7 +155,10 @@ namespace BBWY.Client.ViewModels SearchContactName, pageIndex, pageSize, - globalContext.User.Shop.ShopId); + globalContext.User.Shop.ShopId, + OnlyDF, + ExcludeSD, + ExcludeCanceled); if (!response.Success) { IsLoading = false; @@ -221,6 +231,41 @@ namespace BBWY.Client.ViewModels sd.Closed += Sd_Closed; sd.ShowDialog(); } + else if (storageType == StorageType.代发) + { + var relationPurchaseOrder = new RelationPurchaseOrder(orderId, null, order.ItemList.Select(osku => new RelationPurchaseOrderSku() + { + Logo = osku.Logo, + ProductId = osku.ProductId, + SkuId = osku.Id, + Quantity = osku.ItemTotal, + Title = osku.Title + }).ToList()); + relationPurchaseOrder.Closed += RelationPurchaseOrder_Closed; + relationPurchaseOrder.ShowDialog(); + } + } + + 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)) + .ContinueWith(r => + { + var response = r.Result; + if (!response.Success) + { + IsLoading = false; + App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "关联采购订单")); + return; + } + LoadOrder(PageIndex); //手动计算成功刷新订单列表 + }); } private void Sd_Closed(object sender, EventArgs e) @@ -261,18 +306,32 @@ namespace BBWY.Client.ViewModels { if (order.StorageType == null) return; - if (order.StorageType != StorageType.SD) + if (order.StorageType == StorageType.代发) { - var calculationCostType = new ChooseCalculationCostType(order.Id, order.StorageType.Value, false); - calculationCostType.Closed += ChooseCalculationCostType_Closed; - calculationCostType.ShowDialog(); + var relationPurchaseOrder = new RelationPurchaseOrder(order.Id, order.OrderDropShipping, order.ItemList.Select(osku => new RelationPurchaseOrderSku() + { + Logo = osku.Logo, + ProductId = osku.ProductId, + SkuId = osku.Id, + Quantity = osku.ItemTotal, + Title = osku.Title, + SingleSkuAmount = (order.OrderCostDetailList.FirstOrDefault(ocd => ocd.SkuId == osku.Id)?.SkuAmount / osku.ItemTotal) ?? 0 + }).ToList()); + relationPurchaseOrder.Closed += RelationPurchaseOrder_Closed; + relationPurchaseOrder.ShowDialog(); } - else + else if (order.StorageType == StorageType.SD) { var sd = new SD(order.Id, false); sd.Closed += Sd_Closed; sd.ShowDialog(); } + else + { + var calculationCostType = new ChooseCalculationCostType(order.Id, order.StorageType.Value, false); + calculationCostType.Closed += ChooseCalculationCostType_Closed; + calculationCostType.ShowDialog(); + } } private void ChooseCalculationCostType_Closed(object sender, EventArgs e) diff --git a/BBWY.Client/Views/Order/OrderList.xaml b/BBWY.Client/Views/Order/OrderList.xaml index f149d212..0cdf1425 100644 --- a/BBWY.Client/Views/Order/OrderList.xaml +++ b/BBWY.Client/Views/Order/OrderList.xaml @@ -223,9 +223,9 @@ - - - + + + @@ -438,6 +438,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -644,6 +671,16 @@ CommandParameter="{Binding }" Margin="5,0,0,0"/> + + + + + + + + + + + + + + + diff --git a/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml b/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml new file mode 100644 index 00000000..2b3a5529 --- /dev/null +++ b/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml.cs b/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml.cs new file mode 100644 index 00000000..ef534cb2 --- /dev/null +++ b/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml.cs @@ -0,0 +1,56 @@ +using BBWY.Client.Models; +using BBWY.Controls; +using System.Collections.Generic; +using System.Linq; +using System.Windows; + +namespace BBWY.Client.Views.Order +{ + /// + /// RelationPurchaseOrder.xaml 的交互逻辑 + /// + public partial class RelationPurchaseOrder : BWindow + { + public OrderDropShipping OrderDropShipping { get; set; } + + public IList RelationPurchaseOrderSkuList { get; set; } + + public RelationPurchaseOrder(string orderId, OrderDropShipping orderDropShipping, IList relationPurchaseOrderSkuList) + { + InitializeComponent(); + this.DataContext = this; + OrderDropShipping = new OrderDropShipping() { OrderId = orderId }; + if (orderDropShipping != 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; + } + this.RelationPurchaseOrderSkuList = relationPurchaseOrderSkuList; + foreach (var sku in RelationPurchaseOrderSkuList) + sku.OnSkuAmountChanged = OnSkuAmountChanged; + } + + private void OnSkuAmountChanged() + { + OrderDropShipping.PurchaseAmount = RelationPurchaseOrderSkuList.Sum(sku => sku.SkuAmount); + } + + 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; + } + this.DialogResult = true; + this.Close(); + } + } +} diff --git a/BBWY.Server.API/Controllers/OrderController.cs b/BBWY.Server.API/Controllers/OrderController.cs index 91208b3e..31219f70 100644 --- a/BBWY.Server.API/Controllers/OrderController.cs +++ b/BBWY.Server.API/Controllers/OrderController.cs @@ -68,6 +68,16 @@ namespace BBWY.Server.API.Controllers orderBusiness.SDCalculationCost(sdCalculationCostRequest); } + /// + /// 关联采购单 + /// + /// + [HttpPost] + public void RelationPurchaseOrder([FromBody] RelationPurchaseOrderRequest relationPurchaseOrderRequest) + { + orderBusiness.RelationPurchaseOrder(relationPurchaseOrderRequest); + } + /// /// 订单同步 /// diff --git a/BBWY.Server.API/Controllers/TestController.cs b/BBWY.Server.API/Controllers/TestController.cs index a2fdf590..30494926 100644 --- a/BBWY.Server.API/Controllers/TestController.cs +++ b/BBWY.Server.API/Controllers/TestController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Http; +using BBWY.Server.Model.Db; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; @@ -7,9 +8,10 @@ namespace BBWY.Server.API.Controllers { public class TestController : BaseApiController { - public TestController(IHttpContextAccessor httpContextAccessor) : base(httpContextAccessor) + private IFreeSql fsql; + public TestController(IHttpContextAccessor httpContextAccessor, IFreeSql fsql) : base(httpContextAccessor) { - + this.fsql = fsql; } [HttpGet] @@ -22,5 +24,12 @@ namespace BBWY.Server.API.Controllers DateTime.Now.ToString() }; } + + [HttpGet("{orderId}")] + public decimal SumNoExists([FromRoute] string orderId) + { + var a = fsql.Select().Where(oc => oc.OrderId == orderId).ToAggregate(g => g.Sum(g.Key.CouponPrice) ); + return a; + } } } diff --git a/BBWY.Server.Business/Order/OrderBusiness.cs b/BBWY.Server.Business/Order/OrderBusiness.cs index 280bf14d..ba7eef44 100644 --- a/BBWY.Server.Business/Order/OrderBusiness.cs +++ b/BBWY.Server.Business/Order/OrderBusiness.cs @@ -43,11 +43,15 @@ namespace BBWY.Server.Business public OrderListResponse GetOrderList(SearchOrderRequest searchOrderRequest) { - var select = fsql.Select().LeftJoin((o, ocs, oct) => o.Id == ocs.OrderId) - .LeftJoin((o, ocs, oct) => o.Id == oct.OrderId); + if (searchOrderRequest.OrderState == Enums.OrderState.已取消) + searchOrderRequest.ExcludeCanceled = false; + + var select = fsql.Select().LeftJoin((o, ocs, oct, ods) => o.Id == ocs.OrderId) + .LeftJoin((o, ocs, oct, ods) => o.Id == oct.OrderId) + .LeftJoin((o, ocs, oct, ods) => o.Id == ods.OrderId); if (!string.IsNullOrEmpty(searchOrderRequest.OrderId)) { - select = select.Where((o, ocs, oct) => o.Id == searchOrderRequest.OrderId); + select = select.Where((o, ocs, oct, ods) => o.Id == searchOrderRequest.OrderId); } else { @@ -56,24 +60,27 @@ namespace BBWY.Server.Business var childSelect = fsql.Select().As("osku") .WhereIf(string.IsNullOrEmpty(searchOrderRequest.Sku) == false, osku => osku.SkuId == searchOrderRequest.Sku) .WhereIf(string.IsNullOrEmpty(searchOrderRequest.ProductNo) == false, osku => osku.ProductNo == searchOrderRequest.ProductNo); - select = select.Where((o, ocs, oct) => childSelect.Where(osku => osku.OrderId == o.Id).Any()); + select = select.Where((o, ocs, oct, ods) => childSelect.Where(osku => osku.OrderId == o.Id).Any()); } - select = select.WhereIf(searchOrderRequest.OrderState != null, (o, ocs, oct) => o.OrderState == searchOrderRequest.OrderState) - .WhereIf(searchOrderRequest.StartDate != null, (o, ocs, oct) => o.StartTime >= searchOrderRequest.StartDate) - .WhereIf(searchOrderRequest.EndDate != null, (o, ocs, oct) => o.StartTime <= searchOrderRequest.EndDate) - .WhereIf(string.IsNullOrEmpty(searchOrderRequest.ContactName) == false, (o, ocs, oct) => ocs.ContactName == searchOrderRequest.ContactName) - .WhereIf(string.IsNullOrEmpty(searchOrderRequest.Waybill) == false, (o, ocs, oct) => o.WaybillNo.Contains(searchOrderRequest.Waybill)); //这一步可能比较慢 + select = select.WhereIf(searchOrderRequest.OrderState != null, (o, ocs, oct, ods) => o.OrderState == searchOrderRequest.OrderState) + .WhereIf(searchOrderRequest.StartDate != null, (o, ocs, oct, ods) => o.StartTime >= searchOrderRequest.StartDate) + .WhereIf(searchOrderRequest.EndDate != null, (o, ocs, oct, ods) => o.StartTime <= searchOrderRequest.EndDate) + .WhereIf(searchOrderRequest.OnlyDF, (o, ocs, oct, ods) => o.StorageType == Enums.StorageType.代发) + .WhereIf(searchOrderRequest.ExcludeCanceled, (o, ocs, oct, ods) => o.OrderState != Enums.OrderState.已取消) + .WhereIf(searchOrderRequest.ExcludeSD && !searchOrderRequest.OnlyDF, (o, ocs, oct, ods) => o.StorageType == null || o.StorageType != Enums.StorageType.SD) + .WhereIf(string.IsNullOrEmpty(searchOrderRequest.ContactName) == false, (o, ocs, oct, ods) => ocs.ContactName == searchOrderRequest.ContactName) + .WhereIf(string.IsNullOrEmpty(searchOrderRequest.Waybill) == false, (o, ocs, oct, ods) => o.WaybillNo == searchOrderRequest.Waybill); } - select = select.Where((o, ocs, oct) => o.ShopId == searchOrderRequest.ShopId) - .OrderByDescending((o, ocs, oct) => o.StartTime) + select = select.Where((o, ocs, oct, ods) => o.ShopId == searchOrderRequest.ShopId) + .OrderByDescending((o, ocs, oct, ods) => o.StartTime) .Count(out var total) .Page(searchOrderRequest.PageIndex, searchOrderRequest.PageSize); var sql = select.ToSql(); - var orderSourceList = select.ToList((o, ocs, oct) => new Order() + var orderSourceList = select.ToList((o, ocs, oct, ods) => new Order() { Id = o.Id, BuyerRemark = o.BuyerRemark, @@ -114,7 +121,13 @@ namespace BBWY.Server.Business Profit = oct.Profit, PurchaseAmount = oct.PurchaseAmount, IsManualEdited = oct.IsManualEdited, - SDCommissionAmount = oct.SDCommissionAmount + SDCommissionAmount = oct.SDCommissionAmount, + + BuyerAccount = ods.BuyerAccount, + DeliveryFreight = ods.DeliveryFreight, + PurchaseOrderId = ods.PurchaseOrderId, + PurchasePlatform = ods.PurchasePlatform, + SellerAccount = ods.SellerAccount, }); var orderList = orderSourceList.Map>(); @@ -194,7 +207,9 @@ namespace BBWY.Server.Business var orderSkus = fsql.Select().Where(osku => osku.OrderId == autoCalculationCostRequest.OrderId).ToList(); var orderSkuIds = orderSkus.Select(osku => osku.SkuId).ToList(); - var purchaserOrders = fsql.Select().Where(po => po.RemainingQuantity != 0 && orderSkuIds.Contains(po.SkuId)).ToList(); + var purchaserOrders = fsql.Select().Where(po => po.StorageType == autoCalculationCostRequest.StorageType && + po.RemainingQuantity != 0 && + orderSkuIds.Contains(po.SkuId)).ToList(); if (purchaserOrders.Count() == 0) throw new BusinessException("库存为零不能自动计算成本"); @@ -465,6 +480,155 @@ namespace BBWY.Server.Business }); } + /// + /// 关联外部订单 + /// + /// + public void RelationPurchaseOrder(RelationPurchaseOrderRequest relationPurchaseOrderRequest) + { + var dbOrder = fsql.Select(relationPurchaseOrderRequest.OrderDropShipping.OrderId).ToOne(); + if (dbOrder == null) + throw new BusinessException($"订单号{relationPurchaseOrderRequest.OrderDropShipping.OrderId}不存在"); + + IInsert insertOrderDropShipping = null; + IUpdate updateOrderDropShipping = null; + IInsert insertOrderCost = null; + IUpdate updateOrderCost = null; + IDelete deletePurchaseOrder = null; + IDelete deleteOrderCostDetail = null; + List insertPurchaseOrderList = new List(); + List insertOrderCostDetailList = new List(); + + + #region 代发信息表 + var orderDropShipping = relationPurchaseOrderRequest.OrderDropShipping.Map(); + if (fsql.Select(relationPurchaseOrderRequest.OrderDropShipping.OrderId).Any()) + updateOrderDropShipping = fsql.Update().SetSource(orderDropShipping); + else + { + orderDropShipping.CreateTime = DateTime.Now; + insertOrderDropShipping = fsql.Insert(orderDropShipping); + } + + #endregion + + #region 采购单表 + var oldPourchaseIdList = fsql.Select().Where(ocd => ocd.OrderId == relationPurchaseOrderRequest.OrderDropShipping.OrderId) + .ToList(ocd => ocd.PurchaseOrderPKId); + deletePurchaseOrder = fsql.Delete().Where(po => oldPourchaseIdList.Contains(po.Id)); + insertPurchaseOrderList.AddRange(relationPurchaseOrderRequest.RelationPurchaseOrderSkuList.Select(x => new PurchaseOrder() + { + Id = idGenerator.NewLong(), + CreateTime = DateTime.Now, + ProductId = x.ProductId, + PurchaseMethod = Enums.PurchaseMethod.线下采购, + StorageType = Enums.StorageType.代发, + PurchaseOrderId = relationPurchaseOrderRequest.OrderDropShipping.PurchaseOrderId, + PurchasePlatform = relationPurchaseOrderRequest.OrderDropShipping.PurchasePlatform, + PurchaseQuantity = x.Quantity, + RemainingQuantity = 0, + ShopId = dbOrder.ShopId, + SkuId = x.SkuId, + SingleConsumableAmount = 0, + SingleFirstFreight = 0, + SingleFreight = 0, + SingleOperationAmount = 0, + SingleStorageAmount = 0, + SingleSkuAmount = x.SingleSkuAmount, + SingleDeliveryFreight = 0 + })); + #endregion + + #region 订单成本表 + var orderCost = fsql.Select(relationPurchaseOrderRequest.OrderDropShipping.OrderId).ToOne(); + if (orderCost != null) + { + orderCost.DeliveryExpressFreight = relationPurchaseOrderRequest.OrderDropShipping.DeliveryFreight; + orderCost.PurchaseAmount = relationPurchaseOrderRequest.OrderDropShipping.PurchaseAmount; + orderCost.Profit = dbOrder.OrderSellerPrice + + dbOrder.FreightPrice - + orderCost.PurchaseAmount - + orderCost.DeliveryExpressFreight - + orderCost.PlatformCommissionAmount; + updateOrderCost = fsql.Update().SetSource(orderCost).IgnoreColumns(oc => new + { + oc.CreateTime, + oc.SDCommissionAmount, + oc.PlatformCommissionAmount, + oc.PlatformCommissionRatio + }); + } + else + { + var preferentialAmount = fsql.Select().Where(oc => oc.OrderId == relationPurchaseOrderRequest.OrderDropShipping.OrderId) + .ToAggregate(g => g.Sum(g.Key.CouponPrice)); + orderCost = new OrderCost() + { + OrderId = relationPurchaseOrderRequest.OrderDropShipping.OrderId, + CreateTime = DateTime.Now, + DeliveryExpressFreight = relationPurchaseOrderRequest.OrderDropShipping.DeliveryFreight, + PlatformCommissionRatio = 0.05M, + SDCommissionAmount = 0, + PurchaseAmount = relationPurchaseOrderRequest.RelationPurchaseOrderSkuList.Sum(s => s.SingleSkuAmount * s.Quantity), + PlatformCommissionAmount = dbOrder.OrderSellerPrice * 0.05M, + PreferentialAmount = preferentialAmount, + IsManualEdited = true + }; + + orderCost.Profit = dbOrder.OrderSellerPrice + + dbOrder.FreightPrice - + orderCost.PurchaseAmount - + orderCost.DeliveryExpressFreight - + orderCost.PlatformCommissionAmount; + insertOrderCost = fsql.Insert(orderCost); + } + #endregion + + #region 订单成本明细表 + var oldOrderCostDetailIdList = fsql.Select().Where(ocd => ocd.OrderId == relationPurchaseOrderRequest.OrderDropShipping.OrderId) + .ToList(ocd => ocd.Id); + deleteOrderCostDetail = fsql.Delete().Where(ocd => oldOrderCostDetailIdList.Contains(ocd.Id)); + insertOrderCostDetailList.AddRange(relationPurchaseOrderRequest.RelationPurchaseOrderSkuList.Select(x => new OrderCostDetail() + { + Id = idGenerator.NewLong(), + ConsumableAmount = 0, + CreateTime = DateTime.Now, + DeductionQuantity = x.Quantity, + DeliveryExpressFreight = 0, + FirstFreight = 0, + OperationAmount = 0, + OrderId = relationPurchaseOrderRequest.OrderDropShipping.OrderId, + ProductId = x.ProductId, + PurchaseFreight = 0, + SkuAmount = x.SingleSkuAmount * x.Quantity, + SkuId = x.SkuId, + StorageAmount = 0, + TotalCost = x.SingleSkuAmount * x.Quantity, + UnitCost = x.SingleSkuAmount, + PurchaseOrderPKId = insertPurchaseOrderList.FirstOrDefault(po => po.SkuId == x.SkuId).Id + })); + #endregion + + fsql.Transaction(() => + { + deletePurchaseOrder?.ExecuteAffrows(); + deleteOrderCostDetail?.ExecuteAffrows(); + insertOrderDropShipping?.ExecuteAffrows(); + updateOrderDropShipping?.ExecuteAffrows(); + insertOrderCost?.ExecuteAffrows(); + updateOrderCost?.ExecuteAffrows(); + fsql.Insert(insertPurchaseOrderList).ExecuteAffrows(); + fsql.Insert(insertOrderCostDetailList).ExecuteAffrows(); + if (dbOrder.StorageType != Enums.StorageType.代发) + { + fsql.Update(relationPurchaseOrderRequest.OrderDropShipping.OrderId) + .Set(o => o.StorageType, Enums.StorageType.代发) + .SetIf(dbOrder.OrderState == Enums.OrderState.等待采购, o => o.OrderState, Enums.OrderState.待出库) + .ExecuteAffrows(); + } + }); + } + public void SyncOrder(long shopId, string orderId) { #region 获取店铺信息; @@ -774,6 +938,7 @@ namespace BBWY.Server.Business #region 扣减库存, 计算成本 if (dbOrder.StorageType != null && dbOrder.StorageType != Enums.StorageType.SD && + dbOrder.StorageType != Enums.StorageType.代发 && orderState != null && orderState != Enums.OrderState.待付款 && orderState != Enums.OrderState.已取消) diff --git a/BBWY.Server.Model/Db/Order/Order.cs b/BBWY.Server.Model/Db/Order/Order.cs index e7918f7c..e5d467e9 100644 --- a/BBWY.Server.Model/Db/Order/Order.cs +++ b/BBWY.Server.Model/Db/Order/Order.cs @@ -212,6 +212,38 @@ namespace BBWY.Server.Model.Db [Column(IsIgnore = true)] public bool? IsDecode { get; set; } #endregion + + #region 代发信息 + /// + /// 买家账号 + /// + [Column(IsIgnore = true)] + public string BuyerAccount { get; set; } + + /// + /// 发货运费 + /// + [Column(IsIgnore = true)] + public decimal DeliveryFreight { get; set; } = 0.00M; + + /// + /// 采购单号 + /// + [Column(IsIgnore = true)] + public string PurchaseOrderId { get; set; } + + /// + /// 采购平台 + /// + [Column(IsIgnore = true)] + public Enums.Platform? PurchasePlatform { get; set; } + + /// + /// 卖家账号 + /// + [Column(IsIgnore = true)] + public string SellerAccount { get; set; } + #endregion } } diff --git a/BBWY.Server.Model/Db/Order/OrderDropShipping.cs b/BBWY.Server.Model/Db/Order/OrderDropShipping.cs new file mode 100644 index 00000000..f7651ae1 --- /dev/null +++ b/BBWY.Server.Model/Db/Order/OrderDropShipping.cs @@ -0,0 +1,58 @@ +using FreeSql.DataAnnotations; +using System; + +namespace BBWY.Server.Model.Db +{ + + /// + /// 代发信息表 + /// + [Table(Name = "orderdropshipping", DisableSyncStructure = true)] + public partial class OrderDropShipping + { + + [Column(StringLength = 50, IsPrimary = true, IsNullable = false)] + public string OrderId { get; set; } + + /// + /// 买家账号 + /// + [Column(StringLength = 50)] + public string BuyerAccount { get; set; } + + [Column(DbType = "datetime")] + public DateTime? CreateTime { get; set; } + + /// + /// 发货运费 + /// + [Column(DbType = "decimal(20,2)")] + public decimal DeliveryFreight { get; set; } = 0.00M; + + /// + /// 采购金额 + /// + [Column(DbType = "decimal(20,2)")] + public decimal PurchaseAmount { get; set; } = 0.00M; + + /// + /// 采购单号 + /// + [Column(StringLength = 50)] + public string PurchaseOrderId { get; set; } + + /// + /// 采购平台 + /// + [Column(DbType = "int(1)", MapType = typeof(int?))] + public Enums.Platform? PurchasePlatform { get; set; } + + /// + /// 卖家账号 + /// + [Column(StringLength = 50)] + public string SellerAccount { get; set; } + + } + +} diff --git a/BBWY.Server.Model/Dto/Request/Order/OrderDropShippingRequest.cs b/BBWY.Server.Model/Dto/Request/Order/OrderDropShippingRequest.cs new file mode 100644 index 00000000..0e692938 --- /dev/null +++ b/BBWY.Server.Model/Dto/Request/Order/OrderDropShippingRequest.cs @@ -0,0 +1,8 @@ +using BBWY.Server.Model.Db; + +namespace BBWY.Server.Model.Dto +{ + public class OrderDropShippingRequest : OrderDropShipping + { + } +} diff --git a/BBWY.Server.Model/Dto/Request/Order/RelationPurchaseOrderRequest.cs b/BBWY.Server.Model/Dto/Request/Order/RelationPurchaseOrderRequest.cs new file mode 100644 index 00000000..280a74b4 --- /dev/null +++ b/BBWY.Server.Model/Dto/Request/Order/RelationPurchaseOrderRequest.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; + +namespace BBWY.Server.Model.Dto +{ + public class RelationPurchaseOrderRequest + { + public OrderDropShippingRequest OrderDropShipping { get; set; } + + public IList RelationPurchaseOrderSkuList { get; set; } + } + + public class RelationPurchaseOrderSkuRequest + { + public string ProductId { get; set; } + + public string SkuId { get; set; } + + public decimal SingleSkuAmount { get; set; } + + public int Quantity { get; set; } + } +} diff --git a/BBWY.Server.Model/Dto/Request/Order/SearchOrderRequest.cs b/BBWY.Server.Model/Dto/Request/Order/SearchOrderRequest.cs index 1aa65a08..ad2ae40a 100644 --- a/BBWY.Server.Model/Dto/Request/Order/SearchOrderRequest.cs +++ b/BBWY.Server.Model/Dto/Request/Order/SearchOrderRequest.cs @@ -47,5 +47,10 @@ namespace BBWY.Server.Model.Dto /// 排除刷单 /// public bool ExcludeSD { get; set; } + + /// + /// 过滤已取消 + /// + public bool ExcludeCanceled { get; set; } } } diff --git a/BBWY.Server.Model/Dto/Response/Order/OrderDropShippingResponse.cs b/BBWY.Server.Model/Dto/Response/Order/OrderDropShippingResponse.cs new file mode 100644 index 00000000..699db061 --- /dev/null +++ b/BBWY.Server.Model/Dto/Response/Order/OrderDropShippingResponse.cs @@ -0,0 +1,8 @@ +using BBWY.Server.Model.Db; + +namespace BBWY.Server.Model.Dto +{ + public class OrderDropShippingResponse: OrderDropShipping + { + } +} diff --git a/BBWY.Server.Model/Dto/Response/Order/OrderResponse.cs b/BBWY.Server.Model/Dto/Response/Order/OrderResponse.cs index e98fcb4f..b0643a61 100644 --- a/BBWY.Server.Model/Dto/Response/Order/OrderResponse.cs +++ b/BBWY.Server.Model/Dto/Response/Order/OrderResponse.cs @@ -148,6 +148,11 @@ namespace BBWY.Server.Model.Dto /// 订单成本明细列表 /// public IList OrderCostDetailList { get; set; } + + /// + /// 代发信息 + /// + public OrderDropShippingResponse OrderDropShipping { get; set; } } public class OrderListResponse diff --git a/BBWY.Server.Model/MappingProfiles.cs b/BBWY.Server.Model/MappingProfiles.cs index 33d030d4..19834532 100644 --- a/BBWY.Server.Model/MappingProfiles.cs +++ b/BBWY.Server.Model/MappingProfiles.cs @@ -24,6 +24,7 @@ namespace BBWY.Server.Model CreateMap(); CreateMap(); + CreateMap(); CreateMap(); CreateMap(); CreateMap(); @@ -49,7 +50,14 @@ namespace BBWY.Server.Model .ForPath(t => t.OrderCost.PlatformCommissionRatio, opt => opt.MapFrom(f => f.PlatformCommissionRatio ?? 0)) .ForPath(t => t.OrderCost.PreferentialAmount, opt => opt.MapFrom(f => f.PreferentialAmount)) .ForPath(t => t.OrderCost.IsManualEdited, opt => opt.MapFrom(f => f.IsManualEdited)) - .ForPath(t => t.OrderCost.SDCommissionAmount, opt => opt.MapFrom(f => f.SDCommissionAmount)); + .ForPath(t => t.OrderCost.SDCommissionAmount, opt => opt.MapFrom(f => f.SDCommissionAmount)) + .ForPath(t => t.OrderDropShipping.PurchaseAmount, opt => opt.MapFrom(f => f.PurchaseAmount)) + .ForPath(t => t.OrderDropShipping.PurchaseOrderId, opt => opt.MapFrom(f => f.PurchaseOrderId)) + .ForPath(t => t.OrderDropShipping.OrderId, opt => opt.MapFrom(f => f.Id)) + .ForPath(t => t.OrderDropShipping.DeliveryFreight, opt => opt.MapFrom(f => f.DeliveryFreight)) + .ForPath(t => t.OrderDropShipping.PurchasePlatform, opt => opt.MapFrom(f => f.PurchasePlatform)) + .ForPath(t => t.OrderDropShipping.BuyerAccount, opt => opt.MapFrom(f => f.BuyerAccount)) + .ForPath(t => t.OrderDropShipping.SellerAccount, opt => opt.MapFrom(f => f.SellerAccount)); } }