Beispiel #1
0
        /// <summary>
        /// 获取某个实体正在参加的满额折
        /// </summary>
        /// <param name="proId"></param>
        /// <param name="shopId"></param>
        /// <returns></returns>
        public static FullDiscountActive GetOngoingActiveByProductId(long proId, long shopId, long branchId = 0)
        {
            FullDiscountActive result = null;

            if (branchId <= 0)
            {//非门店,则验证是否有限时购
                //限时购不参与满额减(bug需求34735)
                var ltmbuy = ServiceApplication.Create <ILimitTimeBuyService>().GetLimitTimeMarketItemByProductId(proId);
                if (ltmbuy != null)
                {
                    return(result);
                }
            }
            var active = Service.GetOngoingActiveByProductId(proId, shopId);

            if (active == null)
            {
                return(result);
            }
            //result = Mapper.Map<Entities.ActiveInfo, FullDiscountActive>(active);
            result = active.Map <FullDiscountActive>();


            var _rlist = Service.GetActiveRules(result.Id);

            //   result.Rules = Mapper.Map<List<Entities.FullDiscountRuleInfo>, List<FullDiscountRules>>(_rlist);
            result.Rules = _rlist.Map <List <FullDiscountRules> >();


            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 用户当前商品运费显示文本
        /// </summary>
        /// <param name="productId">商品Id</param>
        /// <param name="freightTemplate">运费末班</param>
        /// <param name="member">访问的用户</param>
        /// <param name="product">商品实体</param>
        /// <param name="buynumber">购买件数</param>
        /// <returns></returns>
        public static string GetFreightStr(long productId, FreightTemplateInfo freightTemplate, MemberInfo member = null, ProductInfo product = null, int buynumber = 1)
        {
            string freightStr = "免运费";

            if (freightTemplate == null || freightTemplate.IsFree == CommonModel.FreightTemplateType.Free)
            {
                return(freightStr);
            }

            IProductService productService = ServiceApplication.Create <IProductService>();

            #region 是否虚拟商品,如是虚拟商品免运费
            if (product == null)
            {
                product = productService.GetProduct(productId);
                if (product == null || product.ProductType == 1)//虚拟商品无运费
                {
                    return(freightStr);
                }
            }
            #endregion

            int addressId = 0;
            if (member != null)
            {
                var addressInfo = ShippingAddressApplication.GetDefaultUserShippingAddressByUserId(member.Id);
                if (addressInfo != null)
                {
                    addressId = addressInfo.RegionId;
                }
            }

            #region 当前是否是指定地区包邮
            if (addressId > 0)
            {
                bool    isFree = false; //当前地区是否为自定包邮
                decimal price  = 0;     //购买商品的金额

                var freeRegions = Service.GetShippingFreeRegions(freightTemplate.Id);
                if (freeRegions != null && freeRegions.Count() > 0)
                {
                    IRegionService regionService = ServiceProvider.Instance <IRegionService> .Create;
                    freeRegions.ForEach(p =>
                    {
                        p.RegionSubList = regionService.GetSubsNew(p.RegionId, true).Select(a => a.Id).ToList();
                    });
                    var regions = freeRegions.Where(p => p.RegionSubList.Contains(addressId));//根据模板设置的包邮地区过滤出当前配送地址所在地址
                    if (regions != null && regions.Count() > 0)
                    {
                        var groupIds   = regions.Select(p => p.GroupId).ToList();
                        var freeGroups = Service.GetShippingFreeGroupInfos(freightTemplate.Id, groupIds);

                        //只要有一个符合包邮,则退出
                        decimal amount = price * buynumber;
                        freeGroups.ForEach(p =>
                        {
                            if (p.ConditionType == 1)//购买件数
                            {
                                if (buynumber >= int.Parse(p.ConditionNumber))
                                {
                                    isFree = true;
                                    return;
                                }
                            }
                            else if (p.ConditionType == 2)//金额
                            {
                                if (amount >= decimal.Parse(p.ConditionNumber))
                                {
                                    isFree = true;
                                    return;
                                }
                            }
                            else if (p.ConditionType == 3)//件数+金额
                            {
                                var condition1 = int.Parse(p.ConditionNumber.Split('$')[0]);
                                var condition2 = decimal.Parse(p.ConditionNumber.Split('$')[1]);
                                if (buynumber >= condition1 && amount >= condition2)
                                {
                                    isFree = true;
                                    return;
                                }
                            }
                        });
                    }
                }

                if (isFree)
                {
                    return(freightStr);//直接返回免运费
                }
            }
            #endregion

            decimal freight = productService.GetFreight(new List <long>()
            {
                productId
            }, new List <int>()
            {
                1
            }, addressId, true);
            freightStr = freight <= 0 ? "免运费" : string.Format("运费 {0}元", freight.ToString("f2"));

            return(freightStr);
        }