/// <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)); }
/// <summary> /// 生成商品的促销信息 /// </summary> /// <param name="singlePromotionInfo">单品促销活动</param> /// <param name="buySendPromotionList">买送促销活动列表</param> /// <param name="fullSendPromotionInfo">满赠促销活动</param> /// <param name="fullCutPromotionInfo">满减促销活动</param> /// <returns></returns> public static string GeneratePromotionMsg(SinglePromotionInfo singlePromotionInfo, List <BuySendPromotionInfo> buySendPromotionList, FullSendPromotionInfo fullSendPromotionInfo, FullCutPromotionInfo fullCutPromotionInfo) { StringBuilder promotionMsg = new StringBuilder(); //单品促销 if (singlePromotionInfo != null) { //折扣类别 switch (singlePromotionInfo.DiscountType) { case 0: //折扣 promotionMsg.AppendFormat("折扣:{0}折<br/>", singlePromotionInfo.DiscountValue); break; case 1: //直降 promotionMsg.AppendFormat("直降:{0}元<br/>", singlePromotionInfo.DiscountValue); break; case 2: //折后价 promotionMsg.AppendFormat("折后价:{0}元<br/>", singlePromotionInfo.DiscountValue); break; } //积分 if (singlePromotionInfo.PayCredits > 0) { promotionMsg.AppendFormat("赠送{0}:{1}<br/>", Credits.PayCreditName, singlePromotionInfo.PayCredits); } //优惠劵 if (singlePromotionInfo.CouponTypeId > 0) { CouponTypeInfo couponTypeInfo = Coupons.GetCouponTypeById(singlePromotionInfo.CouponTypeId); if (couponTypeInfo != null) { promotionMsg.AppendFormat("赠送优惠劵:{0}<br/>", couponTypeInfo.Name); } } } //买送促销 if (buySendPromotionList != null && buySendPromotionList.Count > 0) { promotionMsg.Append("买送促销:"); foreach (BuySendPromotionInfo buySendPromotionInfo in buySendPromotionList) { promotionMsg.AppendFormat("买{0}送{1},", buySendPromotionInfo.BuyCount, buySendPromotionInfo.SendCount); } promotionMsg.Remove(promotionMsg.Length - 1, 1); promotionMsg.Append("<br/>"); } //满赠促销 if (fullSendPromotionInfo != null) { promotionMsg.Append("满赠促销:"); promotionMsg.AppendFormat("满{0}元加{1}元<br/>", fullSendPromotionInfo.LimitMoney, fullSendPromotionInfo.AddMoney); } //满减促销 if (fullCutPromotionInfo != null) { promotionMsg.Append("满减促销:"); promotionMsg.AppendFormat("满{0}元减{1}元,", fullCutPromotionInfo.LimitMoney1, fullCutPromotionInfo.CutMoney1); if (fullCutPromotionInfo.LimitMoney2 > 0 && fullCutPromotionInfo.CutMoney2 > 0) { promotionMsg.AppendFormat("满{0}元减{1}元,", fullCutPromotionInfo.LimitMoney2, fullCutPromotionInfo.CutMoney2); } if (fullCutPromotionInfo.LimitMoney3 > 0 && fullCutPromotionInfo.CutMoney3 > 0) { promotionMsg.AppendFormat("满{0}元减{1}元,", fullCutPromotionInfo.LimitMoney3, fullCutPromotionInfo.CutMoney3); } promotionMsg.Remove(promotionMsg.Length - 1, 1); promotionMsg.Append("<br/>"); } return(promotionMsg.Length > 0 ? promotionMsg.Remove(promotionMsg.Length - 5, 5).ToString() : ""); }
/// <summary> /// 更新满赠促销活动 /// </summary> public static void UpdateFullSendPromotion(FullSendPromotionInfo fullSendPromotionInfo) { BrnMall.Data.Promotions.UpdateFullSendPromotion(fullSendPromotionInfo); }
/// <summary> /// 创建满赠促销活动 /// </summary> public static void CreateFullSendPromotion(FullSendPromotionInfo fullSendPromotionInfo) { BrnShop.Data.Promotions.CreateFullSendPromotion(fullSendPromotionInfo); }
/// <summary> /// 更新满赠促销活动 /// </summary> public static void UpdateFullSendPromotion(FullSendPromotionInfo fullSendPromotionInfo) { NStore.Data.Promotions.UpdateFullSendPromotion(fullSendPromotionInfo); }