Exemplo n.º 1
0
        /// <summary>
        /// 根据模板ID获取运费模板信息
        /// </summary>
        /// <param name="templateId"></param>
        /// <returns></returns>
        public static FreightTemplate GetFreightTemplate(long templateId, long shopId)
        {
            var model = _iFreightTemplateService.GetFreightTemplate(templateId);

            if (model.ShopID != shopId)
            {
                throw new HimallException("此运费模板不存在");
            }
            var areas   = _iFreightTemplateService.GetFreightAreaContent(templateId);
            var details = _iFreightTemplateService.GetFreightAreaDetail(templateId);

            model.Himall_FreightAreaContent = areas;
            foreach (var m in model.Himall_FreightAreaContent)
            {
                var t = details.Where(a => a.FreightAreaId == m.Id).ToList();
                m.FreightAreaDetailInfo = t;
            }
            var freightTemplate = AutoMapper.Mapper.Map <FreightTemplate>(model);
            var area            = freightTemplate.FreightArea.Where(a => a.IsDefault == 0).ToList();

            foreach (var f in area)
            {
                foreach (var a in f.FreightAreaDetail)
                {
                    a.ProvinceName = RegionApplication.GetRegion(a.ProvinceId).Name;
                    if (a.CityId.HasValue && a.CityId.Value != 0)
                    {
                        a.CityName = RegionApplication.GetRegion(a.CityId.Value).Name;
                    }
                    if (a.CountyId.HasValue && a.CountyId.Value != 0)
                    {
                        a.CountyName = RegionApplication.GetRegion(a.CountyId.Value).Name;
                    }
                    if (!string.IsNullOrEmpty(a.TownIds))
                    {
                        var regionNames = RegionApplication.GetAllRegions().Where(x => a.TownIds.Split(',').ToList().Contains(x.Id.ToString())).Select(t => t.Name).ToList();
                        a.TownNames = string.Join(",", regionNames);
                    }
                }
            }
            return(freightTemplate);
        }
Exemplo n.º 2
0
        public static FreightTemplate GetFreightAreaDetail(long templateId, long shopId)
        {
            var model = Service.GetFreightTemplate(templateId);

            if (model.ShopID != shopId)
            {
                throw new HimallException("此运费模板不存在");
            }

            var freightTemplate = AutoMapper.Mapper.Map <FreightTemplate>(model);

            freightTemplate.FreightArea = AutoMapper.Mapper.Map <List <FreightArea> >(model.FreightAreaContentInfo);
            foreach (var m in freightTemplate.FreightArea)
            {
                m.FreightAreaDetail = AutoMapper.Mapper.Map <List <FreightAreaDetail> >(model.FreightAreaContentInfo.Where(a => a.Id == m.Id).FirstOrDefault().FreightAreaDetailInfo);
            }
            freightTemplate.FreeTempContent = new List <FreeTempContent>();
            var freeGroups  = Service.GetShippingFreeGroups(model.Id);
            var freeRegions = Service.GetShippingFreeRegions(model.Id);

            freeGroups.ForEach(item =>
            {
                var info = new FreeTempContent()
                {
                    ConditionNumber = item.ConditionNumber,
                    ConditionType   = item.ConditionType
                };
                if (!string.IsNullOrWhiteSpace(info.ConditionNumber))
                {
                    var condition = info.ConditionNumber.Split('$');
                    if (condition.Length == 2)
                    {
                        info.ConditionNumber1 = condition[0];
                        info.ConditionNumber2 = condition[1];
                    }
                    else if (condition.Length == 1)
                    {
                        info.ConditionNumber1 = condition[0];
                    }
                }
                info.FreightAreaDetail = freeRegions
                                         .Where(p => p.GroupId == item.Id)
                                         .Select(a => new FreightAreaDetail()
                {
                    RegionPath = a.RegionPath
                })
                                         .ToList();

                freightTemplate.FreeTempContent.Add(info);
            });
            var area = freightTemplate.FreightArea.Where(a => a.IsDefault == 0).ToList();

            foreach (var f in area)
            {
                foreach (var a in f.FreightAreaDetail)
                {
                    a.ProvinceName = RegionApplication.GetRegion(a.ProvinceId).Name;
                    if (a.CityId.HasValue && a.CityId.Value != 0)
                    {
                        a.CityName = RegionApplication.GetRegion(a.CityId.Value).Name;
                    }
                    if (a.CountyId.HasValue && a.CountyId.Value != 0)
                    {
                        a.CountyName = RegionApplication.GetRegion(a.CountyId.Value).Name;
                    }
                    if (!string.IsNullOrEmpty(a.TownIds))
                    {
                        var regionNames = RegionApplication.GetAllRegions().Where(x => a.TownIds.Split(',').ToList().Contains(x.Id.ToString())).Select(t => t.Name).ToList();
                        a.TownNames = string.Join(",", regionNames);
                    }
                }
            }

            foreach (var item in freightTemplate.FreeTempContent)
            {
                Parallel.ForEach(item.FreightAreaDetail, a =>
                {
                    var path = a.RegionPath;
                    var arr  = path.Split(',');
                    if (arr.Length >= 3)
                    {
                        a.ProvinceId = int.Parse(arr[0]);
                        a.CityId     = int.Parse(arr[1]);
                        a.CountyId   = int.Parse(arr[2]);

                        a.ProvinceName = RegionApplication.GetRegion(a.ProvinceId).Name;
                        a.CityName     = RegionApplication.GetRegion(a.CityId.Value).Name;
                        a.CountyName   = RegionApplication.GetRegion(a.CountyId.Value).Name;
                    }
                    else if (arr.Length >= 2)
                    {
                        a.ProvinceId   = int.Parse(arr[0]);
                        a.CityId       = int.Parse(arr[1]);
                        a.ProvinceName = RegionApplication.GetRegion(a.ProvinceId).Name;
                        a.CityName     = RegionApplication.GetRegion(a.CityId.Value).Name;
                    }
                    else if (arr.Length >= 1)
                    {
                        a.ProvinceId   = int.Parse(arr[0]);
                        a.ProvinceName = RegionApplication.GetRegion(a.ProvinceId).Name;
                    }
                });
            }
            return(freightTemplate);
        }