Пример #1
0
        /// <summary>
        /// 加入购物车
        /// </summary>
        /// <note>
        /// Request Param:
        /// Category-加入的对象类型;Product-商品,Package-套餐
        /// SysNo-根据加入的对象类型对应的系统编号
        /// Qty-数量
        /// e.g:?Category=Package&SysNo=1006&Qty=2
        /// </note>
        /// <returns></returns>
        public ActionResult AddToShoppingCart()
        {
            string shoppingCartUrl = PageHelper.BuildUrl("ShoppingCartRoute");

            #region 1.Check
            int    sysNo    = 0;
            int    qty      = 0;
            string category = Request.Params["Category"];
            if (string.IsNullOrWhiteSpace(category) || (category.Equals("Product") && category.Equals("Package")))
            {
                return(Redirect(shoppingCartUrl));
            }
            else if (!int.TryParse(Request.Params["SysNo"], out sysNo) || sysNo <= 0)
            {
                return(Redirect(shoppingCartUrl));
            }
            else if (!int.TryParse(Request.Params["Qty"], out qty) || qty <= 0)
            {
                return(Redirect(shoppingCartUrl));
            }
            if (category.Equals("Product"))
            {
                var product = ProductFacade.GetProductBasicInfoBySysNo(sysNo);
                if (product == null || product.ProductStatus != Enums.ProductStatus.Show)
                {
                    return(Redirect(shoppingCartUrl));
                }
            }
            #endregion

            #region 2.加入购物车
            ShoppingItemGroup shoppingItemGroup = ShoppingFacade.BuildShoppingItemGroup(category, sysNo, qty);
            ShoppingCart      shoppingCart      = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();
            if (shoppingItemGroup != null)
            {
                //用于计算会员价:
                LoginUser userInfo = UserMgr.ReadUserInfo();
                shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;

                ShoppingFacade.AddToShoppingCart(shoppingItemGroup, shoppingCart);
                ShoppingStorageManager.SaveShoppingCart(shoppingCart);
            }
            #endregion

            return(Redirect(shoppingCartUrl));
        }
Пример #2
0
        public static CheckOutResult GetPayAndShipTypeList(CheckOutContext context, int customerSysNo, ShoppingCart shoppingCart)
        {
            CheckOutResult result = new CheckOutResult();

            CheckOutContext newCheckoutContenxt = new CheckOutContext();

            if (context != null)
            {
                newCheckoutContenxt = context.Clone();
            }

            MemberInfo memberInfo = CustomerDA.GetCustomerInfo(customerSysNo);

            //取得用户选择的收货地址信息
            var custShippingAddrResult = GetCustomerShippingAddressList(newCheckoutContenxt, customerSysNo);

            result.SelShippingAddress = custShippingAddrResult.SelShippingAddress;

            #region 支付类别选择
            result.PaymentCategoryList = GetAllPaymentCategoryList();
            //优先取context指定的支付类型
            //其次取配送地址指定的支付类型
            if (!result.PaymentCategoryList.Exists(x =>
            {
                if (x.Key.ToString() == newCheckoutContenxt.PaymentCategoryID ||
                    x.Key == result.SelShippingAddress.PaymentCategoryID)
                {
                    result.SelPaymentCategoryID = x.Key;
                    return(true);
                }
                return(false);
            }))
            {
                //都没有就取第一条支付类型
                result.SelPaymentCategoryID = result.PaymentCategoryList.First().Key;
            }
            #endregion



            #region 配送方式选择
            //step1 取得配送地址支持的所有配送方式
            List <ShipTypeInfo> ShipTypeInfoList = new List <ShipTypeInfo>();
            List <ShipTypeInfo> shipTypeList     = new List <ShipTypeInfo>();
            foreach (ShoppingItemGroup ShoppingItemGroup in shoppingCart.ShoppingItemGroupList)
            {
                foreach (ShoppingItem ShoppingItem in ShoppingItemGroup.ShoppingItemList)
                {
                    ProductBasicInfo    basicInfo   = ProductFacade.GetProductBasicInfoBySysNo(ShoppingItem.ProductSysNo);
                    List <ShipTypeInfo> ShipTypeNew = ShipTypeFacade.Checkout_GetStockShippingType(basicInfo.VendorSysno);
                    if (ShipTypeNew.Count > 0)
                    {
                        if (ShipTypeInfoList.Count <= 0)
                        {
                            ShipTypeInfoList.AddRange(ShipTypeNew);
                            shipTypeList.AddRange(ShipTypeNew);
                        }
                        else
                        {
                            shipTypeList = new List <ShipTypeInfo>();
                            for (int i = 0; i < ShipTypeInfoList.Count; i++)
                            {
                                for (int j = 0; j < ShipTypeNew.Count; j++)
                                {
                                    if (ShipTypeInfoList[i].ShipTypeName == ShipTypeNew[j].ShipTypeName)
                                    {
                                        shipTypeList.Add(ShipTypeInfoList[i]);
                                    }
                                }
                            }
                            if (shipTypeList.Count <= 0)
                            {
                                result.ErrorMessages.Add("不同商家的商品,没有相同的配送方式,请分开下单!");
                                break;
                            }
                            else
                            {
                                ShipTypeInfoList = shipTypeList;
                            }
                        }
                    }
                    else
                    {
                        string error = string.Format("商品【{0}】没有对应配送方式,暂时无法为您配送!", basicInfo.ProductName);
                        result.ErrorMessages.Add(error);
                        result.ShipTypeList = null;
                        break;
                    }
                }
                if (result.ErrorMessages.Count > 0)
                {
                    break;
                }
            }
            //var shipTypeList = ShipTypeFacade.GetSupportedShipTypeList(result.SelShippingAddress.ReceiveAreaSysNo, null);
            //step2 如果不存在支持货到付款的配送方式, 则移除掉货到付款支付类别
            if (shipTypeList.Count(x => x.IsPayWhenRecv) <= 0)
            {
                result.PaymentCategoryList  = result.PaymentCategoryList.FindAll(x => x.Key == (int)PaymentCategory.OnlinePay);
                result.SelPaymentCategoryID = (int)PaymentCategory.OnlinePay;
            }
            //step3 如果选择的是货到付款,则移除掉不支持货到付款的配送方式
            if (result.SelPaymentCategoryID == (int)PaymentCategory.PayWhenRecv)
            {
                result.ShipTypeList = shipTypeList.Where(x => x.IsPayWhenRecv).ToList();
                //step4 移除掉不支持货到付款的配送方式后没有可用的配送方式时,系统自动选择在线支付
                if (result.ShipTypeList.Count <= 0)
                {
                    result.ShipTypeList         = shipTypeList;
                    result.PaymentCategoryList  = result.PaymentCategoryList.FindAll(x => x.Key == (int)PaymentCategory.OnlinePay);
                    result.SelPaymentCategoryID = (int)PaymentCategory.OnlinePay;
                }
            }
            else
            {
                result.ShipTypeList = shipTypeList;
            }

            //优先取context指定的配送方式
            result.SelShipType = result.ShipTypeList.Find(x => x.ShipTypeSysNo.ToString() == newCheckoutContenxt.ShipTypeID);
            //其次取配送地址指定的配送方式
            if (result.SelShipType == null && result.SelShippingAddress != null)
            {
                result.SelShipType = result.ShipTypeList.Find(x => x.ShipTypeSysNo == result.SelShippingAddress.ShipTypeSysNo);
            }
            //都没有就取第一条配送方式
            if (result.SelShipType == null && result.ShipTypeList.Count > 0)
            {
                result.SelShipType = result.ShipTypeList.First();
            }
            result.ShipTypeList = EnsureNotNullObject(result.ShipTypeList);
            result.SelShipType  = EnsureNotNullObject(result.SelShipType);
            #endregion

            #region 支付方式选择
            result.PayTypeList = GetAllPayTypeList();
            if (result.SelPaymentCategoryID == (int)PaymentCategory.PayWhenRecv)
            {
                result.PayTypeList = result.PayTypeList.FindAll(x => x.IsPayWhenRecv == 1);
            }
            //优先取用户上次下单使用的支付方式
            result.SelPayType = result.PayTypeList.Find(x => x.PayTypeID == memberInfo.ExtendInfo.LastPayTypeSysNo);
            if (result.SelPayType == null && result.PayTypeList.Count > 0)
            {
                result.SelPayType = result.PayTypeList.First();
            }
            if (result.SelPayType != null && result.PayTypeList.Count > 0)
            {
                var cateId             = result.SelPayType.IsPayWhenRecv == 1 ? (int)PaymentCategory.PayWhenRecv : (int)PaymentCategory.OnlinePay;
                var isPayWhenRecvValue = result.SelPaymentCategoryID == (int)PaymentCategory.PayWhenRecv ? 1 : 0;
                //如果上次下单用户使用的支付方式类型跟本次下单选择的支付类型不一致
                //则选择符合当前选择的支付类型的第一个支付方式
                if (cateId != result.SelPaymentCategoryID)
                {
                    result.SelPayType = result.PayTypeList.Where(x => x.IsPayWhenRecv == isPayWhenRecvValue).First();
                }

                if (context != null && context.PayTypeID.HasValue)
                {
                    result.SelPayType = result.PayTypeList.Where(x => x.PayTypeID == context.PayTypeID.Value).First();
                }
            }
            result.PayTypeList = EnsureNotNullObject(result.PayTypeList);
            result.SelPayType  = EnsureNotNullObject(result.SelPayType);
            #endregion

            return(result);
        }
Пример #3
0
        /// <summary>
        /// 获取商品详情
        /// </summary>
        /// <param name="id">系统编号</param>
        /// <param name="isGroupBuy">0--标识id为商品系统编号,1--标识id为团购活动系统编号</param>
        /// <returns></returns>
        public ProductDetailModel GetProductDetails(int id, int isGroupBuy)
        {
            int             productSysNo = 0;
            GroupBuyingInfo groupBuyInfo = null;

            if (isGroupBuy == 1)
            {
                groupBuyInfo = GroupBuyingFacade.GetGroupBuyingInfoBySysNo(id);
                if (groupBuyInfo == null)
                {
                    //提示团购活动找不到
                    throw new BusinessException("团购活动找不到啦,请选购其它商品,谢谢。");
                }
                productSysNo = groupBuyInfo.ProductSysNo;
            }
            else
            {
                productSysNo = id;
            }


            //商品基本信息
            ProductBasicInfo basicInfo = ProductFacade.GetProductBasicInfoBySysNo(productSysNo);

            //商品销售信息
            ProductSalesInfo salesInfo = ProductFacade.GetProductSalesInfoBySysNo(productSysNo);

            if (basicInfo == null || salesInfo == null)
            {
                //提示商品找不到
                throw new BusinessException("商品找不到啦,请选购其它商品,谢谢。");
            }
            //如果是不展示或下架
            if (basicInfo.ProductStatus == ProductStatus.NotShow || basicInfo.ProductStatus == ProductStatus.Abandon)
            {
                //提示商品状态已下架或已作废
                throw new BusinessException("商品已下架或已作废,请选购其它商品,谢谢。");
            }
            //商品组信息
            List <ProductPropertyView> propertyView = ProductFacade.GetProductPropetyView(productSysNo, basicInfo.ProductCommonInfoSysNo);

            //商品附件
            List <ProductItemInfo> attachmentList = ProductFacade.GetProductAttachmentList(productSysNo);

            //商品配件
            List <ProductAccessories> accessoriesList = ProductFacade.GetProductAccessoriesList(productSysNo);

            //商家信息
            StoreBasicInfo storeinfo = StoreFacade.QueryStoreBasicInfo(basicInfo.VendorSysno);

            //商品促销信息
            ProductPromotionInfo promotionInfo = Nesoft.ECWeb.Facade.Product.ProductFacade.GetProductPromotionInfo(productSysNo);

            //商品组图片信息
            List <ProductImage> productImages = ProductFacade.GetProductImages(basicInfo.ProductCommonInfoSysNo);

            //商品内容(商品详情,规格参数,售后服务,购买须知等)
            List <ProductContent> contentList = ProductFacade.GetProductContentList(basicInfo);

            ProductDetailModel result = new ProductDetailModel();

            //基本信息
            result.BasicInfo = TransformBasicInfo(basicInfo);
            //商品销售(价格,库存等)信息
            result.SalesInfo = TransformSalesInfo(basicInfo, salesInfo);

            //商品图片列表
            result.ImageList = TransformImageList(productImages);
            //商品描述信息
            result.DescInfo = TransformDescInfo(contentList);
            //if (result.DescInfo != null && basicInfo != null)
            //    result.DescInfo.Performance = basicInfo.Performance;


            //分组属性
            result.GroupPropertyInfo = TransformGroupProperty(propertyView);
            //附件信息
            result.AttachmentInfo = TransformAttachmentInfo(attachmentList);
            //配件信息
            result.AccessoryList = TransformAccessoryInfo(accessoriesList);

            //商家信息
            result.StoreBasicInfo = Transformstoreinfo(storeinfo);


            //限时抢购,赠品,套餐等促销信息
            result.PromoInfo = TransformPromoInfo(promotionInfo);

            //如果是团购商品进一步加载团购详情
            if (promotionInfo != null && promotionInfo.GroupBuySysNo > 0)
            {
                if (groupBuyInfo == null)
                {
                    groupBuyInfo = GroupBuyingFacade.GetGroupBuyingInfoBySysNo(promotionInfo.GroupBuySysNo);
                }
                if (groupBuyInfo == null)
                {
                    result.PromoInfo.GroupBuyingSysNo = 0;
                }
                else
                {
                    //团购图片特殊处理,用活动设置的图片
                    result.BasicInfo.DefaultImageUrl = groupBuyInfo.GroupBuyingPicUrl;
                    result.ImageList.Clear();
                    ProductImageModel groupBuyImage = new ProductImageModel();
                    groupBuyImage.ImageUrlBig  = groupBuyInfo.GroupBuyingPicUrl;
                    groupBuyImage.ImageUrlHuge = groupBuyInfo.GroupBuyingPicUrl;
                    result.ImageList.Add(groupBuyImage);
                    //海外团购商品,算税
                    if (groupBuyInfo.GroupBuyingTypeSysNo == 0)
                    {
                        result.SalesInfo.TariffPrice = salesInfo.CurrentPrice * salesInfo.TariffRate;

                        if (result.SalesInfo.TariffPrice <= ConstValue.TariffFreeLimit)
                        {
                            result.SalesInfo.FreeEntryTax = true;
                            result.SalesInfo.TotalPrice   = salesInfo.CurrentPrice;
                        }
                        else
                        {
                            result.SalesInfo.FreeEntryTax = false;
                            result.SalesInfo.TotalPrice   = salesInfo.CurrentPrice + result.SalesInfo.TariffPrice;
                        }
                        decimal snapShotTariffPrice = groupBuyInfo.SnapShotCurrentPrice * salesInfo.TariffRate;
                        if (snapShotTariffPrice <= ConstValue.TariffFreeLimit)
                        {
                            snapShotTariffPrice = 0;
                        }
                        result.SalesInfo.BasicPrice = groupBuyInfo.SnapShotCurrentPrice + groupBuyInfo.SnapShotCashRebate + snapShotTariffPrice;
                    }
                    else
                    {
                        result.SalesInfo.BasicPrice   = groupBuyInfo.SnapShotCurrentPrice + groupBuyInfo.SnapShotCashRebate;
                        result.SalesInfo.TotalPrice   = salesInfo.CurrentPrice;
                        result.SalesInfo.TariffPrice  = 0;
                        result.SalesInfo.FreeEntryTax = false;
                    }
                    groupBuyInfo.MarketPrice = result.SalesInfo.BasicPrice;

                    result.GroupBuyInfo = MapGroupBuyInfo(groupBuyInfo);
                }
            }
            if (promotionInfo != null && promotionInfo.Countdown != null)
            {
                //限时抢购重算市场价
                decimal snapShotTariffPrice = promotionInfo.Countdown.SnapShotCurrentPrice * salesInfo.TariffRate;
                if (snapShotTariffPrice <= ConstValue.TariffFreeLimit)
                {
                    snapShotTariffPrice = 0;
                }
                result.SalesInfo.BasicPrice = promotionInfo.Countdown.SnapShotCurrentPrice + promotionInfo.Countdown.SnapShotCashRebate + snapShotTariffPrice;
            }

            result.ActionInfo = MapActionInfo(result);

            return(result);
        }