public ActionResult BuyNow(string sku, int qty, int?aid, string teamcode, int pid = 0) { ProductSkuEntity entity = new ProductSkuEntity(); ViewBag.BuyQty = qty; ViewBag.Pid = pid; ViewBag.TeamCode = teamcode; if (aid.HasValue) { ViewBag.ChooseAddressId = aid.AsInt32(); } else { ViewBag.ChooseAddressId = 0; } if (string.IsNullOrWhiteSpace(sku)) { return(Redirect("/home/error")); } if (qty < 1) { return(Redirect("/home/error")); } try { entity = new ProductSkuEntity(); entity = productBll.GetProductBySku(sku, language); if (pid != 0) { var proList = itemBll.GetPromotionInfoByPid(pid); if (proList.Count() == 0 || proList.FirstOrDefault().Sku != sku) { return(Redirect("/product/FightIndex")); } } if (entity == null) { return(Redirect("/home/error")); } if (entity.Qty < qty) { return(Redirect("/home/error")); } if (entity.SalesTerritory != base.DeliveryRegion && entity.SalesTerritory != 3) { return(Redirect("/home/error")); } var ping = 0; int proid = 0; if (!string.IsNullOrEmpty(teamcode)) { var teaminfo = teamBll.GetTeamInfoByTeamCode(teamcode); ping = teaminfo.TeamStatus; proid = teaminfo.PromotionId; if (teaminfo.UserID == this.LoginUser.UserID || teaminfo.TeamStatus != 1) { return(Redirect("/Team/teamDetail?TeamCode=" + teamcode + "&Flag=1")); } } var cart = base.GetBuyVirtualCart(entity, ping, proid);//计算促销信息 var item = cart.Items.FirstOrDefault(); if (item == null) { return(Redirect("/home/error")); } entity.ProductPrice = item.SalePriceExchanged; var promotionsku = itemBll.GetPromotionInfoBySku(item.Sku); if (pid == 0 && (promotionsku.Count > 0 && promotionsku.FirstOrDefault().PromotionType == 2) && string.IsNullOrEmpty(teamcode)) { entity.ProductPrice = item.PriceExchanged; } ViewBag.IsShowHuoli = false; var HuoliEntity = accountBll.GetHuoliEntityByUerId(this.LoginUser.UserID); if (HuoliEntity == null) { ViewBag.IsShowHuoli = true; } else { if (HuoliEntity.HuoLiCurrent <= 0 || !string.IsNullOrEmpty(teamcode)) { ViewBag.IsShowHuoli = true; } } //========================优惠券=========================== //如果使用酒豆,则首先检查一下是否有默认可用的优惠券,如果有,则得减掉默认优惠券面值之后再*90%得到可用优惠券 int quanType = Convert.ToInt32(PromotionType.None); if (promotionsku.Count > 0) { if (promotionsku.FirstOrDefault().PromotionType == 1) { quanType = Convert.ToInt32(PromotionType.Promotion);//1.打折 2.拼团 对应的枚举--> 打折:0x02 拼团0x04 } else if (promotionsku.FirstOrDefault().PromotionType == 2) { if (pid != 0 || !string.IsNullOrEmpty(teamcode)) { quanType = Convert.ToInt32(PromotionType.GroupBuy); } } } //获取默认优惠券 decimal totleAmount = entity.ProductPrice * qty; var GiftCardNotUsedList = giftCardBll.GetCanUseGiftCardList(base.LoginUser.UserID, totleAmount, quanType); //转换成 ViewModel集合,并进行酒豆操作 List <CanUseGiftCardViewModel> vmlist = new List <CanUseGiftCardViewModel>(); //如果有酒豆 if (!ViewBag.IsShowHuoli) { if (GiftCardNotUsedList != null) { ViewBag.HuoliNoUseGiftCard = BuyOrderManager.GetCanUseHuoli(totleAmount, HuoliEntity.HuoLiCurrent, 0M); ViewBag.HuoliMoneyNoUseGiftCard = (BuyOrderManager.GetCanUseHuoli(totleAmount, HuoliEntity.HuoLiCurrent, 0M) / 100).ToNumberRoundStringWithPoint(); var GiftCardEntityDefault = GiftCardNotUsedList.FirstOrDefault(); decimal cardValue = 0M; if (GiftCardEntityDefault != null) { cardValue = GiftCardEntityDefault.CardSum; } foreach (var model in GiftCardNotUsedList) { var vm = giftCardBll.EntityToViewModel(model); vm.Huoli = BuyOrderManager.GetCanUseHuoli(totleAmount, HuoliEntity.HuoLiCurrent, model.CardSum); vm.Money = (BuyOrderManager.GetCanUseHuoli(totleAmount, HuoliEntity.HuoLiCurrent, model.CardSum) / 100).ToNumberRoundStringWithPoint(); vmlist.Add(vm); } decimal huoli = BuyOrderManager.GetCanUseHuoli(totleAmount, HuoliEntity.HuoLiCurrent, cardValue); ViewBag.Huoli = huoli; } else { ViewBag.Huoli = BuyOrderManager.GetCanUseHuoli(totleAmount, HuoliEntity.HuoLiCurrent, 0M); } } else//没有酒豆,直接返回可用的优惠券即可 { if (GiftCardNotUsedList != null) { foreach (var model in GiftCardNotUsedList) { var vm = giftCardBll.EntityToViewModel(model); vmlist.Add(vm); } } } ViewBag.GiftCardList = vmlist; //========================时令美食 获得限购数量 开始=========================== // 判断是否是节日食品 bool IsHolidayFoods = productBll.isHolidayGoods(entity.Spu); if (IsHolidayFoods) { // 根据sku获取时令美食spu信息 ProductExpandEntity HolidaySpuInfo = productBll.GetHolidaySpuInfoBySku(sku, language); if (HolidaySpuInfo == null) { return(Redirect("/home/error")); } // 时令美食 月饼 if (Convert.ToString(HolidaySpuInfo.CategoryId).Equals(System.Web.Configuration.WebConfigurationManager.AppSettings["MoonCakeKey"].ToString())) { if (HolidaySpuInfo.Weight <= 0) { return(Redirect("/home/error")); } // 只根据重量进行限量判断:1、不能超过两件 2、不能超过3Kg decimal MaxNum = holidayBll.GetCanBuyNumberByWeight(HolidaySpuInfo.Weight); ViewBag.HolidayMaxNum = MaxNum; } } //========================时令美食 获得限购数量 结束=========================== //entity.ProductPrice * base.ExchangeRate; //entity.MinPrice = entity.MinPrice * base.ExchangeRate; //entity.Price = entity.Price * base.ExchangeRate; } catch (Exception ex) { LogHelper.Error(ex); return(Redirect("/home/error")); } return(View(entity)); }