/// <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)); }
/// <summary> /// 满赠主商品列表 /// </summary> /// <returns></returns> public ActionResult FullSendMainProductList() { //满赠促销活动id int pmId = GetRouteInt("pmId"); if (pmId == 0) { pmId = WebHelper.GetQueryInt("pmId"); } //开始价格 int startPrice = GetRouteInt("startPrice"); if (startPrice == 0) { startPrice = WebHelper.GetQueryInt("startPrice"); } //结束价格 int endPrice = GetRouteInt("endPrice"); if (endPrice == 0) { endPrice = WebHelper.GetQueryInt("endPrice"); } //排序列 int sortColumn = GetRouteInt("sortColumn"); if (sortColumn == 0) { sortColumn = WebHelper.GetQueryInt("sortColumn"); } //排序方向 int sortDirection = GetRouteInt("sortDirection"); if (sortDirection == 0) { sortDirection = WebHelper.GetQueryInt("sortDirection"); } //当前页数 int page = GetRouteInt("page"); if (page == 0) { page = WebHelper.GetQueryInt("page"); } //满赠促销活动 FullSendPromotionInfo fullSendPromotionInfo = Promotions.GetFullSendPromotionByPmIdAndTime(pmId, DateTime.Now); if (fullSendPromotionInfo == null) { return(PromptView(Url.Action("index"), "促销活动不存在")); } PageModel pageModel = new PageModel(20, page, Promotions.GetFullSendMainProductCount(pmId, startPrice, endPrice)); FullSendMainProductListModel model = new FullSendMainProductListModel() { PmId = pmId, StartPrice = startPrice, EndPrice = endPrice, SortColumn = sortColumn, SortDirection = sortDirection, PageModel = pageModel, ProductList = Promotions.GetFullSendMainProductList(pageModel.PageSize, pageModel.PageNumber, pmId, startPrice, endPrice, sortColumn, sortDirection), OrderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid) }; return(View(model)); }