예제 #1
0
        /// <summary>
        /// 购物车
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();
            //用于计算会员价:
            LoginUser userInfo = UserMgr.ReadUserInfo();

            shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;
            if (shoppingCart != null)
            {
                ShoppingStorageManager.SaveShoppingCart(shoppingCart);
            }
            OrderPipelineProcessResult shoppingResult = ShoppingFacade.BuildShoppingCart(shoppingCart);
            ShoppingCart pipelineShoppingCart         = (shoppingResult.ReturnData != null &&
                                                         shoppingResult.ReturnData["ShoppingCart"] != null)
                ? shoppingResult.ReturnData["ShoppingCart"] as ShoppingCart
                : new ShoppingCart();

            shoppingCart.OrderSelectGiftSysNo = pipelineShoppingCart.OrderSelectGiftSysNo;
            shoppingCart.OrderDeleteGiftSysNo = pipelineShoppingCart.OrderDeleteGiftSysNo;
            ShoppingStorageManager.SaveShoppingCart(shoppingCart);

            //将迷你购物车加入Cookie
            ShoppingStorageManager.SaveShoppingCartMini(ShoppingFacade.BuildMiniShoppingCartFromPipeline(shoppingResult));

            return(View(shoppingResult));
        }
예제 #2
0
        public static AjaxResult AddToShoppingCart(UpdateCartReqModel req)
        {
            AjaxResult result = new AjaxResult();

            result.Success = false;
            int totalProduct = 0;

            #region Check
            string checkResultMessage = "";
            if (req.SysNo <= 0)
            {
                if (req.IsPackage)
                {
                    checkResultMessage = "请输入正确的套餐编号!";
                }
                else
                {
                    checkResultMessage = "请输入正确的商品编号!";
                }
            }
            else if (req.Qty <= 0)
            {
                checkResultMessage = "请输入正确的商品数量";
            }

            #endregion

            #region 加入购物车
            if (string.IsNullOrWhiteSpace(checkResultMessage))
            {
                result.Success     = true;
                checkResultMessage = "加入购物车失败";
                ShoppingItemGroup shoppingItemGroup = ShoppingFacade.BuildShoppingItemGroup(req.IsPackage ? "package" : "product", req.SysNo, req.Qty);
                ShoppingCart      shoppingCart      = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();

                if (shoppingItemGroup != null)
                {
                    ShoppingFacade.AddToShoppingCart(shoppingItemGroup, shoppingCart);
                    ShoppingStorageManager.SaveShoppingCart(shoppingCart);
                    checkResultMessage = "加入购物车成功";
                }
                //计算购物商品数量
                if (shoppingCart != null && shoppingCart.ShoppingItemGroupList != null)
                {
                    foreach (var itemGroup in shoppingCart.ShoppingItemGroupList)
                    {
                        foreach (var item in itemGroup.ShoppingItemList)
                        {
                            totalProduct += itemGroup.Quantity * item.UnitQuantity;
                        }
                    }
                }
            }
            result.Data    = totalProduct;
            result.Message = checkResultMessage;

            #endregion

            return(result);
        }
예제 #3
0
        /// <summary>
        /// 加载购物车信息
        /// </summary>
        /// <returns>购物车信息</returns>
        private PartialViewResult LoadShoppingCartData(ShoppingCart shoppingCart, string errorMessage = "")
        {
            //Key添加CustomerSysNo
            LoginUser userInfo = UserManager.ReadUserInfo();

            shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;
            OrderPipelineProcessResult shoppingResult = ShoppingFacade.BuildShoppingCart(shoppingCart);
            ShoppingCart pipelineShoppingCart         = (shoppingResult.ReturnData != null &&
                                                         shoppingResult.ReturnData["ShoppingCart"] != null)
                ? shoppingResult.ReturnData["ShoppingCart"] as ShoppingCart
                : ShoppingStorageManager.GetShoppingCartFromCreateNew();

            shoppingCart.OrderSelectGiftSysNo = pipelineShoppingCart.OrderSelectGiftSysNo;
            shoppingCart.OrderDeleteGiftSysNo = pipelineShoppingCart.OrderDeleteGiftSysNo;
            ShoppingStorageManager.SaveShoppingCart(shoppingCart);

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                //更改失败返回错误信息
                if (shoppingResult.ErrorMessages != null)
                {
                    shoppingResult.ErrorMessages = new List <string>()
                    {
                        errorMessage
                    };
                }
                else
                {
                    shoppingResult.ErrorMessages.Add(errorMessage);
                }
            }

            return(PartialView("_ShoppingCartPanel", shoppingResult));
        }
예제 #4
0
        /// <summary>
        /// 结算页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Checkout()
        {
            ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();

            if (ShoppingCartIsEmpty(shoppingCart))
            {
                return(Redirect(PageHelper.BuildUrl("ShoppingCart")));
            }

            var checkOutResult = ShoppingFacade.BuildCheckOut(null, shoppingCart, CurrUser.UserSysNo);

            //重新保存一次购物车cookie,在购物流程中会对购物车中库存数量不足的赠品进行剔除
            ShoppingCart pipelineShoppingCart = (checkOutResult.OrderProcessResult != null &&
                                                 checkOutResult.OrderProcessResult.ReturnData != null &&
                                                 checkOutResult.OrderProcessResult.ReturnData["ShoppingCart"] != null)
                ? checkOutResult.OrderProcessResult.ReturnData["ShoppingCart"] as ShoppingCart
                : ShoppingStorageManager.GetShoppingCartFromCookie();
            //Key添加CustomerSysNo
            LoginUser userInfo = UserManager.ReadUserInfo();

            shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;
            ShoppingStorageManager.SaveShoppingCart(pipelineShoppingCart);

            return(View(checkOutResult));
        }
예제 #5
0
        /// <summary>
        /// Mini购物车删除商品
        /// </summary>
        /// <returns></returns>
        public PartialViewResult DelMiniShoppingCartProduct()
        {
            #region Check
            bool checkResult  = true;
            int  packageSysNo = 0;
            int  productSysNo = 0;
            if (!int.TryParse(Request.Params["PackageSysNo"], out packageSysNo))
            {
                checkResult = false;
            }
            else if (!int.TryParse(Request.Params["ProductSysNo"], out productSysNo))
            {
                checkResult = false;
            }
            #endregion

            ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();
            if (checkResult)
            {
                if (packageSysNo.Equals(0))
                {
                    //删除单个商品
                    shoppingCart = DelProductCalcShoppingCart(shoppingCart, productSysNo);
                }
                else
                {
                    //删除套餐中的商品
                    shoppingCart = DelPackageProductCalcShoppingCart(shoppingCart, packageSysNo, productSysNo);
                }
            }
            OrderPipelineProcessResult pipelineShoppingResult = null;
            ShoppingCartMiniResult     shoppingResult         = ShoppingFacade.BuildMiniShoppingCart(shoppingCart, out pipelineShoppingResult);
            ShoppingCart pipelineShoppingCart = (pipelineShoppingResult.ReturnData != null &&
                                                 pipelineShoppingResult.ReturnData["ShoppingCart"] != null)
                ? pipelineShoppingResult.ReturnData["ShoppingCart"] as ShoppingCart
                : new ShoppingCart();
            shoppingCart.OrderSelectGiftSysNo = pipelineShoppingCart.OrderSelectGiftSysNo;
            shoppingCart.OrderDeleteGiftSysNo = pipelineShoppingCart.OrderDeleteGiftSysNo;
            //Key添加CustomerSysNo
            LoginUser userInfo = UserMgr.ReadUserInfo();
            shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;
            ShoppingStorageManager.SaveShoppingCart(shoppingCart);
            //将迷你购物车加入Cookie
            ShoppingStorageManager.SaveShoppingCartMini(ShoppingFacade.BuildMiniShoppingCartFromPipeline(pipelineShoppingResult));

            return(PartialView("_ShoppingCartMini", shoppingResult));
        }
예제 #6
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));
        }
예제 #7
0
        private CheckOutResult BuildCheckout(CheckOutContext context)
        {
            if (context == null)
            {
                throw new BusinessException("无效的请求");
            }
            ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartFromCreateNew();

            //优先从购买商品参数来构建购物车对象
            if (!String.IsNullOrWhiteSpace(context.ShoppingItemParam))
            {
                String[] shoppingItemParams = context.ShoppingItemParam.Split(new char[] { '|' });
                if (shoppingItemParams.Length == 2)
                {
                    shoppingCart = ShoppingStorageManager.GetShoppingCartFromParam(shoppingItemParams[0], shoppingItemParams[1]);
                }
            }
            //其次从cookie中来构建购物车对象
            if (ShoppingCartIsEmpty(shoppingCart))
            {
                shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();
            }

            var checkOutResult = ShoppingFacade.BuildCheckOut(context, shoppingCart, CurrUser.UserSysNo);

            //重新保存一次购物车cookie,在购物流程中会对购物车中库存数量不足的赠品进行剔除
            //fixbug: 直接购物车下单不应该影响购物车Cookie
            if (String.IsNullOrWhiteSpace(context.ShoppingItemParam))
            {
                ShoppingCart pipelineShoppingCart = (checkOutResult.OrderProcessResult != null &&
                                                     checkOutResult.OrderProcessResult.ReturnData != null &&
                                                     checkOutResult.OrderProcessResult.ReturnData["ShoppingCart"] != null)
                    ? checkOutResult.OrderProcessResult.ReturnData["ShoppingCart"] as ShoppingCart
                    : ShoppingStorageManager.GetShoppingCartFromCookie();

                //Key添加CustomerSysNo
                LoginUser userInfo = UserManager.ReadUserInfo();
                shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;
                ShoppingStorageManager.SaveShoppingCart(pipelineShoppingCart);
            }

            return(checkOutResult);
        }
예제 #8
0
        public static CheckOutResultModel AjaxBuildCheckOut(CheckOutContext context)
        {
            if (context == null)
            {
                throw new BusinessException("无效的请求");
            }

            ShoppingCart shoppingCart    = ShoppingStorageManager.GetShoppingCartFromCreateNew();
            ShoppingCart shoppingCartNew = ShoppingStorageManager.GetShoppingCartFromCreateNew();

            //优先从购买商品参数来构建购物车对象
            if (!String.IsNullOrWhiteSpace(context.ShoppingItemParam))
            {
                String[] shoppingItemParams = context.ShoppingItemParam.Split(new char[] { '|' });
                if (shoppingItemParams.Length == 2)
                {
                    shoppingCartNew = ShoppingStorageManager.GetShoppingCartFromParam(shoppingItemParams[0], shoppingItemParams[1]);
                }
            }
            //其次从cookie中来构建购物车对象
            if (ShoppingCartIsEmpty(shoppingCartNew))
            {
                shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();
                ShoppingItemGroup ShoppingItem = new ShoppingItemGroup();
                shoppingCartNew.ShoppingItemGroupList = shoppingCart.ShoppingItemGroupList.FindAll(m => m.PackageChecked);
            }

            shoppingCartNew.OrderDeleteGiftSysNo = shoppingCart.OrderDeleteGiftSysNo;
            shoppingCartNew.OrderSelectGiftSysNo = shoppingCart.OrderSelectGiftSysNo;

            var checkOutResult        = ShoppingFacade.BuildCheckOut(context, shoppingCartNew, UserMgr.ReadUserInfo().UserSysNo);
            CheckOutResultModel model = OrderMapping.MappingCheckOutResult(checkOutResult);

            //重新保存一次购物车cookie,在购物流程中会对购物车中库存数量不足的赠品进行剔除
            //fixbug: 直接购物车下单不应该影响购物车Cookie
            if (String.IsNullOrWhiteSpace(context.ShoppingItemParam))
            {
                ShoppingStorageManager.SaveShoppingCart(GetShoppingCart(checkOutResult));
            }

            return(model);
        }
예제 #9
0
        //
        // GET: /Shopping/

        public ActionResult Index()
        {
            ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();
            OrderPipelineProcessResult shoppingResult = ShoppingFacade.BuildShoppingCart(shoppingCart);
            ShoppingCart pipelineShoppingCart         = (shoppingResult.ReturnData != null &&
                                                         shoppingResult.ReturnData["ShoppingCart"] != null)
                ? shoppingResult.ReturnData["ShoppingCart"] as ShoppingCart
                : ShoppingStorageManager.GetShoppingCartFromCreateNew();

            shoppingCart.OrderSelectGiftSysNo = pipelineShoppingCart.OrderSelectGiftSysNo;
            shoppingCart.OrderDeleteGiftSysNo = pipelineShoppingCart.OrderDeleteGiftSysNo;

            //Key添加CustomerSysNo
            LoginUser userInfo = UserManager.ReadUserInfo();

            shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;
            ShoppingStorageManager.SaveShoppingCart(shoppingCart);

            return(View(shoppingResult));
        }
예제 #10
0
        /// <summary>
        /// Mini购物车获取商品数量
        /// </summary>
        /// <returns></returns>
        public JsonResult GetMiniShoppingCartCount()
        {
            int          totalProductCount = 0;
            ShoppingCart shoppingCart      = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();
            //Key添加CustomerSysNo
            LoginUser userInfo = UserManager.ReadUserInfo();

            shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;
            if (shoppingCart != null && shoppingCart.ShoppingItemGroupList != null)
            {
                foreach (var itemGroup in shoppingCart.ShoppingItemGroupList)
                {
                    foreach (var item in itemGroup.ShoppingItemList)
                    {
                        totalProductCount += itemGroup.Quantity * item.UnitQuantity;
                    }
                }
            }
            ShoppingStorageManager.SaveShoppingCart(shoppingCart);
            return(new JsonResult()
            {
                Data = totalProductCount, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
예제 #11
0
        /// <summary>
        /// 普通商品checkout
        /// </summary>
        /// <returns></returns>
        public static CheckOutResultModel Checkout(string proSysNos = null, string packSysNos = null)
        {
            ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();

            #region 得到新的shoppingCart
            ShoppingCart             shoppingCartNew = ShoppingStorageManager.GetShoppingCartFromCreateNew();
            List <ShoppingItemGroup> ShoppingItem    = new List <ShoppingItemGroup>();
            //套餐
            ShoppingItem = shoppingCart.ShoppingItemGroupList.FindAll(m =>
                                                                      (m.PackageType.Equals(1) && m.PackageChecked));
            shoppingCartNew.ShoppingItemGroupList.AddRange(ShoppingItem);
            //单个商品
            ShoppingItem = shoppingCart.ShoppingItemGroupList.FindAll(m =>
                                                                      (m.PackageType.Equals(0) && m.ShoppingItemList[0].ProductChecked));
            shoppingCartNew.ShoppingItemGroupList.AddRange(ShoppingItem);
            #endregion
            if (ShoppingCartIsEmpty(shoppingCartNew))
            {
                throw new BusinessException("购物车不能为空");
            }
            shoppingCartNew.OrderDeleteGiftSysNo = shoppingCart.OrderDeleteGiftSysNo;
            shoppingCartNew.OrderSelectGiftSysNo = shoppingCart.OrderSelectGiftSysNo;

            LoginUser userInfo = UserMgr.ReadUserInfo();
            shoppingCartNew.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;
            var checkOutResult = ShoppingFacade.BuildCheckOut(null, shoppingCartNew, userInfo.UserSysNo);

            checkOutResult.PackageTypeGroupList  = packSysNos;
            checkOutResult.PackageTypeSingleList = proSysNos;

            CheckOutResultModel model = OrderMapping.MappingCheckOutResult(checkOutResult);

            ShoppingStorageManager.SaveShoppingCart(GetShoppingCart(checkOutResult));

            return(model);
        }
예제 #12
0
        public ActionResult AjaxBuildCheckOut(CheckOutContext context)
        {
            if (context == null)
            {
                throw new BusinessException("无效的请求");
            }

            ShoppingCart shoppingCart    = ShoppingStorageManager.GetShoppingCartFromCreateNew();
            ShoppingCart shoppingCartNew = ShoppingStorageManager.GetShoppingCartFromCreateNew();

            //优先从购买商品参数来构建购物车对象
            if (!String.IsNullOrWhiteSpace(context.ShoppingItemParam))
            {
                String[] shoppingItemParams = context.ShoppingItemParam.Split(new char[] { '|' });
                if (shoppingItemParams.Length == 2)
                {
                    shoppingCartNew = ShoppingStorageManager.GetShoppingCartFromParam(shoppingItemParams[0], shoppingItemParams[1]);
                }
            }
            //其次从cookie中来构建购物车对象
            if (ShoppingCartIsEmpty(shoppingCartNew))
            {
                shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();
                ShoppingItemGroup ShoppingItem = new ShoppingItemGroup();
                if (!string.IsNullOrEmpty(context.PackageTypeGroupList))
                {
                    string[] array = context.PackageTypeGroupList.Split(',');
                    foreach (var item in array)
                    {
                        int sysNo = 0;
                        if (int.TryParse(item, out sysNo))
                        {
                            ShoppingItem = shoppingCart.ShoppingItemGroupList.FindAll(m =>
                                                                                      (m.PackageType.Equals(1) && m.PackageNo.Equals(sysNo)))[0];
                            shoppingCartNew.ShoppingItemGroupList.Add(ShoppingItem);
                        }
                    }
                }

                if (!string.IsNullOrEmpty(context.PackageTypeSingleList))
                {
                    string[] array = context.PackageTypeSingleList.Split(',');
                    foreach (var item in array)
                    {
                        int sysNo = 0;
                        if (int.TryParse(item, out sysNo))
                        {
                            ShoppingItem = shoppingCart.ShoppingItemGroupList.FindAll(m =>
                                                                                      (m.PackageType.Equals(0) && m.ShoppingItemList[0].ProductSysNo.Equals(sysNo)))[0];
                            shoppingCartNew.ShoppingItemGroupList.Add(ShoppingItem);
                        }
                    }
                }
            }

            shoppingCartNew.OrderDeleteGiftSysNo = shoppingCart.OrderDeleteGiftSysNo;
            shoppingCartNew.OrderSelectGiftSysNo = shoppingCart.OrderSelectGiftSysNo;

            var checkOutResult = ShoppingFacade.BuildCheckOut(context, shoppingCartNew, CurrUser.UserSysNo);

            //重新保存一次购物车cookie,在购物流程中会对购物车中库存数量不足的赠品进行剔除
            //fixbug: 直接购物车下单不应该影响购物车Cookie
            if (String.IsNullOrWhiteSpace(context.ShoppingItemParam))
            {
                ShoppingCart pipelineShoppingCart = (checkOutResult.OrderProcessResult != null &&
                                                     checkOutResult.OrderProcessResult.ReturnData != null &&
                                                     checkOutResult.OrderProcessResult.ReturnData["shoppingCartNew"] != null)
                    ? checkOutResult.OrderProcessResult.ReturnData["shoppingCartNew"] as ShoppingCart
                    : ShoppingStorageManager.GetShoppingCartFromCookie();


                //Key添加CustomerSysNo
                LoginUser userInfo = UserMgr.ReadUserInfo();
                pipelineShoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;
                ShoppingStorageManager.SaveShoppingCart(pipelineShoppingCart);
            }

            checkOutResult = CalcGroupBuyTag(checkOutResult);

            return(PartialView("_CheckOutEditPanel", checkOutResult));
        }
예제 #13
0
        /// <summary>
        /// 普通商品checkout
        /// </summary>
        /// <returns></returns>
        public ActionResult Checkout()
        {
            ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();

            #region 得到新的shoppingCart
            ShoppingCart      shoppingCartNew       = ShoppingStorageManager.GetShoppingCartFromCreateNew();
            string            PackageTypeSingleList = Request.QueryString["PackageTypeSingle"];
            string            PackageTypeGroupList  = Request.QueryString["PackageTypeGroup"];
            ShoppingItemGroup ShoppingItem          = new ShoppingItemGroup();
            if (!string.IsNullOrEmpty(PackageTypeGroupList))
            {
                string[] array = PackageTypeGroupList.Split(',');
                foreach (var item in array)
                {
                    int sysNo = 0;
                    if (int.TryParse(item, out sysNo))
                    {
                        ShoppingItem = shoppingCart.ShoppingItemGroupList.FindAll(m =>
                                                                                  (m.PackageType.Equals(1) && m.PackageNo.Equals(sysNo)))[0];
                        shoppingCartNew.ShoppingItemGroupList.Add(ShoppingItem);
                    }
                }
            }

            if (!string.IsNullOrEmpty(PackageTypeSingleList))
            {
                string[] array = PackageTypeSingleList.Split(',');
                foreach (var item in array)
                {
                    int sysNo = 0;
                    if (int.TryParse(item, out sysNo))
                    {
                        ShoppingItem = shoppingCart.ShoppingItemGroupList.FindAll(m =>
                                                                                  (m.PackageType.Equals(0) && m.ShoppingItemList[0].ProductSysNo.Equals(sysNo)))[0];
                        shoppingCartNew.ShoppingItemGroupList.Add(ShoppingItem);
                    }
                }
            }
            #endregion
            if (ShoppingCartIsEmpty(shoppingCartNew))
            {
                return(Redirect(PageHelper.BuildUrl("ShoppingCartRoute")));
            }
            shoppingCartNew.OrderDeleteGiftSysNo = shoppingCart.OrderDeleteGiftSysNo;
            shoppingCartNew.OrderSelectGiftSysNo = shoppingCart.OrderSelectGiftSysNo;

            LoginUser userInfo = UserMgr.ReadUserInfo();
            shoppingCartNew.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;
            var checkOutResult = ShoppingFacade.BuildCheckOut(null, shoppingCartNew, CurrUser.UserSysNo);
            checkOutResult.PackageTypeGroupList  = PackageTypeGroupList;
            checkOutResult.PackageTypeSingleList = PackageTypeSingleList;

            int bankAccountPoint = 0;
            bankAccountPoint = CookieHelper.GetCookie <int>("BankAccountPoint"); //获取网银用户积分
            checkOutResult.Customer.BankAccountPoint = bankAccountPoint;
            ViewBag.IsBankingAccount = bankAccountPoint > 0;                     //仅当网银积分>0方才显示该区域

            //重新保存一次购物车cookie,在购物流程中会对购物车中库存数量不足的赠品进行剔除
            ShoppingCart pipelineShoppingCart = (checkOutResult.OrderProcessResult != null &&
                                                 checkOutResult.OrderProcessResult.ReturnData != null &&
                                                 checkOutResult.OrderProcessResult.ReturnData["shoppingCartNew"] != null)
                ? checkOutResult.OrderProcessResult.ReturnData["shoppingCartNew"] as ShoppingCart
                : ShoppingStorageManager.GetShoppingCartFromCookie();

            ShoppingStorageManager.SaveShoppingCart(pipelineShoppingCart);

            checkOutResult = CalcGroupBuyTag(checkOutResult);

            return(View(checkOutResult));
        }
예제 #14
0
        private static CartResultModel BuilderOrderResultModel(ShoppingCart shoppingCart, string errorMessage = null, string proSysNos = null, string packSysNos = null)
        {
            if (proSysNos != null || packSysNos != null)
            {
                foreach (var itemGroup in shoppingCart.ShoppingItemGroupList)
                {
                    itemGroup.PackageChecked = false;
                    foreach (ShoppingItem ProductItem in itemGroup.ShoppingItemList)
                    {
                        ProductItem.ProductChecked = false;
                    }
                }
                //checkbox单个商品购买
                if (!string.IsNullOrEmpty(proSysNos))
                {
                    string[] array = proSysNos.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var item in array)
                    {
                        int sysNo = 0;
                        if (int.TryParse(item, out sysNo))
                        {
                            foreach (var itemGroup in shoppingCart.ShoppingItemGroupList)
                            {
                                if (itemGroup.PackageType.Equals(0))
                                {
                                    if (!itemGroup.PackageChecked)
                                    {
                                        foreach (ShoppingItem ProductItem in itemGroup.ShoppingItemList)
                                        {
                                            if (ProductItem.ProductSysNo == sysNo && !ProductItem.ProductChecked)
                                            {
                                                itemGroup.PackageChecked   = true;
                                                ProductItem.ProductChecked = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //checkbox套餐商品购买
                if (!string.IsNullOrEmpty(packSysNos))
                {
                    string[] array = packSysNos.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var item in array)
                    {
                        int sysNo = 0;
                        if (int.TryParse(item, out sysNo))
                        {
                            foreach (var itemGroup in shoppingCart.ShoppingItemGroupList)
                            {
                                if (itemGroup.PackageType.Equals(1))
                                {
                                    if (!itemGroup.PackageChecked)
                                    {
                                        if (itemGroup.PackageNo == sysNo)
                                        {
                                            itemGroup.PackageChecked = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            ////ShoppingCart pipelineShoppingCart = shoppingCart;
            //if (shoppingCart.ShoppingItemGroupList.Count == 1)
            //{
            //    foreach (var itemGroup in shoppingCart.ShoppingItemGroupList)
            //    {
            //        foreach (ShoppingItem ProductItem in itemGroup.ShoppingItemList)
            //        {
            //            itemGroup.PackageChecked = true;
            //            ProductItem.ProductChecked = true;
            //        }
            //    }
            //}
            //if (shoppingCart.ShoppingItemGroupList.Count > 1)
            //{
            //    if (shoppingCart.ShoppingItemGroupList.FindAll(m => m.PackageChecked).Count == 0)
            //    {
            //        if (shoppingCart.ShoppingItemGroupList[0].PackageType.Equals(1))
            //        {
            //            shoppingCart.ShoppingItemGroupList[0].PackageChecked = true;
            //        }
            //        if (shoppingCart.ShoppingItemGroupList[0].PackageType.Equals(0))
            //        {
            //            foreach (ShoppingItem ProductItem in shoppingCart.ShoppingItemGroupList[0].ShoppingItemList)
            //            {
            //                shoppingCart.ShoppingItemGroupList[0].PackageChecked = true;
            //                ProductItem.ProductChecked = true;
            //            }
            //        }
            //    }
            //}
            LoginUser userInfo = UserMgr.ReadUserInfo();

            shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;
            OrderPipelineProcessResult shoppingResult = ShoppingFacade.BuildShoppingCart(shoppingCart);
            ShoppingCart pipelineShoppingCart         = (shoppingResult.ReturnData != null &&
                                                         shoppingResult.ReturnData["ShoppingCart"] != null)
                ? shoppingResult.ReturnData["ShoppingCart"] as ShoppingCart
                : new ShoppingCart();

            shoppingCart.OrderSelectGiftSysNo = pipelineShoppingCart.OrderSelectGiftSysNo;
            shoppingCart.OrderDeleteGiftSysNo = pipelineShoppingCart.OrderDeleteGiftSysNo;

            CartResultModel model = new CartResultModel();

            model.HasSucceed    = shoppingResult.HasSucceed;
            model.ErrorMessages = shoppingResult.ErrorMessages;
            if (!string.IsNullOrEmpty(errorMessage))
            {
                model.ErrorMessages.Add(errorMessage);
            }

            OrderInfo orderInfo = shoppingResult.ReturnData;

            if (orderInfo != null)
            {
                OrderInfoModel orderInfoModel = OrderMapping.MappingOrderInfo(orderInfo, "Cart");
                if (!string.IsNullOrEmpty(orderInfo.WarmTips))
                {
                    model.ErrorMessages.Add(orderInfo.WarmTips);
                }

                model.ReturnData = orderInfoModel;
            }

            ShoppingStorageManager.SaveShoppingCart(shoppingCart);

            return(model);
        }
예제 #15
0
        /// <summary>
        /// 加载购物车信息
        /// </summary>
        /// <returns>购物车信息</returns>
        private PartialViewResult LoadShoppingCartData(ShoppingCart shoppingCart, string errorMessage = "", string PackageTypeSingleList = "", string PackageTypeGroupList = "")
        {
            foreach (var itemGroup in shoppingCart.ShoppingItemGroupList)
            {
                itemGroup.PackageChecked = false;
                foreach (ShoppingItem ProductItem in itemGroup.ShoppingItemList)
                {
                    ProductItem.ProductChecked = false;
                }
            }
            //checkbox单个商品购买
            if (!string.IsNullOrEmpty(PackageTypeSingleList))
            {
                string[] array = PackageTypeSingleList.Split(',');
                foreach (var item in array)
                {
                    int sysNo = 0;
                    if (int.TryParse(item, out sysNo))
                    {
                        foreach (var itemGroup in shoppingCart.ShoppingItemGroupList)
                        {
                            if (itemGroup.PackageType.Equals(0))
                            {
                                if (!itemGroup.PackageChecked)
                                {
                                    foreach (ShoppingItem ProductItem in itemGroup.ShoppingItemList)
                                    {
                                        if (ProductItem.ProductSysNo == sysNo && !ProductItem.ProductChecked)
                                        {
                                            itemGroup.PackageChecked   = true;
                                            ProductItem.ProductChecked = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //checkbox套餐商品购买
            if (!string.IsNullOrEmpty(PackageTypeGroupList))
            {
                string[] array = PackageTypeGroupList.Split(',');
                foreach (var item in array)
                {
                    int sysNo = 0;
                    if (int.TryParse(item, out sysNo))
                    {
                        foreach (var itemGroup in shoppingCart.ShoppingItemGroupList)
                        {
                            if (itemGroup.PackageType.Equals(1))
                            {
                                if (!itemGroup.PackageChecked)
                                {
                                    if (itemGroup.PackageNo == sysNo)
                                    {
                                        itemGroup.PackageChecked = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }



            //用于计算会员价:
            LoginUser userInfo = UserMgr.ReadUserInfo();

            shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;
            OrderPipelineProcessResult shoppingResult = ShoppingFacade.BuildShoppingCart(shoppingCart);
            ShoppingCart pipelineShoppingCart         = (shoppingResult.ReturnData != null &&
                                                         shoppingResult.ReturnData["ShoppingCart"] != null)
                ? shoppingResult.ReturnData["ShoppingCart"] as ShoppingCart
                : new ShoppingCart();

            shoppingCart.OrderSelectGiftSysNo = pipelineShoppingCart.OrderSelectGiftSysNo;
            shoppingCart.OrderDeleteGiftSysNo = pipelineShoppingCart.OrderDeleteGiftSysNo;
            ////checkbox单个商品购买
            //if (!string.IsNullOrEmpty(PackageTypeSingleList))
            //{
            //    string[] array = PackageTypeSingleList.Split(',');
            //    foreach (var item in array)
            //    {
            //        int sysNo = 0;
            //        if (int.TryParse(item, out sysNo))
            //        {
            //            foreach (var itemGroup in shoppingResult.ReturnData.OrderItemGroupList)
            //            {
            //                if (itemGroup.PackageType.Equals(0))
            //                {
            //                    foreach (OrderProductItem ProductItem in itemGroup.ProductItemList)
            //                    {
            //                        if (ProductItem.ProductSysNo == sysNo && ProductItem.ProductChecked == false)
            //                        {
            //                            itemGroup.PackageChecked = true;
            //                            ProductItem.ProductChecked = true;
            //                        }
            //                    }
            //                }
            //            }
            //        }
            //    }
            //}
            ////checkbox套餐商品购买
            //if (!string.IsNullOrEmpty(PackageTypeGroupList))
            //{
            //    string[] array = PackageTypeGroupList.Split(',');
            //    foreach (var item in array)
            //    {
            //        int sysNo = 0;
            //        if (int.TryParse(item, out sysNo))
            //        {
            //            foreach (var itemGroup in shoppingResult.ReturnData.OrderItemGroupList)
            //            {
            //                if (itemGroup.PackageType.Equals(1))
            //                {
            //                    if (itemGroup.PackageNo == sysNo && itemGroup.PackageChecked == false)
            //                    {
            //                        itemGroup.PackageChecked = true;
            //                    }
            //                }
            //            }
            //        }
            //    }
            //}



            ShoppingStorageManager.SaveShoppingCart(shoppingCart);
            //将迷你购物车加入Cookie
            ShoppingStorageManager.SaveShoppingCartMini(ShoppingFacade.BuildMiniShoppingCartFromPipeline(shoppingResult));

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                //更改失败返回错误信息
                if (shoppingResult.ErrorMessages != null)
                {
                    shoppingResult.ErrorMessages = new List <string>()
                    {
                        errorMessage
                    };
                }
                else
                {
                    shoppingResult.ErrorMessages.Add(errorMessage);
                }
            }

            return(PartialView("_ShoppingCartPanel", shoppingResult));
        }
예제 #16
0
        public static AjaxResult AjaxSubmitCheckout(CheckOutContext context)
        {
            AjaxResult ajaxResult = new AjaxResult();

            ajaxResult.Success = false;
            ajaxResult.Code    = -1;
            if (context == null)
            {
                ajaxResult.Code    = -2;
                ajaxResult.Message = "无效的请求";

                return(ajaxResult);
            }

            ShoppingCart shoppingCart    = ShoppingStorageManager.GetShoppingCartFromCreateNew();
            ShoppingCart shoppingCartNew = ShoppingStorageManager.GetShoppingCartFromCreateNew();

            //优先从购买商品参数来构建购物车对象
            if (!String.IsNullOrWhiteSpace(context.ShoppingItemParam))
            {
                String[] shoppingItemParams = context.ShoppingItemParam.Split(new char[] { '|' });
                if (shoppingItemParams.Length == 2)
                {
                    shoppingCartNew = ShoppingStorageManager.GetShoppingCartFromParam(shoppingItemParams[0], shoppingItemParams[1]);
                }
            }
            //其次从cookie中来构建购物车对象
            if (ShoppingCartIsEmpty(shoppingCartNew))
            {
                shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();
                ShoppingItemGroup ShoppingItem = new ShoppingItemGroup();
                shoppingCartNew.ShoppingItemGroupList = shoppingCart.ShoppingItemGroupList.FindAll(m => m.PackageChecked);
            }

            if (ShoppingCartIsEmpty(shoppingCartNew))
            {
                ajaxResult.Code    = -3;
                ajaxResult.Message = "空购物车";

                return(ajaxResult);
            }
            shoppingCartNew.OrderDeleteGiftSysNo = shoppingCart.OrderDeleteGiftSysNo;
            shoppingCartNew.OrderSelectGiftSysNo = shoppingCart.OrderSelectGiftSysNo;
            CheckOutResult result = ShoppingFacade.SubmitCheckout(context, shoppingCartNew, UserMgr.ReadUserInfo().UserSysNo, HeaderHelper.GetClientType() == ClientType.IPhone ? SOSource.IPhone : SOSource.Android);

            if (result.ErrorMessages != null && result.ErrorMessages.Count > 0)
            {
                result.ErrorMessages.ForEach(item =>
                {
                    if (!string.IsNullOrWhiteSpace(item))
                    {
                        ajaxResult.Message += item;
                    }
                });
            }
            if (result.HasSucceed)
            {
                //取得订单编号列表
                List <int> soSysNoList = result.OrderProcessResult.ReturnData.SubOrderList.Select(subOrder => subOrder.Value.ID).ToList();
                ShoppingStorageManager.SaveLatestSO(soSysNoList);
                //团购订单数据不是来自cookie,不能清除cookie
                if (!result.OrderProcessResult.ReturnData.SubOrderList.Any(x => x.Value.SOType == (int)SOType.GroupBuy))
                {
                    //ShoppingStorageManager.RemoveShoppingCartCookie();
                    ShoppingCart leaveshoppingCart = ShoppingStorageManager.GetShoppingCartFromCreateNew();
                    leaveshoppingCart.ShoppingItemGroupList = shoppingCart.ShoppingItemGroupList.FindAll(m => !m.PackageChecked);
                    if (leaveshoppingCart.ShoppingItemGroupList.Count > 0)
                    {
                        foreach (var itemGroup in leaveshoppingCart.ShoppingItemGroupList)
                        {
                            if (itemGroup.PackageType.Equals(0))
                            {
                                foreach (ShoppingItem ProductItem in itemGroup.ShoppingItemList)
                                {
                                    itemGroup.PackageChecked   = true;
                                    ProductItem.ProductChecked = true;
                                }
                            }
                            if (itemGroup.PackageType.Equals(1))
                            {
                                itemGroup.PackageChecked = true;
                            }
                        }
                    }
                    LoginUser userInfo = UserMgr.ReadUserInfo();
                    leaveshoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;
                    HttpContext.Current.Request.Cookies.Remove(ShoppingStorageManager.GetConfigCartName());
                    ShoppingStorageManager.SaveShoppingCart(leaveshoppingCart);
                }

                ajaxResult.Code    = 0;
                ajaxResult.Success = true;
                ajaxResult.Data    = result.OrderProcessResult.ReturnData.ShoppingCartID;
                //var cookie = HttpContext.Current.Request.Cookies.Get(ShoppingStorageManager.GetConfigCartName());
                //ShoppingCart shoppingCart222 = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();
                return(ajaxResult);
            }


            return(ajaxResult);
        }
예제 #17
0
        public JsonResult AjaxSubmitCheckout(CheckOutContext context)
        {
            if (context == null)
            {
                return(Json(BuildAjaxErrorObject("无效的请求")));
            }

            ShoppingCart shoppingCart    = ShoppingStorageManager.GetShoppingCartFromCreateNew();
            ShoppingCart shoppingCartNew = ShoppingStorageManager.GetShoppingCartFromCreateNew();

            //优先从购买商品参数来构建购物车对象
            if (!String.IsNullOrWhiteSpace(context.ShoppingItemParam))
            {
                String[] shoppingItemParams = context.ShoppingItemParam.Split(new char[] { '|' });
                if (shoppingItemParams.Length == 2)
                {
                    shoppingCartNew = ShoppingStorageManager.GetShoppingCartFromParam(shoppingItemParams[0], shoppingItemParams[1]);
                }
            }
            //其次从cookie中来构建购物车对象
            if (ShoppingCartIsEmpty(shoppingCartNew))
            {
                shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();
                ShoppingItemGroup ShoppingItem = new ShoppingItemGroup();
                if (!string.IsNullOrEmpty(context.PackageTypeGroupList))
                {
                    string[] array = context.PackageTypeGroupList.Split(',');
                    foreach (var item in array)
                    {
                        int sysNo = 0;
                        if (int.TryParse(item, out sysNo))
                        {
                            ShoppingItem = shoppingCart.ShoppingItemGroupList.FindAll(m =>
                                                                                      (m.PackageType.Equals(1) && m.PackageNo.Equals(sysNo)))[0];
                            shoppingCartNew.ShoppingItemGroupList.Add(ShoppingItem);
                        }
                    }
                }

                if (!string.IsNullOrEmpty(context.PackageTypeSingleList))
                {
                    string[] array = context.PackageTypeSingleList.Split(',');
                    foreach (var item in array)
                    {
                        int sysNo = 0;
                        if (int.TryParse(item, out sysNo))
                        {
                            ShoppingItem = shoppingCart.ShoppingItemGroupList.FindAll(m =>
                                                                                      (m.PackageType.Equals(0) && m.ShoppingItemList[0].ProductSysNo.Equals(sysNo)))[0];
                            shoppingCartNew.ShoppingItemGroupList.Add(ShoppingItem);
                        }
                    }
                }
            }

            if (ShoppingCartIsEmpty(shoppingCartNew))
            {
                return(Json(new { url = PageHelper.BuildUrl("ShoppingCartRoute") }));
            }
            shoppingCartNew.OrderDeleteGiftSysNo = shoppingCart.OrderDeleteGiftSysNo;
            shoppingCartNew.OrderSelectGiftSysNo = shoppingCart.OrderSelectGiftSysNo;
            CheckOutResult result = ShoppingFacade.SubmitCheckout(context, shoppingCartNew, CurrUser.UserSysNo, SOSource.None);

            if (result.HasSucceed)
            {
                //取得订单编号列表
                List <int> soSysNoList = result.OrderProcessResult.ReturnData.SubOrderList.Select(subOrder => subOrder.Value.ID).ToList();
                ShoppingStorageManager.SaveLatestSO(soSysNoList);
                //团购订单数据不是来自cookie,不能清除cookie
                if (!result.OrderProcessResult.ReturnData.SubOrderList.Any(x => x.Value.SOType == (int)SOType.GroupBuy || x.Value.SOType == (int)SOType.VirualGroupBuy))
                {
                    //ShoppingStorageManager.RemoveShoppingCartCookie();
                    //移除mini购物车
                    //ShoppingStorageManager.RemoveShoppingCartMiniCookie();

                    //删除套餐
                    if (!string.IsNullOrEmpty(context.PackageTypeGroupList))
                    {
                        string[] array = context.PackageTypeGroupList.Split(',');
                        foreach (var item in array)
                        {
                            int sysNo = 0;
                            if (int.TryParse(item, out sysNo))
                            {
                                shoppingCart.ShoppingItemGroupList =
                                    shoppingCart.ShoppingItemGroupList.FindAll(m
                                                                               => (m.PackageType.Equals(1) && !m.PackageNo.Equals(sysNo)) ||
                                                                               m.PackageType.Equals(0));
                            }
                        }
                    }
                    //删除单个商品
                    if (!string.IsNullOrEmpty(context.PackageTypeSingleList))
                    {
                        string[] array = context.PackageTypeSingleList.Split(',');
                        foreach (var item in array)
                        {
                            int sysNo = 0;
                            if (int.TryParse(item, out sysNo))
                            {
                                shoppingCart.ShoppingItemGroupList =
                                    shoppingCart.ShoppingItemGroupList.FindAll(m
                                                                               => (m.PackageType.Equals(0) && !m.ShoppingItemList[0].ProductSysNo.Equals(sysNo)) ||
                                                                               m.PackageType.Equals(1));
                            }
                        }
                    }
                    //用于计算会员价:
                    LoginUser userInfo = UserMgr.ReadUserInfo();
                    shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo;
                    OrderPipelineProcessResult shoppingResult = ShoppingFacade.BuildShoppingCart(shoppingCart);
                    ShoppingCart pipelineShoppingCart         = (shoppingResult.ReturnData != null &&
                                                                 shoppingResult.ReturnData["ShoppingCart"] != null)
                        ? shoppingResult.ReturnData["ShoppingCart"] as ShoppingCart
                        : new ShoppingCart();
                    shoppingCart.OrderSelectGiftSysNo = pipelineShoppingCart.OrderSelectGiftSysNo;
                    shoppingCart.OrderDeleteGiftSysNo = pipelineShoppingCart.OrderDeleteGiftSysNo;
                    ShoppingStorageManager.SaveShoppingCart(shoppingCart);
                    //将迷你购物车加入Cookie
                    ShoppingStorageManager.SaveShoppingCartMini(ShoppingFacade.BuildMiniShoppingCartFromPipeline(shoppingResult));
                }

                return(Json(new { url = PageHelper.BuildUrl("Thankyou", result.OrderProcessResult.ReturnData.ShoppingCartID) }));
            }

            return(Json(new { errors = result.ErrorMessages }));
        }