Exemplo n.º 1
0
        /// <summary>
        /// 套装
        /// </summary>
        public ActionResult Suit()
        {
            //套装id
            int pmId = GetRouteInt("pmId");

            if (pmId == 0)
            {
                pmId = WebHelper.GetQueryInt("pmId");
            }

            //判断套装是否存在或过期
            SuitPromotionInfo suitPromotionInfo = Promotions.GetSuitPromotionByPmIdAndTime(pmId, DateTime.Now);

            if (suitPromotionInfo == null)
            {
                return(PromptView("/", "你访问的套装不存在或过期"));
            }

            //扩展套装商品列表
            List <ExtSuitProductInfo> extSuitProductList = Promotions.GetExtSuitProductList(pmId);

            SuitModel model = new SuitModel();

            model.SuitPromotionInfo = suitPromotionInfo;
            model.SuitProductList   = extSuitProductList;

            foreach (ExtSuitProductInfo extSuitProductInfo in extSuitProductList)
            {
                model.SuitDiscount  += extSuitProductInfo.Number * extSuitProductInfo.Discount;
                model.ProductAmount += extSuitProductInfo.Number * extSuitProductInfo.ShopPrice;
            }
            model.SuitAmount = model.ProductAmount - model.SuitDiscount;

            return(View(model));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 套装
        /// </summary>
        public ActionResult Suit()
        {
            //套装id
            int pmId = GetRouteInt("pmId");

            if (pmId == 0)
            {
                pmId = WebHelper.GetQueryInt("pmId");
            }

            //判断套装是否存在或过期
            SuitPromotionInfo suitPromotionInfo = Promotions.GetSuitPromotionByPmIdAndTime(pmId, DateTime.Now);

            if (suitPromotionInfo == null)
            {
                return(PromptView("/", "你访问的套装不存在或过期"));
            }

            //店铺信息
            StoreInfo storeInfo = Stores.GetStoreById(suitPromotionInfo.StoreId);

            if (storeInfo.State != (int)StoreState.Open)
            {
                return(PromptView("/", "你访问的套装不存在"));
            }

            //扩展套装商品列表
            List <ExtSuitProductInfo> extSuitProductList = Promotions.GetExtSuitProductList(pmId);

            SuitModel model = new SuitModel();

            model.SuitPromotionInfo = suitPromotionInfo;
            model.SuitProductList   = extSuitProductList;
            model.StoreInfo         = storeInfo;
            model.StoreKeeperInfo   = Stores.GetStoreKeeperById(storeInfo.StoreId);
            model.StoreRegion       = Regions.GetRegionById(storeInfo.RegionId);
            model.StoreRankInfo     = StoreRanks.GetStoreRankById(storeInfo.StoreRid);

            foreach (ExtSuitProductInfo extSuitProductInfo in extSuitProductList)
            {
                model.SuitDiscount  += extSuitProductInfo.Number * extSuitProductInfo.Discount;
                model.ProductAmount += extSuitProductInfo.Number * extSuitProductInfo.ShopPrice;
            }
            model.SuitAmount = model.ProductAmount - Convert.ToDecimal(model.SuitDiscount);

            return(View(model));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 直接购买套装
        /// </summary>
        /// <returns></returns>
        public ActionResult DirectBuySuit()
        {
            int pmId     = WebHelper.GetQueryInt("pmId");     //套装id
            int buyCount = WebHelper.GetQueryInt("buyCount"); //购买数量

            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
            {
                return(AjaxResult("nologin", "请先登录"));
            }

            //购买数量不能小于1
            if (buyCount < 1)
            {
                return(AjaxResult("buycountmin", "请填写购买数量"));
            }

            //获得套装促销活动
            SuitPromotionInfo suitPromotionInfo = Promotions.GetSuitPromotionByPmIdAndTime(pmId, DateTime.Now);

            //套装促销活动不存在时
            if (suitPromotionInfo == null)
            {
                return(AjaxResult("nosuit", "请选择套装"));
            }

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

            if (suitOrderProductList.Count == 0)
            {
                if ((WorkContext.Uid > 0 && orderProductList.Count >= WorkContext.ShopConfig.MemberSCCount) || (WorkContext.Uid < 1 && orderProductList.Count >= WorkContext.ShopConfig.GuestSCCount))
                {
                    return(AjaxResult("full", "购物车已满"));
                }
            }

            //扩展套装商品列表
            List <ExtSuitProductInfo> extSuitProductList = Promotions.GetExtSuitProductList(suitPromotionInfo.PmId);

            if (extSuitProductList.Count < 1)
            {
                return(AjaxResult("noproduct", "套装中没有商品"));
            }

            //套装商品id列表
            StringBuilder pidList = new StringBuilder();

            foreach (ExtSuitProductInfo extSuitProductInfo in extSuitProductList)
            {
                pidList.AppendFormat("{0},", extSuitProductInfo.Pid);
            }
            pidList.Remove(pidList.Length - 1, 1);

            //套装商品库存列表
            List <ProductStockInfo> productStockList = Products.GetProductStockList(pidList.ToString());

            foreach (ProductStockInfo item in productStockList)
            {
                if (item.Number < buyCount)
                {
                    return(AjaxResult("stockout", item.Pid.ToString()));
                }
            }

            buyCount = suitOrderProductList.Count == 0 ? buyCount : suitOrderProductList[0].BuyCount / suitOrderProductList[0].ExtCode3 + buyCount;
            Carts.AddSuitToCart(ref orderProductList, extSuitProductList, suitPromotionInfo, buyCount, WorkContext.Sid, WorkContext.Uid, DateTime.Now);
            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(Carts.SumOrderProductCount(orderProductList));

            return(AjaxResult("success", Url.Action("confirmorder", "order", new RouteValueDictionary {
                { "selectedCartItemKeyList", "1_" + pmId }
            })));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 添加套装到购物车
        /// </summary>
        public ActionResult AddSuit()
        {
            int pmId         = WebHelper.GetQueryInt("pmId");       //套装id
            int buyCount     = WebHelper.GetQueryInt("buyCount");   //购买数量
            int scSubmitType = WorkContext.ShopConfig.SCSubmitType; //购物车的提交方式

            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
            {
                switch (scSubmitType)
                {
                case 0:
                    return(Redirect(Url.Action("login", "account", new RouteValueDictionary {
                        { "returnUrl", Url.Action("suit", "catalog", new RouteValueDictionary {
                                { "pmId", pmId }
                            }) }
                    })));

                case 1:
                    return(Redirect(Url.Action("login", "account", new RouteValueDictionary {
                        { "returnUrl", Url.Action("suit", "catalog", new RouteValueDictionary {
                                { "pmId", pmId }
                            }) }
                    })));

                case 2:
                    return(AjaxResult("nologin", "请先登录"));

                default:
                    return(Redirect(Url.Action("login", "account", new RouteValueDictionary {
                        { "returnUrl", Url.Action("suit", "catalog", new RouteValueDictionary {
                                { "pmId", pmId }
                            }) }
                    })));
                }
            }

            //购买数量不能小于1
            if (buyCount < 1)
            {
                switch (scSubmitType)
                {
                case 0:
                    return(PromptView(Url.Action("suit", "catalog", new RouteValueDictionary {
                        { "pmId", pmId }
                    }), "购买数量不能小于1"));

                case 1:
                    return(PromptView(Url.Action("suit", "catalog", new RouteValueDictionary {
                        { "pmId", pmId }
                    }), "购买数量不能小于1"));

                case 2:
                    return(AjaxResult("buycountmin", "请填写购买数量"));

                default:
                    return(PromptView(Url.Action("suit", "catalog", new RouteValueDictionary {
                        { "pmId", pmId }
                    }), "购买数量不能小于1"));
                }
            }

            //获得套装促销活动
            SuitPromotionInfo suitPromotionInfo = Promotions.GetSuitPromotionByPmIdAndTime(pmId, DateTime.Now);

            //套装促销活动不存在时
            if (suitPromotionInfo == null)
            {
                switch (scSubmitType)
                {
                case 0:
                    return(PromptView("/", "套装不存在"));

                case 1:
                    return(PromptView("/", "套装不存在"));

                case 2:
                    return(AjaxResult("nosuit", "请选择套装"));

                default:
                    return(PromptView("/", "套装不存在"));
                }
            }

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

            if (suitOrderProductList.Count == 0)
            {
                if ((WorkContext.Uid > 0 && orderProductList.Count >= WorkContext.ShopConfig.MemberSCCount) || (WorkContext.Uid < 1 && orderProductList.Count >= WorkContext.ShopConfig.GuestSCCount))
                {
                    switch (scSubmitType)
                    {
                    case 2:
                        return(AjaxResult("full", "购物车已满"));

                    default:
                        return(PromptView(Url.Action("index", "cart"), "购物车已满,请先结账"));
                    }
                }
            }

            //扩展套装商品列表
            List <ExtSuitProductInfo> extSuitProductList = Promotions.GetExtSuitProductList(suitPromotionInfo.PmId);

            if (extSuitProductList.Count < 1)
            {
                switch (scSubmitType)
                {
                case 0:
                    return(PromptView(Url.Action("suit", "catalog", new RouteValueDictionary {
                        { "pmId", pmId }
                    }), "套装商品为空"));

                case 1:
                    return(PromptView(Url.Action("suit", "catalog", new RouteValueDictionary {
                        { "pmId", pmId }
                    }), "套装商品为空"));

                case 2:
                    return(AjaxResult("noproduct", "套装中没有商品"));

                default:
                    return(PromptView(Url.Action("suit", "catalog", new RouteValueDictionary {
                        { "pmId", pmId }
                    }), "套装商品为空"));
                }
            }

            //套装商品id列表
            StringBuilder pidList = new StringBuilder();

            foreach (ExtSuitProductInfo extSuitProductInfo in extSuitProductList)
            {
                pidList.AppendFormat("{0},", extSuitProductInfo.Pid);
            }
            pidList.Remove(pidList.Length - 1, 1);

            //套装商品库存列表
            List <ProductStockInfo> productStockList = Products.GetProductStockList(pidList.ToString());

            foreach (ProductStockInfo item in productStockList)
            {
                if (item.Number < buyCount)
                {
                    switch (scSubmitType)
                    {
                    case 0:
                        return(PromptView(Url.Action("suit", "catalog", new RouteValueDictionary {
                            { "pmId", pmId }
                        }), "库存不足"));

                    case 1:
                        return(PromptView(Url.Action("suit", "catalog", new RouteValueDictionary {
                            { "pmId", pmId }
                        }), "库存不足"));

                    case 2:
                        return(AjaxResult("stockout", item.Pid.ToString()));

                    default:
                        return(PromptView(Url.Action("suit", "catalog", new RouteValueDictionary {
                            { "pmId", pmId }
                        }), "库存不足"));
                    }
                }
            }

            buyCount = suitOrderProductList.Count == 0 ? buyCount : suitOrderProductList[0].BuyCount / suitOrderProductList[0].ExtCode2 + buyCount;
            Carts.AddSuitToCart(ref orderProductList, extSuitProductList, suitPromotionInfo, buyCount, WorkContext.Sid, WorkContext.Uid, DateTime.Now);
            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(Carts.SumOrderProductCount(orderProductList));

            switch (scSubmitType)
            {
            case 0:
                return(RedirectToAction("addsuccess", new RouteValueDictionary {
                    { "type", 1 }, { "id", pmId }
                }));

            case 1:
                return(RedirectToAction("index"));

            case 2:
                return(AjaxResult("success", "添加成功"));

            default:
                return(RedirectToAction("addsuccess", new RouteValueDictionary {
                    { "type", 1 }, { "id", pmId }
                }));
            }
        }