예제 #1
0
        public async Task <ActionResult> Create([NamedModelBinder(typeof(CommaSeparatedModelBinder), "orderIds")] string[] orderIds)
        {
            if (!orderIds.Any())
            {
                return(Error("订单号不能为空"));
            }

            var orderManager = new OrderManager(User);
            var orders       = await orderManager.GetOrdersAsync(orderIds);

            //if (!orders.All(r => r.OrderStatus == OrderStatus.ToBeShip))
            //    return Error("订单号状态不是待出货");

            var customers = orders.Select(r => r.Customer).Distinct().ToList();

            if (customers.Count > 1)
            {
                return(Error("生成出货单不能选择了多个公司"));
            }

            var customer = customers.FirstOrDefault();

            var discountRateManager = new DiscountRateManager();
            var discountRate        = await discountRateManager.GetCustomerDiscountRateAsync(customer.Id);

            var shipmentOrderViewModel = new ShipmentOrderViewModel()
            {
                SideStoneRate   = (double)discountRate.SideStone / 100,
                StoneSetterRate = (double)discountRate.StoneSetter / 100
            };

            shipmentOrderViewModel.ShipmentOrderInfos = await Task.WhenAll(orders.Select(async o =>
            {
                var dailyGoldPriceManager      = new DailyGoldPriceManager();
                var dailyGoldPrice             = await dailyGoldPriceManager.GetNewDailyGoldPriceAsync(o.ColorFormId);
                var shipmentOrderInfoViewModel = new ShipmentOrderInfoViewModel(o)
                {
                    GoldPrice = dailyGoldPrice == null ? 0 : dailyGoldPrice.Price,
                    LossRate  = o.ColorForm.Name.ToLower().Contains("pt") ? discountRate.LossPt : discountRate.Loss18K,
                };

                shipmentOrderInfoViewModel.Hhz        = Math.Round(shipmentOrderInfoViewModel.GoldWeight * (1 + shipmentOrderInfoViewModel.LossRate / 100), 2);
                shipmentOrderInfoViewModel.GoldAmount = shipmentOrderInfoViewModel.GoldPrice *shipmentOrderInfoViewModel.Hhz;
                shipmentOrderInfoViewModel.TotalSetStoneWorkingCost = shipmentOrderInfoViewModel.OrderSetStoneInfos.Sum(r => r.SetStoneWorkingCost) * ((double)discountRate.StoneSetter / 100);
                shipmentOrderInfoViewModel.SideStoneNumber          = shipmentOrderInfoViewModel.OrderSetStoneInfos.Sum(r => r.Number);
                shipmentOrderInfoViewModel.SideStoneWeight          = shipmentOrderInfoViewModel.OrderSetStoneInfos.Sum(r => r.Weight);
                shipmentOrderInfoViewModel.SideStoneTotalAmount     = shipmentOrderInfoViewModel.OrderSetStoneInfos.Sum(r => r.TotalAmount) * ((double)discountRate.SideStone / 100);;
                shipmentOrderInfoViewModel.RushCost = GetOrderRushCost(o);
                shipmentOrderInfoViewModel.RiskFee  = o.IsInsure ? GetRiskFee(o.Insurance, o.RiskType) : 0;
                return(shipmentOrderInfoViewModel);
            }));

            shipmentOrderViewModel.CustomerName = customer.Name;
            shipmentOrderViewModel.CustomerId   = customer.Id;
            shipmentOrderViewModel.TotalNumber  = shipmentOrderViewModel.ShipmentOrderInfos.Sum(r => r.Number);

            return(View(shipmentOrderViewModel));
        }
예제 #2
0
        private async Task <IEnumerable <ShipmentOrderInfoViewModel> > GetShipmentOrderInfoViewModels(ShipmentReportQuery reportQuery)
        {
            var manager = new ShipmentManager(User);

            var stopwatch          = Stopwatch.StartNew();
            var shipmentOrderInfos = await manager.GetShipmentOrderInfosAsync(reportQuery.GetShipmentOrderInfosQueryFilter());

            stopwatch.Stop();
            var shipmentOrderInfoViewModels = shipmentOrderInfos.Select(f =>
            {
                var shipmentOrderInfoViewModel          = Mapper.Map <ShipmentOrderInfo, ShipmentOrderInfoViewModel>(f);
                shipmentOrderInfoViewModel.CustomerName = f.Order.Customer.Name;
                shipmentOrderInfoViewModel.Hhz          = Math.Round(f.GoldWeight * (1 + f.LossRate / 100), 2);
                shipmentOrderInfoViewModel.IsShipOnTime = f.Order.DeliveryDate.HasValue && f.ShipmentOrder.DeliveryDate < f.Order.DeliveryDate.Value ? "正常" : "逾期";
                shipmentOrderInfoViewModel.DeliveryDate = f.ShipmentOrder.DeliveryDate.ToShortDateString();
                return(shipmentOrderInfoViewModel);
            }).ToList();

            var stopwatch2 = Stopwatch.StartNew();

            if (shipmentOrderInfoViewModels.Any())
            {
                var total = new ShipmentOrderInfoViewModel
                {
                    Number                   = shipmentOrderInfoViewModels.Sum(r => r.Number),
                    GoldWeight               = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.GoldWeight), 2),
                    Hhz                      = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.Hhz), 2),
                    GoldAmount               = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.GoldAmount), 2),
                    SideStoneNumber          = shipmentOrderInfoViewModels.Sum(r => r.SideStoneNumber),
                    SideStoneWeight          = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.SideStoneWeight), 2),
                    TotalSetStoneWorkingCost = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.TotalSetStoneWorkingCost), 2),
                    SideStoneTotalAmount     = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.SideStoneTotalAmount), 2),
                    BasicCost                = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.BasicCost), 2),
                    OutputWaxCost            = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.OutputWaxCost), 2),
                    RiskFee                  = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.RiskFee), 2),
                    OtherCost                = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.OtherCost), 2),
                    TotalAmount              = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.TotalAmount), 2),
                    Weight                   = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.Weight), 2),
                    IsShipOnTime             = $"正常{shipmentOrderInfoViewModels.Count(r => r.IsShipOnTime == "正常")},逾期{shipmentOrderInfoViewModels.Count(r => r.IsShipOnTime == "逾期")}",
                };
                shipmentOrderInfoViewModels.Add(total);
            }
            stopwatch2.Stop();
            LoggerHelper.Logger.LogInformation($"获取数据耗时{stopwatch.ElapsedMilliseconds}毫秒,统计数据耗时{stopwatch2.ElapsedMilliseconds}毫秒");
            return(shipmentOrderInfoViewModels);
        }
예제 #3
0
        private async Task <IEnumerable <ShipmentOrderInfoViewModel> > GetShipmentOrderInfoViewModels(ShipmentReportQuery reportQuery)
        {
            var manager = new ShipmentManager(User);

            var shipmentOrderInfos = await manager.GetShipmentOrderInfosAsync(reportQuery.GetShipmentOrderInfosQueryFilter());

            var shipmentOrderInfoViewModels = shipmentOrderInfos.Select(f =>
            {
                var shipmentOrderInfoViewModel = Mapper.Map <ShipmentOrderInfo, ShipmentOrderInfoViewModel>(f);
                shipmentOrderInfoViewModel.Hhz = Math.Round(f.GoldWeight * (1 + f.LossRate / 100), 2);
                return(shipmentOrderInfoViewModel);
            }).ToList();

            if (shipmentOrderInfoViewModels.Any())
            {
                var total = new ShipmentOrderInfoViewModel
                {
                    Id                       = "总计",
                    Number                   = shipmentOrderInfoViewModels.Sum(r => r.Number),
                    GoldWeight               = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.GoldWeight), 2),
                    Hhz                      = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.Hhz), 2),
                    GoldAmount               = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.GoldAmount), 2),
                    SideStoneNumber          = shipmentOrderInfoViewModels.Sum(r => r.SideStoneNumber),
                    SideStoneWeight          = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.SideStoneWeight), 2),
                    TotalSetStoneWorkingCost = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.TotalSetStoneWorkingCost), 2),
                    SideStoneTotalAmount     = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.SideStoneTotalAmount), 2),
                    BasicCost                = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.BasicCost), 2),
                    OutputWaxCost            = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.OutputWaxCost), 2),
                    RiskFee                  = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.RiskFee), 2),
                    OtherCost                = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.OtherCost), 2),
                    TotalAmount              = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.TotalAmount), 2),
                    Weight                   = Math.Round(shipmentOrderInfoViewModels.Sum(r => r.Weight), 2),
                };
                shipmentOrderInfoViewModels.Add(total);
            }
            return(shipmentOrderInfoViewModels);
        }