// GET: Web/ProductConsultation
        public ActionResult Index(long id = 0)
        {
            var productMark = _iCommentService.GetCommentsByProductId(id).Average(a => (decimal?)a.ReviewMark).GetValueOrDefault();

            ViewBag.productMark = productMark;
            var productinfo = _iProductService.GetProduct(id);
            List <FlashSalePrice> falseSalePrice = _iLimitTimeBuyService.GetPriceByProducrIds(new List <long> {
                id
            });

            if (falseSalePrice != null && falseSalePrice.Count == 1)
            {
                productinfo.MinSalePrice = falseSalePrice[0].MinPrice;
            }
            return(View(productinfo));
        }
        // GET: Web/ProductConsultation
        public ActionResult Index(long id = 0)
        {
            var productMark = CommentApplication.GetProductAverageMark(id);

            ViewBag.CommentCount = CommentApplication.GetCommentCountByProduct(id);
            ViewBag.productMark  = productMark;
            var productinfo = _iProductService.GetProduct(id);
            List <FlashSalePrice> falseSalePrice = _iLimitTimeBuyService.GetPriceByProducrIds(new List <long> {
                id
            });

            if (falseSalePrice != null && falseSalePrice.Count == 1)
            {
                productinfo.MinSalePrice = falseSalePrice[0].MinPrice;
            }
            ViewBag.Keyword = SiteSettings.Keyword;
            return(View(productinfo));
        }
 /// <summary>
 /// 取限时购价格
 /// </summary>
 /// <param name="ids"></param>
 /// <returns></returns>
 public static List <FlashSalePrice> GetPriceByProducrIds(List <long> ids)
 {
     return(_iLimitTimeBuyService.GetPriceByProducrIds(ids));
 }
예제 #4
0
        public JsonResult ProductList(int pageSize, int pageNo, string shopCategoryId, string shopId, string shopBranchId)
        {
            bool isOpenStore = SiteSettingApplication.GetSiteSettings() != null && SiteSettingApplication.GetSiteSettings().IsOpenStore;

            if (!isOpenStore)
            {
                throw new Core.HimallException("门店未授权!");
            }
            ShopBranchProductQuery query = new ShopBranchProductQuery();

            query.PageSize                = pageSize;
            query.PageNo                  = pageNo;
            query.ShopId                  = TypeHelper.ObjectToInt(shopId, 0);
            query.shopBranchId            = TypeHelper.ObjectToInt(shopBranchId, 0);
            query.ShopBranchProductStatus = ShopBranchSkuStatus.Normal;

            if (query.ShopId <= 0)
            {
                return(Json(new { Success = false, Message = "无法定位到商家!" }, JsonRequestBehavior.AllowGet));
            }

            if (TypeHelper.ObjectToInt(shopCategoryId, 0) > 0)
            {
                query.ShopCategoryId = TypeHelper.ObjectToInt(shopCategoryId);
            }

            if (query.shopBranchId <= 0)
            {
                return(Json(new { Success = false, Message = "无法定位到门店!" }, JsonRequestBehavior.AllowGet));
            }

            var pageModel = ShopBranchApplication.GetShopBranchProducts(query);

            if (pageModel.Models != null && pageModel.Models.Count > 0)
            {
                #region 处理商品 官方自营店会员折扣价,各活动价等。
                var flashSalePriceList      = _iLimitTimeBuyService.GetPriceByProducrIds(pageModel.Models.Select(p => p.Id).ToList());
                var fightGroupSalePriceList = FightGroupApplication.GetActiveByProductIds(pageModel.Models.Select(p => p.Id).ToArray());

                if (CurrentUser != null)
                {
                    var shopInfo = ShopApplication.GetShop(query.ShopId.Value);
                    if (shopInfo != null && shopInfo.IsSelf)//当前商家是否是官方自营店
                    {
                        decimal discount = 1M;
                        discount = CurrentUser.MemberDiscount;
                        foreach (var item in pageModel.Models)
                        {
                            item.MinSalePrice = Math.Round(item.MinSalePrice * discount, 2);
                        }
                    }
                }

                foreach (var item in pageModel.Models)
                {
                    var flashSale      = flashSalePriceList.Any(p => p.ProductId == item.Id);
                    var fightGroupSale = fightGroupSalePriceList.Any(p => p.ProductId == item.Id);

                    if (flashSale && !fightGroupSale)
                    {
                        item.MinSalePrice = TypeHelper.ObjectToDecimal(flashSalePriceList.FirstOrDefault(p => p.ProductId == item.Id).MinPrice.ToString("f2"));
                    }
                    else if (!flashSale && fightGroupSale)
                    {
                        item.MinSalePrice = TypeHelper.ObjectToDecimal(fightGroupSalePriceList.FirstOrDefault(p => p.ProductId == item.Id).MiniGroupPrice.ToString("f2"));
                    }
                }
                #endregion
            }
            var product = pageModel.Models.ToList().Select(item =>
            {
                return(new
                {
                    Id = item.Id,
                    ProductName = item.ProductName,
                    MeasureUnit = item.MeasureUnit,
                    MinSalePrice = item.MinSalePrice.ToString("f2"),
                    SaleCounts = item.SaleCounts,//销量统计没有考虑订单支付完成。
                    RelativePath = Core.HimallIO.GetRomoteProductSizeImage(item.RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_350),
                });
            });
            return(Json(new { Success = true, Models = product, Total = pageModel.Total }, JsonRequestBehavior.AllowGet));
        }