Exemplo n.º 1
0
        private string CalcSF(FedExQueryAdv ship)
        {
            var result = string.Empty;

            //1:CNY 2:USD
            ship.CoinType = ConfigurationManager.AppSettings["CoinType"] == "1" ? "CNY" : "USD";


            ShipmentEx shipment = null;


            //获得采购商地址
            ShopInfo shop = ServiceHelper.Create <IShopService>().GetShop(ship.ShopId, true);

            if (shop != null)
            {
                ship.OrigId       = shop.CompanyRegionId;
                ship.OrigAddress  = shop.CompanyAddress;
                ship.OrigPostCode = shop.ZipCode;
            }


            shipment = ServiceHelper.Create <IShipmentService>().CalcSFCostAdv(ship);
            if (shipment != null)
            {
                result = Newtonsoft.Json.JsonConvert.SerializeObject(shipment);
            }

            return(result);
        }
Exemplo n.º 2
0
        public string CalcPrice(FedExQueryAdv ship)
        {
            var result = string.Empty;

            switch (ship.ShipType)
            {
            case "FedEx":
                result = CalcFedex(ship);
                break;

            case "SF":
                result = CalcSF(ship);
                break;
            }

            return(result);
        }
Exemplo n.º 3
0
        public string CalcPriceAdv(FedExQueryAdv ship)
        {
            var result = string.Empty;

            //1:CNY 2:USD
            ship.CoinType = ConfigurationManager.AppSettings["CoinType"] == "1" ? "CNY" : "USD";

            var appSettings = ConfigurationManager.AppSettings;

            ship.FedexKey           = appSettings["FedExKey"];
            ship.FedexPassword      = appSettings["FedExPassword"];
            ship.FedexAccountNumber = appSettings["FedExAccountNumber"];
            ship.FedexMeterNumber   = appSettings["FedExMeterNumber"];

            ShipmentEx shipment = null;

            if (ship.ShopId > 0)
            {
                //获得采购商地址
                ShopInfo shop = ServiceHelper.Create <IShopService>().GetShop(ship.ShopId, true);
                ship.OrigId       = shop.CompanyRegionId;
                ship.OrigAddress  = shop.CompanyAddress;
                ship.OrigPostCode = shop.ZipCode;

                shipment = ServiceHelper.Create <IShipmentService>().CalcPriceAdv(ship);
                if (shipment != null)
                {
                    result = Newtonsoft.Json.JsonConvert.SerializeObject(shipment);
                }
            }
            else
            {
                shipment = ServiceHelper.Create <IShipmentService>().CalcPrice(ship);
                if (shipment != null)
                {
                    result = Newtonsoft.Json.JsonConvert.SerializeObject(shipment);
                }
            }



            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 计算顺丰物流费用
        /// </summary>
        /// <param name="ship"></param>
        /// <returns></returns>
        public ShipmentEx CalcSFCostAdv(FedExQueryAdv ship)
        {
            ShipmentEx result = null;

            try
            {
                SFRateRequest rateRequest = new SFRateRequest();
                string        countyCode  = string.Empty;
                string        countyName  = string.Empty;
                CountryInfo   county      = null;

                var packages = new List <Package>();

                Package pkg = null;


                CountryInfo ortCity = context.CountryInfo.SingleOrDefault(x => x.ID == ship.OrigId);

                if (ortCity != null)
                {
                    county = GetCountry(ortCity.PID);

                    if (county != null)
                    {
                        countyCode = county.Code;
                        countyName = county.ContryNameEN;

                        if (countyCode.ToUpper() != "CN")
                        {
                            rateRequest.OriginCode       = county.SFCode;
                            rateRequest.ParentOriginCode = county.SFCode;
                        }
                        else
                        {
                            rateRequest.OriginCode       = ortCity.SFCode;
                            rateRequest.ParentOriginCode = ortCity.SFCode;
                        }
                    }
                }


                var origin = new Address(ship.OrigAddress, "", "", ortCity.ContryNameEN, "", ship.OrigPostCode, countyCode);
                origin.CountryName = countyName;


                //获取目的地

                ShippingAddressInfo destAddress = context.ShippingAddressInfo.SingleOrDefault(x => x.Id == ship.DestId);
                CountryInfo         destCity    = context.CountryInfo.SingleOrDefault(x => x.ID == destAddress.RegionId);

                if (destCity != null)
                {
                    county = null;
                    county = GetCountry(destCity.PID);

                    if (county != null)
                    {
                        countyCode = county.Code;
                        countyName = county.ContryNameEN;
                        if (countyCode.ToUpper() != "CN")
                        {
                            rateRequest.DestCode       = county.SFCode;
                            rateRequest.ParentDestCode = county.SFCode;
                        }
                        else
                        {
                            rateRequest.DestCode       = destCity.SFCode;
                            rateRequest.ParentDestCode = destCity.SFCode;
                        }
                    }
                }

                var destination = new Address(destAddress.Address, "", "", destCity.ContryNameEN, "", destAddress.PostCode, countyCode);
                destination.CountryName = countyName;

                rateRequest.Volume    = 0;
                rateRequest.QueryType = 5;
                rateRequest.Lang      = "sc";
                rateRequest.Region    = "cn";

                foreach (ShipPackage item in ship.PackagesList)
                {
                    pkg              = GetPackage(item, 6000);
                    pkg.Currency     = ship.CoinType;
                    pkg.PackageCount = item.Num;
                    pkg.PackageType  = "自备包装";
                    packages.Add(pkg);
                }

                rateRequest.Weight = Math.Round(packages.Sum(x => x.Weight), 2);
                // rateRequest.Time = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd hh:mm");//"2016-07-06T13%3A30%3A00%2B08%3A00"

                DateTime dtNow = DateTime.Now;
                rateRequest.Time = string.Format("{0}T{1}%3A{2}%3A{3}%2B08%3A00", dtNow.ToString("yyyy-MM-dd"), dtNow.ToString("hh"), dtNow.ToString("mm"), dtNow.ToString("ss"));

                var rateManager = new RateManager();

                rateManager.AddProvider(new SFProvider(rateRequest));


                result = rateManager.GetRates(origin, destination, packages);

                if (result.Rates != null && result.Rates.Count > 0)
                {
                    result.RateValue = result.Rates[0];
                }
            }
            catch (Exception ex)
            {
            }

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 计算Fedex费用
        /// </summary>
        /// <param name="ship"></param>
        /// <returns></returns>

        public ShipmentEx CalcPriceAdv(FedExQueryAdv ship)
        {
            ShipmentEx result = null;

            try
            {
                string      countyCode = string.Empty;
                string      countyName = string.Empty;
                CountryInfo county     = null;

                var packages = new List <Package>();

                Package pkg = null;

                //获取始发地

                //ShippingAddressInfo orgAddress = context.ShippingAddressInfo.SingleOrDefault(x => x.Id == ship.OrigId);

                //CountryInfo ortCity = context.CountryInfo.SingleOrDefault(x => x.ID == orgAddress.RegionId);

                //county = GetCountry(ortCity.PID);

                //if (county != null)
                //{
                //    countyCode = county.Code;
                //    countyName = county.ContryNameEN;
                //}

                //var origin = new Address(orgAddress.Address, "", "", ortCity.ContryNameEN, "", ortCity.Code, countyCode);
                //origin.CountryName = countyName;


                CountryInfo ortCity = context.CountryInfo.SingleOrDefault(x => x.ID == ship.OrigId);

                county = GetCountry(ortCity.PID);

                if (county != null)
                {
                    countyCode = county.Code;
                    countyName = county.ContryNameEN;
                }

                var origin = new Address(ship.OrigAddress, "", "", ortCity.ContryNameEN, "", ship.OrigPostCode, countyCode);
                origin.CountryName = countyName;


                //获取目的地
                ShippingAddressInfo destAddress = context.ShippingAddressInfo.SingleOrDefault(x => x.Id == ship.DestId);
                CountryInfo         destCity    = context.CountryInfo.SingleOrDefault(x => x.ID == destAddress.RegionId);
                county = null;
                county = GetCountry(destCity.PID);

                if (county != null)
                {
                    countyCode = county.Code;
                    countyName = county.ContryNameEN;
                }

                var destination = new Address(destAddress.Address, "", "", destCity.ContryNameEN, "", destAddress.PostCode, countyCode);
                destination.CountryName = countyName;



                foreach (ShipPackage item in ship.PackagesList)
                {
                    //if (item.Num > 0)
                    //{
                    //    for (int i = 0; i < item.Num; i++)
                    //    {
                    //        pkg = GetPackage(item);
                    //        pkg.Currency = ship.CoinType;
                    //        pkg.PackageCount = 1;
                    //        pkg.PackageType = "自备包装";
                    //        packages.Add(pkg);
                    //    }
                    //}
                    pkg              = GetPackage(item);
                    pkg.Currency     = ship.CoinType;
                    pkg.PackageCount = item.Num;
                    pkg.PackageType  = "自备包装";
                    packages.Add(pkg);
                }

                var rateManager = new RateManager();

                rateManager.AddProvider(new FedExProvider(ship.FedexKey, ship.FedexPassword, ship.FedexAccountNumber, ship.FedexMeterNumber));


                result = rateManager.GetRates(origin, destination, packages);

                if (result.Rates != null && result.Rates.Count > 0)
                {
                    result.RateValue = result.Rates[0];
                }
            }
            catch (Exception ex)
            {
            }

            return(result);
        }