Exemple #1
0
        private void ComputeFreightRangeDTOs(IList <FreightDTO> templates)
        {
            var templateIds = templates.Where(predicate => predicate.PricingMethod == 3).Select(selector => selector.Id).ToList();

            var freights = FreightRangeDetails.ObjectSet()
                           .Where(predicate => templateIds.Contains(predicate.TemplateId))
                           .GroupBy(selector => new { selector.TemplateId, selector.ProvinceCodes })
                           .ToList();

            foreach (var freight in freights)
            {
                var templateId = freight.Key.TemplateId;

                var template = templates.FirstOrDefault(predicate => predicate.Id == templateId);

                var provinceNames = ComputeProvincesName(freight.Key.ProvinceCodes);

                var costText = string.Join(";", freight.OrderBy(selector => selector.Min).Select(selector => ComputeFreightCostText(selector)));

                template.RangeFreights.Add(new FreightRangeDTO
                {
                    DefaultFreight   = string.IsNullOrEmpty(freight.Key.ProvinceCodes) ? "默认运费" : "",
                    ExpressProvinces = provinceNames,
                    FreightCosts     = costText
                });
            }
        }
Exemple #2
0
        /// <summary>
        /// 仅更新区间运费模板
        /// </summary>
        /// <param name="inputDTO"></param>
        private void OnlyUpdateRangeFreightTemplate(Deploy.CustomDTO.RangeFreightTemplateInputDTO inputDTO)
        {
            if (inputDTO == null)
            {
                throw new ArgumentNullException("inputDTO");
            }

            if (inputDTO.TemplateId == Guid.Empty)
            {
                throw new ArgumentException("inputDTO.TemplateId");
            }

            var templateId = inputDTO.TemplateId;

            var template = FreightTemplate.ObjectSet().FirstOrDefault(predicate => predicate.Id == templateId);

            if (template == null)
            {
                throw new Exception(string.Format("未找到运费模板对象 FreightTemplateId: {0}", templateId));
            }

            template.Name       = inputDTO.Name;
            template.IsFreeExp  = inputDTO.FreeExpress;
            template.ModifiedId = base.ContextDTO.LoginUserID;

            FreightRangeDetails.ObjectSet()
            .Where(predicate => predicate.TemplateId == templateId)
            .ToList()
            .ForEach(freight =>
                     freight.EntityState = System.Data.EntityState.Deleted);

            var context = ContextFactory.CurrentThreadContext;

            foreach (var group in inputDTO.Freights.GroupBy(selector => selector.IsSpecific))
            {
                foreach (var freight in group)
                {
                    var detail = FreightRangeDetails.CreateFreightRangeDetails();
                    detail.TemplateId    = template.Id;
                    detail.ProvinceCodes = freight.ProvinceCodes;
                    detail.IsSpecific    = freight.IsSpecific;
                    detail.Min           = freight.Min;
                    detail.Max           = freight.Max;
                    detail.Cost          = freight.Cost;

                    context.SaveObject(detail);
                }
            }

            context.SaveObject(template);
            context.SaveChange();
        }
Exemple #3
0
        /// <summary>
        /// 计算运费显示信息
        /// </summary>
        /// <param name="details"></param>
        /// <returns></returns>
        private string ComputeFreightCostText(FreightRangeDetails details)
        {
            if (details == null)
            {
                return(string.Empty);
            }

            if (details.Max > 0)
            {
                return(string.Format("{0}~{1}元,运费{2}元", details.Min, details.Max, details.Cost));
            }
            return(string.Format("{0}元以上,运费{1}元", details.Min, details.Cost));
        }
Exemple #4
0
        /// <summary>
        /// 仅创建区间运费模板
        /// </summary>
        /// <param name="inputDTO"></param>
        private void OnlyCreateRangeFreightTemplate(Deploy.CustomDTO.RangeFreightTemplateInputDTO inputDTO)
        {
            var context = ContextFactory.CurrentThreadContext;

            var template = FreightTemplate.CreateFreightTemplate();

            template.AppId         = inputDTO.AppId;
            template.SubId         = base.ContextDTO.LoginUserID;
            template.Name          = inputDTO.Name;
            template.IsFreeExp     = inputDTO.FreeExpress;
            template.PricingMethod = 3; //按区间计价
            template.SubTime       = DateTime.Now;
            template.ExpressType   = 0;

            template.FreightMethod   = 0;
            template.FreightTo       = "";
            template.FirstCount      = 0M;
            template.FirstCountPrice = 0M;
            template.NextCount       = 0M;
            template.NextCountPrice  = 0M;
            template.ModifiedOn      = DateTime.Now;
            template.IsDefault       = 0;

            context.SaveObject(template);

            foreach (var freight in inputDTO.Freights)
            {
                var detail = FreightRangeDetails.CreateFreightRangeDetails();
                detail.TemplateId    = template.Id;
                detail.ProvinceCodes = freight.ProvinceCodes;
                detail.IsSpecific    = !string.IsNullOrEmpty(freight.ProvinceCodes);
                detail.Min           = freight.Min;
                detail.Max           = freight.Max;
                detail.Cost          = freight.Cost;

                context.SaveObject(detail);
            }
            context.SaveChanges();
        }
Exemple #5
0
        /// <summary>
        /// 获取一条运费模板记录
        /// </summary>
        /// <param name="freightTemplateId"></param>
        /// <returns></returns>
        public FreightDTO GetOneFreightExt(Guid freightTemplateId)
        {
            try
            {
                FreightDTO      freight = null;
                FreightTemplate ftDTO   = FreightTemplate.ObjectSet().Where(s => s.Id == freightTemplateId).FirstOrDefault();
                if (ftDTO == null)
                {
                    return(freight);
                }
                freight                 = new FreightDTO();
                freight.Id              = ftDTO.Id;
                freight.AppId           = ftDTO.AppId;
                freight.Name            = ftDTO.Name;
                freight.IsFreeExp       = ftDTO.IsFreeExp;
                freight.FreightMethod   = ftDTO.FreightMethod;
                freight.FreightTo       = ftDTO.FreightTo;
                freight.FirstCount      = ftDTO.FirstCount;
                freight.FirstCountPrice = ftDTO.FirstCountPrice;
                freight.NextCount       = ftDTO.NextCount;
                freight.NextCountPrice  = ftDTO.NextCountPrice;
                freight.PricingMethod   = ftDTO.PricingMethod;
                freight.ExpressType     = ftDTO.ExpressType;

                //运费详情。
                freight.FreightDetailList = GetFreightTemplateDetailListByTemId(freightTemplateId);

                //部分包邮
                var pfQuery = from fpf in FreightPartialFree.ObjectSet()
                              where fpf.FreightTemplateId == ftDTO.Id
                              select fpf;
                if (pfQuery.Any())
                {
                    var pfList = pfQuery.ToList().ConvertAll(ConvertFreightPartialFree2ExtDTO);
                    try
                    {
                        var provList = CBCBP.Instance.GeProvinceByCountryCode();
                        if (provList != null && provList.Any())
                        {
                            foreach (var pf in pfList)
                            {
                                var provNamesQ = from p in provList
                                                 where ("," + pf.DestinationCodes + ",").Contains("," + p.Code + ",")
                                                 select p.Name;
                                pf.FreightTo = string.Join(",", provNamesQ);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error("GetOneFreightExt中调用Jinher.AMP.CBC.IBP.Facade.GeProvinceByCountryCode异常", ex);
                    }
                    freight.PartialFreeList = pfList;
                }

                #region 价格区间运费
                var             details = FreightRangeDetails.ObjectSet().Where(predicate => predicate.TemplateId == freightTemplateId);
                TPS.CBCBPFacade facade  = new CBCBPFacade();
                if (details.Any())
                {
                    foreach (var group in details.GroupBy(selector => new { selector.ProvinceCodes, selector.IsSpecific }))
                    {
                        var sort = group.OrderBy(selector => selector.Min);

                        if (!group.Key.IsSpecific)
                        {
                            foreach (var detail in sort)
                            {
                                freight.DefaultRangeFreightDetails.Add(new Deploy.CustomDTO.FreightRangeDefaultDetailsDTO
                                {
                                    Min  = detail.Min,
                                    Max  = detail.Max,
                                    Cost = detail.Cost
                                });
                            }
                            continue;
                        }

                        freight.SpecificRangeFreightDetails.Add(new FreightRangeSpecificDetailsDTO
                        {
                            ProvinceNames = facade.GetProvincesNameByCode(group.Key.ProvinceCodes),
                            ProvinceCodes = group.Key.ProvinceCodes,
                            Details       = sort.Select(selector => new Jinher.AMP.BTP.Deploy.CustomDTO.FreightRangeDefaultDetailsDTO
                            {
                                Min  = selector.Min,
                                Max  = selector.Max,
                                Cost = selector.Cost
                            }).ToList()
                        });
                    }
                }
                #endregion

                return(freight);
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("获取一条运费记录服务异常。freightTemplateId:{0}", freightTemplateId), ex);
                return(null);
            }
        }