Example #1
0
        /// <summary>
        /// 选中全部购物车项
        /// </summary>
        /// <returns></returns>
        public ActionResult SelectAllCartItem()
        {
            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
                return AjaxResult("nologin", "请先登录");

            //购物车商品列表
            List<OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);
            //选中的订单商品列表
            List<OrderProductInfo> selectedOrderProductList = null;
            //购物车项列表
            List<CartItemInfo> cartItemList = Carts.TidyOrderProductList(orderProductList, out selectedOrderProductList);

            //商品总数量
            int totalCount = Carts.SumOrderProductCount(selectedOrderProductList);
            //商品合计
            decimal productAmount = Carts.SumOrderProductAmount(selectedOrderProductList);
            //满减折扣
            int fullCut = Carts.SumFullCut(cartItemList);
            //订单合计
            decimal orderAmount = productAmount - fullCut;

            CartModel model = new CartModel
            {
                TotalCount = totalCount,
                ProductAmount = productAmount,
                FullCut = fullCut,
                OrderAmount = orderAmount,
                CartItemList = cartItemList
            };

            return View("ajaxindex", model);
        }
Example #2
0
        /// <summary>
        /// 购物车
        /// </summary>
        public ActionResult Index()
        {
            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
                return Redirect(Url.Action("login", "account", new RouteValueDictionary { { "returnUrl", Url.Action("index") } }));

            //购物车商品列表
            List<OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);
            //商品数量
            int pCount = Carts.SumOrderProductCount(orderProductList);
            //选中的订单商品列表
            List<OrderProductInfo> selectedOrderProductList = null;
            //购物车项列表
            List<CartItemInfo> cartItemList = Carts.TidyOrderProductList(orderProductList, out selectedOrderProductList);

            //商品总数量
            int totalCount = Carts.SumOrderProductCount(selectedOrderProductList);
            //商品合计
            decimal productAmount = Carts.SumOrderProductAmount(selectedOrderProductList);
            //满减折扣
            int fullCut = Carts.SumFullCut(cartItemList);
            //订单合计
            decimal orderAmount = productAmount - fullCut;

            CartModel model = new CartModel
            {
                TotalCount = totalCount,
                ProductAmount = productAmount,
                FullCut = fullCut,
                OrderAmount = orderAmount,
                CartItemList = cartItemList
            };

            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(pCount);

            return View(model);
        }
Example #3
0
        /// <summary>
        /// 删除购物车中套装
        /// </summary>
        public ActionResult DelSuit()
        {
            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
                return AjaxResult("nologin", "请先登录");

            int pmId = WebHelper.GetQueryInt("pmId");//套装id
            string selectedCartItemKeyList = WebHelper.GetQueryString("selectedCartItemKeyList");//选中的购物车项键列表

            //购物车商品列表
            List<OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);
            Carts.DeleteCartSuit(ref orderProductList, pmId);

            //商品数量
            int pCount = Carts.SumOrderProductCount(orderProductList);
            //选中的订单商品列表
            List<OrderProductInfo> selectedOrderProductList = null;
            //购物车项列表
            List<CartItemInfo> cartItemList = Carts.TidyOrderProductList(StringHelper.SplitString(selectedCartItemKeyList), orderProductList, out selectedOrderProductList);

            //商品总数量
            int totalCount = Carts.SumOrderProductCount(selectedOrderProductList);
            //商品合计
            decimal productAmount = Carts.SumOrderProductAmount(selectedOrderProductList);
            //满减折扣
            int fullCut = Carts.SumFullCut(cartItemList);
            //订单合计
            decimal orderAmount = productAmount - fullCut;

            CartModel model = new CartModel
            {
                TotalCount = totalCount,
                ProductAmount = productAmount,
                FullCut = fullCut,
                OrderAmount = orderAmount,
                CartItemList = cartItemList
            };

            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(pCount);

            return View("ajaxindex", model);
        }
Example #4
0
        /// <summary>
        /// 修改购物车中套装数量
        /// </summary>
        public ActionResult ChangeSuitCount()
        {
            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
                return AjaxResult("nologin", "请先登录");

            int pmId = WebHelper.GetQueryInt("pmId");//套装id
            int buyCount = WebHelper.GetQueryInt("buyCount");//购买数量
            string selectedCartItemKeyList = WebHelper.GetQueryString("selectedCartItemKeyList");//选中的购物车项键列表

            //购物车商品列表
            List<OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);
            //套装商品列表
            List<OrderProductInfo> suitOrderProductList = Carts.GetSuitOrderProductList(pmId, orderProductList, true);
            if (suitOrderProductList.Count > 0)//当套装已经存在
            {
                if (buyCount < 1)//当购买数量小于1时,删除此套装
                {
                    Carts.DeleteCartSuit(ref orderProductList, pmId);
                }
                else
                {
                    OrderProductInfo orderProductInfo = suitOrderProductList.Find(x => x.Type == 3);
                    int oldBuyCount = orderProductInfo.RealCount / orderProductInfo.ExtCode2;
                    if (buyCount != oldBuyCount)
                        Carts.AddExistSuitToCart(ref orderProductList, suitOrderProductList, buyCount);
                }
            }

            //商品数量
            int pCount = Carts.SumOrderProductCount(orderProductList);
            //选中的订单商品列表
            List<OrderProductInfo> selectedOrderProductList = null;
            //购物车项列表
            List<CartItemInfo> cartItemList = Carts.TidyOrderProductList(StringHelper.SplitString(selectedCartItemKeyList), orderProductList, out selectedOrderProductList);

            //商品总数量
            int totalCount = Carts.SumOrderProductCount(selectedOrderProductList);
            //商品合计
            decimal productAmount = Carts.SumOrderProductAmount(selectedOrderProductList);
            //满减折扣
            int fullCut = Carts.SumFullCut(cartItemList);
            //订单合计
            decimal orderAmount = productAmount - fullCut;

            CartModel model = new CartModel
            {
                TotalCount = totalCount,
                ProductAmount = productAmount,
                FullCut = fullCut,
                OrderAmount = orderAmount,
                CartItemList = cartItemList
            };

            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(pCount);

            return View("ajaxindex", model);
        }
Example #5
0
        /// <summary>
        /// 修改购物车中商品数量
        /// </summary>
        public ActionResult ChangePruductCount()
        {
            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
                return AjaxResult("nologin", "请先登录");

            int pid = WebHelper.GetQueryInt("pid");//商品id
            int buyCount = WebHelper.GetQueryInt("buyCount");//购买数量
            string selectedCartItemKeyList = WebHelper.GetQueryString("selectedCartItemKeyList");//选中的购物车项键列表

            //购物车商品列表
            List<OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);
            //对应商品
            OrderProductInfo orderProductInfo = Carts.GetCommonOrderProductByPid(pid, orderProductList);
            if (orderProductInfo != null)//当商品已经存在
            {
                if (buyCount < 1)//当购买数量小于1时,删除此商品
                {
                    Carts.DeleteCartProduct(ref orderProductList, orderProductInfo);
                }
                else if (buyCount != orderProductInfo.BuyCount)
                {
                    Carts.AddExistProductToCart(ref orderProductList, buyCount, orderProductInfo, DateTime.Now);
                }
            }

            //商品数量
            int pCount = Carts.SumOrderProductCount(orderProductList);
            //选中的订单商品列表
            List<OrderProductInfo> selectedOrderProductList = null;
            //购物车项列表
            List<CartItemInfo> cartItemList = Carts.TidyOrderProductList(StringHelper.SplitString(selectedCartItemKeyList), orderProductList, out selectedOrderProductList);

            //商品数量
            int totalCount = Carts.SumOrderProductCount(selectedOrderProductList);
            //商品合计
            decimal productAmount = Carts.SumOrderProductAmount(selectedOrderProductList);
            //满减折扣
            int fullCut = Carts.SumFullCut(cartItemList);
            //订单合计
            decimal orderAmount = productAmount - fullCut;

            CartModel model = new CartModel
            {
                TotalCount = totalCount,
                ProductAmount = productAmount,
                FullCut = fullCut,
                OrderAmount = orderAmount,
                CartItemList = cartItemList
            };

            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(pCount);

            return View("ajaxindex", model);
        }
Example #6
0
        /// <summary>
        /// 添加满赠到购物车
        /// </summary>
        public ActionResult AddFullSend()
        {
            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
                return AjaxResult("nologin", "请先登录");

            int pmId = WebHelper.GetQueryInt("pmId");//满赠id
            int pid = WebHelper.GetQueryInt("pid");//商品id
            string selectedCartItemKeyList = WebHelper.GetQueryString("selectedCartItemKeyList");//选中的购物车项键列表

            //添加的商品
            PartProductInfo partProductInfo = Products.GetPartProductById(pid);
            if (partProductInfo == null)
                return AjaxResult("noproduct", "请选择商品");

            //商品库存
            int stockNumber = Products.GetProductStockNumberByPid(pid);
            if (stockNumber < 1)
                return AjaxResult("stockout", "商品库存不足");

            //满赠促销活动
            FullSendPromotionInfo fullSendPromotionInfo = Promotions.GetFullSendPromotionByPmIdAndTime(pmId, DateTime.Now);
            if (partProductInfo == null)
                return AjaxResult("nopromotion", "满赠促销活动不存在或已经结束");

            //购物车商品列表
            List<OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);

            //满赠主商品列表
            List<OrderProductInfo> fullSendMainOrderProductList = Carts.GetFullSendMainOrderProductList(pmId, orderProductList);
            if (fullSendMainOrderProductList.Count < 1)
                return AjaxResult("nolimit", "不符合活动条件");
            decimal amount = Carts.SumOrderProductAmount(fullSendMainOrderProductList);
            if (fullSendPromotionInfo.LimitMoney > amount)
                return AjaxResult("nolimit", "不符合活动条件");

            if (!Promotions.IsExistFullSendProduct(pmId, pid, 1))
                return AjaxResult("nofullsendproduct", "此商品不是满赠商品");

            //赠送商品
            OrderProductInfo fullSendMinorOrderProductInfo = Carts.GetFullSendMinorOrderProduct(pmId, orderProductList);
            if (fullSendMinorOrderProductInfo != null)
            {
                if (fullSendMinorOrderProductInfo.Pid != pid)
                    Carts.DeleteCartFullSend(ref orderProductList, fullSendMinorOrderProductInfo);
                else
                    return AjaxResult("exist", "此商品已经添加");
            }

            //添加满赠商品
            Carts.AddFullSendToCart(ref orderProductList, partProductInfo, fullSendPromotionInfo, WorkContext.Sid, WorkContext.Uid, DateTime.Now);

            //商品数量
            int pCount = Carts.SumOrderProductCount(orderProductList);
            //选中的订单商品列表
            List<OrderProductInfo> selectedOrderProductList = null;
            //购物车项列表
            List<CartItemInfo> cartItemList = Carts.TidyOrderProductList(StringHelper.SplitString(selectedCartItemKeyList), orderProductList, out selectedOrderProductList);

            //商品总数量
            int totalCount = Carts.SumOrderProductCount(selectedOrderProductList);
            //商品合计
            decimal productAmount = Carts.SumOrderProductAmount(selectedOrderProductList);
            //满减折扣
            int fullCut = Carts.SumFullCut(cartItemList);
            //订单合计
            decimal orderAmount = productAmount - fullCut;

            CartModel model = new CartModel
            {
                TotalCount = totalCount,
                ProductAmount = productAmount,
                FullCut = fullCut,
                OrderAmount = orderAmount,
                CartItemList = cartItemList
            };

            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(pCount);

            return View("ajaxindex", model);
        }