/// <summary> /// 获取销售员小店订单 /// </summary> /// <param name="query"></param> /// <returns></returns> public static QueryPageModel <DistributorBrokerageOrder> GetDistributorBrokerageOrderList(DistributionBrokerageQuery query) { var orders = _iDistributionService.GetDistributorBrokerageOrderList(query); var orderids = orders.Models.Select(d => d.Id).ToList(); var itemBrokerages = _iDistributionService.GetDistributionBrokerageByOrderIds(orderids); var shopids = itemBrokerages.Select(d => d.ShopId).Distinct().ToList(); var orderItems = _iOrderService.GetOrderItemsByOrderId(orderids); var shops = _iShopService.GetShops(shopids); var refunds = _iRefundService.GetAllOrderRefunds(new RefundQuery { MoreOrderId = orderids }); QueryPageModel <DistributorBrokerageOrder> result = new QueryPageModel <DistributorBrokerageOrder> { Models = new List <DistributorBrokerageOrder>(), Total = orders.Total }; foreach (var item in orders.Models) { var bitems = itemBrokerages.Where(d => d.OrderId == item.Id).ToList(); var oitems = orderItems.Where(d => d.OrderId == item.Id).ToList(); if (bitems == null || bitems.Count == 0) { continue; } var first = bitems.FirstOrDefault(); var shdatas = refunds.Where(d => d.OrderId == item.Id); DistributorBrokerageOrder odata = new DistributorBrokerageOrder { OrderId = first.OrderId, OrderStatus = item.OrderStatus, Status = first.BrokerageStatus, SettlementTime = first.SettlementTime, Items = new List <DistributorBrokerageOrderItem>(), OrderAmount = item.OrderAmount, OrderDate = item.OrderDate, IsRefundCloseOrder = (item.OrderStatus == OrderInfo.OrderOperateStatus.Close && shdatas.Any(d => d.ManagerConfirmStatus == OrderRefundInfo.OrderRefundConfirmStatus.Confirmed)) }; int SuperiorLevel = 1; decimal BrokerageRate = 0, BrokerageAmount = 0; foreach (var oitem in oitems) { string[] _skus = (new string[] { oitem.Color, oitem.Size, oitem.Version }).Where(d => !string.IsNullOrWhiteSpace(d)).ToArray(); var _shop = shops.FirstOrDefault(d => d.Id == oitem.ShopId); DistributorBrokerageOrderItem idata = new DistributorBrokerageOrderItem { ProductId = oitem.ProductId, ProductName = oitem.ProductName, ProductDefaultImage = MallIO.GetRomoteProductSizeImage(oitem.ThumbnailsUrl, 1, (int)ImageSize.Size_100), Sku = string.Join("、", _skus), ShopId = oitem.ShopId, OrderItemId = oitem.Id, Quantity = oitem.Quantity, ShopName = _shop.ShopName, IsHasRefund = item.OrderStatus != OrderInfo.OrderOperateStatus.Close && refunds.Any(d => d.OrderItemId == oitem.Id && d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund && d.ManagerConfirmStatus == OrderRefundInfo.OrderRefundConfirmStatus.Confirmed) }; var bitem = itemBrokerages.FirstOrDefault(d => d.OrderItemId == oitem.Id); if (bitem != null) { idata.SuperiorId1 = bitem.SuperiorId1; idata.BrokerageRate1 = bitem.BrokerageRate1; idata.SuperiorId2 = bitem.SuperiorId2; idata.BrokerageRate2 = bitem.BrokerageRate2; idata.SuperiorId3 = bitem.SuperiorId3; idata.BrokerageRate3 = bitem.BrokerageRate3; idata.RealPayAmount = bitem.RealPayAmount; idata.SettlementTime = bitem.SettlementTime; idata.Status = bitem.BrokerageStatus; if (idata.SuperiorId1 == query.DistributorId) { SuperiorLevel = 1; BrokerageRate = idata.BrokerageRate1; } if (idata.SuperiorId2 == query.DistributorId) { SuperiorLevel = 2; BrokerageRate = idata.BrokerageRate2; } if (idata.SuperiorId3 == query.DistributorId) { SuperiorLevel = 3; BrokerageRate = idata.BrokerageRate3; } BrokerageAmount += GetDivide100Number(idata.RealPayAmount * BrokerageRate); } odata.Items.Add(idata); } odata.SuperiorLevel = SuperiorLevel; odata.BrokerageAmount = BrokerageAmount; odata.QuantitySum = odata.Items.Sum(d => d.Quantity); result.Models.Add(odata); } result.Models = result.Models.OrderByDescending(d => d.OrderDate).ThenByDescending(d => d.OrderId).ToList(); return(result); }