public ActionResult FreightTrial(FreightTrialFilterModel filter, bool isImport = true) { var viewModels = new FreightTrialViewModels { Filter = filter }; try { viewModels = GetFreightList(filter); var listTile = new Dictionary <string, string>() { { "ShippingMethodName", "运输方式" }, { "Weight", "计算重量" }, { "ShippingFee", "运费" }, { "RegistrationFee", "挂号费" }, { "FuelFee", "燃油费" }, { "SundryFee", "杂费" }, { "TotalFee", "总费用" }, { "DeliveryTime", "时效" }, { "Remarks", "备注" }, }; ExcelHelper.WriteToDownLoad("ShippingFreight.xls", "sheet1", viewModels.FreightList, listTile); } catch (Exception e) { ViewBag.CountryList = GetCountryList(""); ViewBag.GoodsTypeList = GetGoodsTypeList(); ErrorNotification(e.Message); } return(View(viewModels)); }
public ActionResult FreightTrial(string countryCode, decimal?weight, string length, string height, string width, int packageType = 0) { FreightTrialFilterModel filter = new FreightTrialFilterModel { PackageType = packageType, CountryCode = countryCode, Weight = weight, Length = length, Width = width, Height = height }; return(View(BindData(filter))); }
public ActionResult FreightTrial(FreightTrialFilterModel filter) { ViewBag.CountryList = GetCountryList(""); ViewBag.GoodsTypeList = GetGoodsTypeList(); var viewModels = new FreightTrialViewModels { Filter = filter }; try { viewModels = GetFreightList(filter); } catch (Exception e) { ErrorNotification(e.Message); } return(View(viewModels)); }
public FreightTrialViewModels BindData(FreightTrialFilterModel filter) { ViewBag.CountryList = GetCountryList(""); ViewBag.GoodsTypeList = GetGoodsTypeList(); var viewModels = new FreightTrialViewModels { Filter = filter }; try { viewModels = GetFreightList(filter); } catch (Exception e) { ErrorNotification(e.Message); } viewModels.ShowCategoryListModel = ShowCategoryListModel(); return(viewModels); }
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 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); }
//api/lms/GetPrice?countryCode=AE&weight=2&length=1&width=1&height=1& packageType=15 //string countryCode, string weight, string length, string width, string height, string packageType public Response <List <QuotationModel> > GetPrice(string countryCode, string weight, string length, string width, string height, string shippingTypeId, bool enableTariffPrepay = false) { var model = new Response <List <QuotationModel> > { Item = null, ResultCode = ErrorCodeHelper.GetErrorCode(ErrorCode.Error0000), ResultDesc = Resource.Error0000 }; FreightTrialFilterModel filter = new FreightTrialFilterModel(); #region 参数及结果验证 int lengths = 1; int widths = 1; int heights = 1; int shippingTypeIds; decimal weights; if (string.IsNullOrWhiteSpace(weight) || string.IsNullOrWhiteSpace(shippingTypeId) || string.IsNullOrWhiteSpace(countryCode)) { model.ResultCode = ErrorCodeHelper.GetErrorCode(ErrorCode.Error1004); model.ResultDesc = Resource.Error1004; return(model); } filter.CountryCode = countryCode; if (Int32.TryParse(length, out lengths)) { filter.Length = lengths; } else { filter.Length = lengths; } if (Int32.TryParse(width, out widths)) { filter.Width = widths; } else { filter.Width = widths; } if (Int32.TryParse(height, out heights)) { filter.Height = heights; } else { filter.Height = heights; } if (Int32.TryParse(shippingTypeId, out shippingTypeIds)) { filter.PackageType = shippingTypeIds; } else { model.ResultCode = ErrorCodeHelper.GetErrorCode(ErrorCode.Error1004); model.ResultDesc = Resource.Error1004; return(model); } if (decimal.TryParse(weight, out weights)) { filter.Weight = weights; } else { model.ResultCode = ErrorCodeHelper.GetErrorCode(ErrorCode.Error1004); model.ResultDesc = Resource.Error1004; return(model); } filter.EnableTariffPrepay = enableTariffPrepay;//是否启用关税预付服务 List <FreightModel> freightList = GetFreightList(filter).FreightList; if (freightList.Count < 1) { model.ResultCode = ErrorCodeHelper.GetErrorCode(ErrorCode.Error1006); model.ResultDesc = Resource.Error1006; } else { model.Item = new List <QuotationModel>(); freightList.ForEach(p => model.Item.Add(new QuotationModel() { Code = p.Code, ShippingMethodName = p.ShippingMethodName, ShippingMethodEName = p.ShippingMethodEName, ShippingFee = p.ShippingFee, RegistrationFee = p.RegistrationFee, FuelFee = p.FuelFee, SundryFee = p.SundryFee, TariffPrepayFee = p.TariffPrepayFee, TotalFee = p.TotalFee, DeliveryTime = p.DeliveryTime, Remarks = p.Remarks })); } #endregion return(model); }
public ActionResult FreightTrial(FreightTrialFilterModel filter) { return(View(BindData(filter))); }
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); }