Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="templateId"></param>
        /// <returns></returns>
        public FreightInfo GetFreightFeeByTemplate(EntFreightTemplate template, List <EntGoodsCart> shopingItem)
        {
            FreightInfo info = null;

            //满额免运费
            if (template.FullDiscount > 0)
            {
                var totalPrice    = shopingItem.Sum(item => item.Count * item.Price);
                var discountPrice = totalPrice >= template.FullDiscount ? 0 : template.BaseCost;
                info = new FreightInfo
                {
                    Fee     = discountPrice,
                    Msg     = discountPrice == 0 ? "满减免运费" : $"离免运费,还差购买{(template.FullDiscount - totalPrice) * 0.01}元商品",
                    IsVaild = true
                };
            }
            //按件计费
            else if (template.BaseCost > 0 && template.BaseCount > 0 && template.ExtraCost > 0)
            {
                var itemCount  = shopingItem.Sum(item => item.Count);
                var extraCount = itemCount - template.BaseCount;
                var fee        = extraCount > 0 ? extraCount * template.ExtraCost + template.BaseCost: template.BaseCost;
                info = new FreightInfo
                {
                    Fee     = fee,
                    Msg     = extraCount <= 0 ? "无优惠" : $"购买超出{extraCount}将,以每件{template.ExtraCost * 0.01}元续费",
                    IsVaild = true
                };
            }
            else
            {
                info = new FreightInfo {
                    Msg = "无效运费模板"
                };
            }
            return(info);
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="config"></param>
        /// <param name="cartIds"></param>
        /// <returns>"运费|优惠信息|是否在配送范围"</returns>
        public FreightInfo GetFreightFee(StoreConfigModel config, string cartIds, string province, string city)
        {
            FreightInfo info = null;

            //返回统一运费
            if (config.FreightPriceSwitch)
            {
                info = new FreightInfo {
                    Fee = config.FreightPrice, Msg = "无优惠", IsVaild = true
                };
                return(info);
            }
            //获取模板(未启用模板时,返回默认官方模板)
            EntFreightTemplate template = config.FreightTemplateId <= 0 ? GetDefaultTemplate() : GetModel(config.FreightTemplateId);
            //送货地址是否在商家配送范围(默认模板:全国配送)
            bool isInDeliveryArea = CheckDeliveryArea(template: template, province: province, city: city);

            if (!isInDeliveryArea)
            {
                info = new FreightInfo {
                    Fee = 0, Msg = "送货地址超出配送范围", IsVaild = false
                };
                return(info);
            }
            //获取购物车商品
            var shopingItem = EntGoodsCartBLL.SingleModel.GetMyCartById(cartIds.Trim(','));

            if (shopingItem?.Count <= 0)
            {
                info = new FreightInfo {
                    Fee = 0, Msg = "无效商品", IsVaild = false
                };
                return(info);
            }
            //获取运费
            return(GetFreightFeeByTemplate(template, shopingItem));
        }