private PriceModel GetFreightList(FreightTrialFilterModel filter) { var returnModels = new PriceModel { Filter = filter }; if (filter.Weight == 0) { throw new Exception("重量必填"); } if (string.IsNullOrWhiteSpace(filter.CountryCode)) { throw new Exception("请选择发货国家"); } var customer = _customerService.GetCustomer(CustomerCode); if (customer == null || !customer.CustomerTypeID.HasValue) { throw new Exception("客户类型不存在"); } var list = _freightService.GetCustomerShippingPrices(new FreightPackageModel() { Weight = filter.Weight, Length = filter.Length ?? 0, Width = filter.Width ?? 0, Height = filter.Height ?? 0, CountryCode = filter.CountryCode, ShippingTypeId = filter.PackageType, CustomerTypeId = customer.CustomerTypeID.Value, CustomerId = customer.CustomerID, EnableTariffPrepay = filter.EnableTariffPrepay, }); var shippingList = _freightService.GetShippingMethodListByCustomerCode(CustomerCode, true); foreach (var item in list) { if (!item.CanShipping) { continue; } if (item.ShippingMethodId == null) { throw new Exception(string.Format("没有运输方式")); } var shippingMethod = shippingList.First( s => s.ShippingMethodId == item.ShippingMethodId.Value); if (shippingMethod == null) { throw new Exception(string.Format("运输方式【{0}】不存在", item.ShippingMethodId.Value)); } returnModels.FreightList.Add(new FreightModel { ShippingMethodName = shippingList.First(s => item.ShippingMethodId != null && s.ShippingMethodId == item.ShippingMethodId.Value).ShippingMethodName, ShippingMethodEName = shippingList.First(s => item.ShippingMethodId != null && s.ShippingMethodId == item.ShippingMethodId.Value).ShippingMethodEName, Code = shippingList.First(s => item.ShippingMethodId != null && s.ShippingMethodId == item.ShippingMethodId.Value).ShippingMethodCode, Weight = item.Weight, ShippingFee = item.ShippingFee, RegistrationFee = item.RegistrationFee, RemoteAreaFee = item.RemoteAreaFee, FuelFee = item.FuelFee, OtherFee = item.OtherFee, DeliveryTime = item.DeliveryTime, Remarks = item.Remark, TariffPrepayFee = item.TariffPrepayFee }); } returnModels.FreightList = returnModels.FreightList.OrderBy(o => o.TotalFee).ToList(); return(returnModels); }
private FreightTrialViewModels GetFreightList(FreightTrialFilterModel filter) { var viewModels = new FreightTrialViewModels { Filter = filter }; if (!filter.Weight.HasValue && (!filter.Length.HasValue && !filter.Width.HasValue && !filter.Height.HasValue)) { throw new Exception("重量或长宽高必填其中一项"); } if (string.IsNullOrWhiteSpace(filter.CountryCode)) { throw new Exception("请选择发货国家"); } var customerCode = _workContext.User.UserUame; var customer = _customerService.GetCustomer(customerCode); if (customer == null || !customer.CustomerTypeID.HasValue) { throw new Exception("客户类型不存在"); } var list = _freightService.GetCustomerShippingPrices(new FreightPackageModel() { Weight = filter.Weight ?? 0, Length = filter.Length ?? 0, Width = filter.Width ?? 0, Height = filter.Height ?? 0, CountryCode = filter.CountryCode, ShippingTypeId = filter.PackageType, CustomerTypeId = customer.CustomerTypeID.Value, CustomerId = customer.CustomerID }); var shippingList = _freightService.GetShippingMethodListByCustomerCode(customerCode, true); foreach (var item in list) { if (!item.CanShipping) { continue; } if (item.ShippingMethodId == null) { throw new Exception(string.Format("没有运输方式")); } var shippingMethod = shippingList.First( s => s.ShippingMethodId == item.ShippingMethodId.Value); if (shippingMethod == null) { throw new Exception(string.Format("运输方式【{0}】不存在", item.ShippingMethodId.Value)); } viewModels.FreightList.Add(new FreightModel { ShippingMethodName = shippingList.First(s => item.ShippingMethodId != null && s.ShippingMethodId == item.ShippingMethodId.Value).ShippingMethodName, Weight = item.Weight, ShippingFee = item.ShippingFee, RegistrationFee = item.RegistrationFee, RemoteAreaFee = item.RemoteAreaFee, FuelFee = item.FuelFee, OtherFee = item.OtherFee, DeliveryTime = item.DeliveryTime, Remarks = item.Remark }); } viewModels.FreightList = viewModels.FreightList.OrderBy(o => o.TotalFee).ToList(); return(viewModels); }
private FreightTrialViewModels GetFreightList(FreightTrialFilterModel filter) { var viewModels = new FreightTrialViewModels { Filter = filter }; if (!filter.Weight.HasValue && (!string.IsNullOrWhiteSpace(filter.Length) && !string.IsNullOrWhiteSpace(filter.Width) && !string.IsNullOrWhiteSpace(filter.Height))) { throw new Exception("重量或长宽高必填其中一项"); } if (string.IsNullOrWhiteSpace(filter.CountryCode)) { throw new Exception("请选择发货国家"); } string customerCode = ""; Guid customerId = Guid.Empty; int customerTypeId = 12;//默认12 if (null != _workContext.User) { customerCode = _workContext.User.UserUame; var customer = _customerService.GetCustomer(customerCode); if (customer != null && customer.CustomerTypeID.HasValue) { customerTypeId = customer.CustomerTypeID.Value; customerId = customer.CustomerID; } } else { customerCode = _customerService.GetCustomerCode(customerTypeId); } var list = _freightService.GetCustomerShippingPrices(new FreightPackageModel() { Weight = filter.Weight ?? 0, Length = Convert.ToInt32(string.IsNullOrEmpty(filter.Length) ? "0" : filter.Length), Width = Convert.ToInt32(string.IsNullOrEmpty(filter.Width) ? "0" : filter.Width), Height = Convert.ToInt32(string.IsNullOrEmpty(filter.Height) ? "0" : filter.Height), CountryCode = filter.CountryCode, ShippingTypeId = filter.PackageType, CustomerTypeId = customerTypeId, CustomerId = customerId, EnableTariffPrepay = false, }); var shippingList = _freightService.GetShippingMethodListByCustomerCode(customerCode, true); foreach (var item in list) { if (!item.CanShipping) { continue; } if (item.ShippingMethodId == null) { throw new Exception(string.Format("没有运输方式")); } var shippingMethod = shippingList.Find( s => s.ShippingMethodId == item.ShippingMethodId.Value); if (shippingMethod == null) { throw new Exception(string.Format("运输方式【{0}】不存在", item.ShippingMethodId.Value)); } viewModels.FreightList.Add(new FreightModel { ShippingMethodName = shippingList.First(s => item.ShippingMethodId != null && s.ShippingMethodId == item.ShippingMethodId.Value).ShippingMethodName, Weight = item.Weight, ShippingFee = item.ShippingFee, RegistrationFee = item.RegistrationFee, RemoteAreaFee = item.RemoteAreaFee, FuelFee = item.FuelFee, OtherFee = item.Value - (item.ShippingFee + item.RegistrationFee + item.RemoteAreaFee + item.FuelFee), DeliveryTime = item.DeliveryTime, Remarks = item.Remark, TariffPrepayFee = item.TariffPrepayFee, }); } viewModels.FreightList = viewModels.FreightList.OrderBy(o => o.TotalFee).ToList(); return(viewModels); }