Exemplo n.º 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);
            var _rlist = Service.GetActiveRules(result.Id);

            result.Rules = Mapper.Map <List <Entities.FullDiscountRuleInfo>, List <FullDiscountRules> >(_rlist);
            return(result);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 将最低价格保存在商品查询表中
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="shopId"></param>
        public static void SaveCaculateMinPrice(long productId, long shopId)
        {
            var product = Service.GetProduct(productId);

            if (product == null)
            {
                return;
            }
            decimal minPrice = 0;

            if (product.IsOpenLadder)
            {
                //比较阶梯价,取阶梯价最小价格,不用管梯度
                var ladderSkus = _productLadderPriceService.GetLadderPricesByProductIds(productId);
                if (ladderSkus != null && ladderSkus.Count() > 0)
                {
                    decimal minLadderPrice = ladderSkus.Min(p => p.Price);
                    minPrice = minLadderPrice;
                }
            }
            else
            {
                //先取sku最小价格
                var skus = Service.GetSKUs(productId);
                minPrice = skus.Min(p => p.SalePrice);
            }
            //比较拼团价格
            var fightGroup = _iFightGroupService.GetActiveIdByProductIdAndShopId(productId, shopId);

            if (fightGroup != null && fightGroup.ActiveStatus == FightGroupActiveStatus.Ongoing)
            {
                var miniGroupPrice = fightGroup.ActiveItems.Min(p => p.ActivePrice);
                if (miniGroupPrice < minPrice)
                {
                    minPrice = miniGroupPrice;
                }
            }
            //比较限时购价格
            var ltmbuy = ServiceApplication.Create <ILimitTimeBuyService>().GetFlashSaleInfoByProductIdAndShopId(productId, shopId);

            if (ltmbuy != null)
            {
                if (ltmbuy.BeginDate <= DateTime.Now)
                {
                    if (ltmbuy.MinPrice < minPrice)
                    {
                        minPrice = ltmbuy.MinPrice;
                    }
                }
                else
                {
                    var      flashSaleConfig = _iLimitTimeBuyService.GetConfig();
                    TimeSpan flashSaleTime   = ltmbuy.BeginDate - DateTime.Now;                                          //开始时间还剩多久
                    TimeSpan preheatTime     = new TimeSpan(flashSaleConfig.Preheat, 0, 0);                              //预热时间是多久
                    if (preheatTime >= flashSaleTime && !flashSaleConfig.IsNormalPurchase && ltmbuy.MinPrice < minPrice) //预热大于开始并且不能购买,写入最低价格,需求386
                    {
                        minPrice = ltmbuy.MinPrice;
                    }
                }
            }
            var searchInfo = _searchProductService.GetSingleSearchProductInfo(productId, shopId);

            if (searchInfo != null && minPrice != searchInfo.SalePrice)
            {
                _searchProductService.UpdateSearchProductPrice(productId, shopId, minPrice);
            }
        }