Пример #1
0
        /// <summary>
        /// 从缓存中获取运输方式支持的国家
        /// </summary>
        private List <ShippingMethodCountryModel> GetShippingMethodCountriesFromCache(int shippingMethodId)
        {
            object inCache = Cache.Get(shippingMethodId.ToString());

            if (inCache != null)
            {
                var listShippingMethodCountryModel = inCache as List <ShippingMethodCountryModel>;

                if (listShippingMethodCountryModel != null)
                {
                    return(listShippingMethodCountryModel);
                }
            }
            var listShippingMethodCountryModelNewest = _freightService.GetCountryArea(shippingMethodId);

            if (listShippingMethodCountryModelNewest != null)
            {
                Cache.Add(shippingMethodId.ToString(), listShippingMethodCountryModelNewest, 5);
            }

            return(listShippingMethodCountryModelNewest);
        }
Пример #2
0
        /// <summary>
        /// 获取收件人的所在区号
        /// </summary>
        /// <param name="shippingMethodId">运输方式ID</param>
        /// <param name="postCode">邮政编号</param>
        /// <param name="countryCode">国家代码</param>
        /// <returns></returns>
        private int GetShippingZone(int shippingMethodId, string postCode, string countryCode)
        {
            int zone = 0;

            //非俄速通小包专线挂号时就返回0
            if (shippingMethodId != sysConfig.SpecialShippingMethodId)
            {
                List <ShippingMethodCountryModel> shippingMethod = _freightService.GetCountryArea(shippingMethodId, countryCode);
                if (shippingMethod != null && shippingMethod.Count > 0)
                {
                    zone = shippingMethod.First().AreaId;
                }
                return(zone);
            }

            if (string.IsNullOrWhiteSpace(postCode))
            {
                return(zone);
            }

            var firstStr = postCode.Substring(0, 1);

            if (firstStr == "1" || firstStr == "2" || firstStr == "3" || firstStr == "4")
            {
                switch (firstStr)
                {
                case "1":
                    zone = 1;
                    break;

                case "2":
                    zone = 2;
                    break;

                case "3":
                    zone = 3;
                    break;

                case "4":
                    zone = 4;
                    break;

                default:
                    zone = 0;
                    break;
                }
            }
            else
            {
                var twoStr = postCode.Substring(0, 2);
                if (twoStr == "60" || twoStr == "61" || twoStr == "62")
                {
                    switch (twoStr)
                    {
                    case "60":
                    case "61":
                    case "62":
                        zone = 4;
                        break;

                    default:
                        zone = 6;
                        break;
                    }
                }
                else
                {
                    var threeStr = postCode.Substring(0, 3);
                    if (threeStr == "640" || threeStr == "641")
                    {
                        switch (threeStr)
                        {
                        case "640":
                        case "641":
                            zone = 4;
                            break;

                        default:
                            zone = 6;
                            break;
                        }
                    }
                    else
                    {
                        zone = 6;
                    }
                }
            }

            return(zone);
        }