public ActionResult SkuInfo(string productCode) { if (string.IsNullOrEmpty(productCode)) { return(HandleError("无法找到该商品")); } IList <ProductImage> images = null; //获取单品页商品 int userId = 0; if (base.LoginUser.UserID != null) { userId = base.LoginUser.UserID; } var itemskus = bll.GetItemByProductCode(productCode, base.language, ref images, userId); //二期:获取促销信息 var promotions = itemBll.GetPromotionEntities(itemskus.Select(n => n.Sku).ToArray()); //二期:获取品牌信息(获取3种语言版本) //组装DTO--pageload var product = itemskus.ToArray().AsDto(base.ExchangeRate, promotions, false); product.Images = images.ToArray(); return(PartialView("_skulist", product)); }
/// <summary> /// 获取当前购物车对象 /// </summary> /// <returns></returns> internal CartViewModel GetCart(bool?ischecked = null, decimal?exchangeRate = null, int?hasActivity = 0, int?giftCardId = 0) { var cartItemEntities = CartBll.GetCartItemEntities(base.LoginUser.UserID, base.language, base.DeliveryRegion); var cartGatewayItemEntities = CartBll.GetCartGatewayItemEntities(base.LoginUser.UserID); CartViewModel model = new CartViewModel(base.ExchangeRate); IList <PromotionEntity> promotions = null; if (cartItemEntities != null && cartItemEntities.Any()) { promotions = itemBll.GetPromotionEntities(cartItemEntities.Select(n => n.Sku).ToArray()).Where(d => d.PromotionType != 2).ToList(); } var items = cartItemEntities.AsProdcutItems(promotions, exchangeRate ?? base.ExchangeRate, cartGatewayItemEntities); //判断选中优惠券,走优惠券拆分逻辑 decimal cardValue = 0M; //if (giftCardId != 0) //{ // int quanType = Convert.ToInt32(PromotionType.None); //判断是否优惠券是否可用, 默认是0x01:原价商品 // if (promotions.Count > 0) // { // //PromotionType == 1 ? 2 : 4 ;//1.打折 2.拼团 对应的枚举--> 打折:0x02 拼团0x04 // int promotionType = Convert.ToInt32(PromotionType.Promotion), groupType = Convert.ToInt32(PromotionType.GroupBuy); // int i = 0; // //全部不是 原价商品 // if (items.Count() == promotions.Count()) // { // quanType = promotions[0].PromotionType== 1 ? promotionType : groupType; // i = 1; // } // for (; i < promotions.Count; i++) // { // quanType |= promotions[i].PromotionType == 1 ? promotionType : promotionType; // } // } // //获取选中的优惠券 // var productTotalAmount = items.Where(d => d.IsChecked == true).Sum(d => StringUtils.ToAmt(d.SalePrice * base.ExchangeRate) * d.CartQuantity); // var CanUseGiftCardList = giftCardBll.GetCanUseGiftCardList(base.LoginUser.UserID, productTotalAmount, quanType); // if (CanUseGiftCardList != null) // { // var GiftCardEntityChecked = CanUseGiftCardList.Where(x => x.ID == giftCardId).FirstOrDefault(); // if (GiftCardEntityChecked != null) // { // cardValue = (GiftCardEntityChecked as GiftCardEntity).CardSum; // //拆分优惠券 // foreach (var li in items.Where(d => d.IsChecked == true)) // { // if (items.Where(d => d.IsChecked == true).Last().Sku == li.Sku) // { // li.GiftCard = cardValue - items.Where(d => d.IsChecked == true).Sum(d => d.GiftCard); // } // else // { // li.GiftCard = Math.Round(cardValue * StringUtils.ToAmt(li.SalePrice * base.ExchangeRate) * li.CartQuantity / productTotalAmount, 2, MidpointRounding.AwayFromZero); // } // } // } // else //这种情况只有用户在前端篡改了优惠券ID之后才会出现 // { // LogHelper.ErrorMsg("找不到这个优惠券ID对应的数据,一般是用户前端篡改了ID数据!"); // } // } //} //判断选中酒豆,走酒豆拆分逻辑 //if (hasActivity == 1) //{ // var HuoliEntity = accountBll.GetHuoliEntityByUerId(base.LoginUser.UserID); // if (HuoliEntity != null && HuoliEntity.HuoLiCurrent >= 0) // { // var productTotalAmount = items.Where(d => d.IsChecked == true).Sum(d => StringUtils.ToAmt(d.SalePrice * base.ExchangeRate) * d.CartQuantity); // var huolitotal = BuyOrderManager.GetCanUseHuoli(productTotalAmount, HuoliEntity.HuoLiCurrent, cardValue); // //orderInfoEntity.Huoli = huolitotal; // foreach (var li in items.Where(d => d.IsChecked == true)) // { // if (items.Where(d => d.IsChecked == true).Last().Sku == li.Sku) // { // li.Huoli = huolitotal - items.Where(d => d.IsChecked == true).Sum(d => d.Huoli); // } // else // { // li.Huoli = Math.Round(huolitotal * StringUtils.ToAmt(li.SalePrice * base.ExchangeRate) * li.CartQuantity / productTotalAmount, 0, MidpointRounding.AwayFromZero); // } // } // } //} var productItems = items as ProductItem[] ?? items.ToArray(); if (ischecked == null) { //为购物车使用 model.HKOneWareHouseItems = productItems.Where(d => d.RealTaxType == 1).Where(n => n.IsOnSaled == true).ToArray(); model.HKSecWareHouseItems = productItems.Where(d => d.RealTaxType == 2).Where(n => n.IsOnSaled == true).ToArray(); model.Items = items; } else { model.HKOneWareHouseItems = productItems.Where(d => d.RealTaxType == 1).Where(n => n.IsOnSaled == true).ToArray(); model.HKSecWareHouseItems = productItems.Where(d => d.RealTaxType == 2).Where(n => n.IsOnSaled == true).ToArray(); //为结算使用 model.Items = productItems.Where(n => n.IsOnSaled == true && n.IsChecked == ischecked).ToArray(); } model.InvalidItems = productItems.Where(n => n.IsOnSaled == false).ToArray(); model.HKOneWareHouseInvalidItems = items.Where(d => d.RealTaxType == 1).Where(n => n.IsOnSaled == false).ToArray(); model.HKSecWareHouseInvalidItems = items.Where(d => d.RealTaxType == 2).Where(n => n.IsOnSaled == false).ToArray(); return(model); }
public ActionResult Item(string productCode, string selectedSku = "") { try { int userid = LoginUser == null ? 0 : LoginUser.UserID; var item = bll.ItemViewSupporterFromAutoCache(productCode, userid, base.language, selectedSku, base.ExchangeRate); if (item != null && item.ProductSkuEntity != null && item.ProductSkuEntity.Count() > 0) { bool isflag = false; if (base.LoginUser != null) { isflag = bll.getFivoriteDetail(productCode, base.LoginUser.UserID); } var promotions = itemBll.GetPromotionEntities(item.ProductSkuEntity.Select(n => n.Sku).ToArray()); var flag = false; if (promotions.Where(d => d.PromotionType == 2).Count() > 0) { flag = true; } //促销商品,过滤掉拼团(PromotionType=2)商品,留下打折商品PromotionType=1 promotions = promotions.Where(d => d.PromotionType != 2).ToList(); //组装DTO--pageload var product = item.ProductSkuEntity.ToArray().AsDto(base.ExchangeRate, promotions, isflag); if (flag) { product.isTrue = 1; } var skuAttributeViewModel = item.ProductSkuEntity.AsSkuAttributeViewModelD(base.ExchangeRate, promotions, selectedSku, dto: item); //组装skuAttributeViewModel-- for js skuSelected ViewBag.SkuMetaViewModel = skuAttributeViewModel; bool skuFlag = item.ProductSkuEntity.GroupBy(d => d.Sku).Count() > 1; //当SKU只有1条时候,默认要被选中,要把所有的FLAG重置1 if (!skuFlag) { foreach (var skuAttribute in skuAttributeViewModel.MainAttributes) { skuAttribute.Flag = 1; foreach (var subSkuAttribute in skuAttribute.SubAttributes) { subSkuAttribute.Flag = 1; } } foreach (var subSkuAttribute in skuAttributeViewModel.SubAttributes) { subSkuAttribute.Flag = 1; } ViewBag.SkuMetaViewModel = skuAttributeViewModel; } return(PartialView("_Item", item)); } else { return(PartialView("_Item", new ItemViewSupporter())); } } catch (Exception ex) { return(HandleError(ex)); } }
public ActionResult Item(string productCode, string selectedSku = "") { try { IList <ProductImage> images = null; //获取单品页商品 int userId = 0; if (base.LoginUser != null) { userId = base.LoginUser.UserID; } var itemskus = productBll.GetItemByProductCode(productCode, base.language, ref images, userId); if (itemskus.Count() > 0) { var item = itemskus.FirstOrDefault(); string spu = item.Spu; //获取收藏表的信息 bool isflag = false; if (base.LoginUser != null) { isflag = productBll.getFivoriteDetail(spu, base.LoginUser.UserID); } //获取促销信息 var promotions = itemBll.GetPromotionEntities(itemskus.Select(n => n.Sku).ToArray()); //判断这个spu是不是在做拼生活活动(用于前端是否显示拼生活图标链接) var flag = false; if (promotions.Where(d => d.PromotionType == 2).Count() > 0) { flag = true; } //促销商品,过滤掉拼团(PromotionType=2)商品,留下打折商品PromotionType=1 promotions = promotions.Where(d => d.PromotionType != 2).ToList(); //组装DTO--pageload var product = itemskus.ToArray().AsDto(base.ExchangeRate, promotions, isflag); // 查询 拼生活里面 是否有这个spu if (flag) { product.isTrue = 1; } product.Images = images.ToArray(); //组装skuAttributeViewModel-- for js skuSelected var skuAttributeViewModel = itemskus.AsSkuAttributeViewModel(base.ExchangeRate, promotions, selectedSku, dto: product); bool skuFlag = itemskus.GroupBy(d => d.Sku).Count() > 1; //当SKU只有1条时候,默认要被选中,要把所有的FLAG重置1 if (!skuFlag) { foreach (var skuAttribute in skuAttributeViewModel.MainAttributes) { skuAttribute.Flag = 1; foreach (var subSkuAttribute in skuAttribute.SubAttributes) { subSkuAttribute.Flag = 1; } } foreach (var subSkuAttribute in skuAttributeViewModel.SubAttributes) { subSkuAttribute.Flag = 1; } } //装配节日时令产品的:展示属性(净重、规格、口味)以及(毛重Weight用于判断能卖几件商品)=>e.g月饼清关规定:不能超过3Kg,不能超过两件,不能超过800元 HolidayProductAttributeViewModel holidayProductAttrVM = new HolidayProductAttributeViewModel(); var productExpand = productBll.GetProductExpandEntity(spu, base.language); if (productExpand != null) { holidayProductAttrVM.Weight = productExpand.Weight; holidayProductAttrVM.Flavor = productExpand.Flavor; holidayProductAttrVM.Specifications = item.Specifications; holidayProductAttrVM.NetWeight = item.NetWeight; } //装配ViewBag ViewBag.HolidayAttributeViewModel = holidayProductAttrVM; ViewBag.SkuMetaViewModel = skuAttributeViewModel; ViewBag.CanBuyNum = holidayBll.GetCanBuyNumberByWeight(holidayProductAttrVM.Weight); return(PartialView("_Item", product)); } else { return(PartialView("_Item", new ProductDto())); } } catch (Exception ex) { return(HandleError(ex)); } }
/// <summary> /// 收藏列表页 /// </summary> /// <param name="c"></param> /// <param name="level"></param> /// <param name="page"></param> /// <param name="sort"></param> /// <param name="attrids"></param> /// <returns></returns> private FavoriteViewModel GetFavoriteList(int PageIndex, decimal ExchangeRate) { FavoriteViewModel viewmodel = new FavoriteViewModel(); try { int totalRecords = 0, pagecount = 0; //得到收藏的列表 var products = productBll.GetFavoriteList(PageIndex, PageSize, base.language, base.ExchangeRate, base.LoginUser.UserID); foreach (var spuList in products) { IList <ProductImage> images = null; // 获取单品页商品 var itemskus = bll.GetItemByProductCodeAndStatus(spuList.spu, base.language, ref images); string spu = itemskus.FirstOrDefault().Spu; //二期:获取促销信息 var promotions = itemBll.GetPromotionEntities(itemskus.Select(n => n.Sku).ToArray()); promotions = promotions.Where(d => d.PromotionType != 2).ToList(); //组装DTO--pageload var product = itemskus.ToArray().AsDto(base.ExchangeRate, promotions, false); if (product.Promotion != null) { if (spuList.originalPrice > Convert.ToDecimal(product.PromotionDiscountPrice.ToNumberRoundStringWithPoint(2))) { spuList.isDiscount = 1; spuList.DiscountPrice = spuList.originalPrice - product.PromotionDiscountPrice; spuList.originalPrice = product.PromotionDiscountPrice; } } else if (spuList.originalPrice > Convert.ToDecimal(product.MinPrice.ToNumberRoundStringWithPoint(2))) { spuList.isDiscount = 1; spuList.DiscountPrice = spuList.originalPrice - product.MinPrice; spuList.originalPrice = product.MinPrice; } else if (spuList.originalPrice < Convert.ToDecimal(product.MinPrice.ToNumberRoundStringWithPoint(2))) { spuList.originalPrice = product.MinPrice; } } if (products != null) { totalRecords = products.FirstOrDefault().TotalRecord; } else { totalRecords = 0; products = new List <Favorite>(); } viewmodel.Products = products; viewmodel.PageSize = PageSize; viewmodel.TotalRecord = totalRecords; pagecount = totalRecords / PageSize; if (totalRecords % PageSize > 0) { pagecount += 1; } viewmodel.PageCount = pagecount; viewmodel.PageIndex = PageIndex; } catch (Exception ex) { LogHelper.Error(ex); } return(viewmodel); }