コード例 #1
0
        public ActionResult ProductDetail(string id = "")
        {
            CheckPromoter();

            var    shopService = ServiceHelper.Create <IVShopService>();
            string price       = "";

            ProductDetailModel detailModel           = new ProductDetailModel();
            DistributionProductDetailShowModel model = new DistributionProductDetailShowModel()
            {
                Product = new Model.ProductInfo(),
                Shop    = new ShopInfoModel(),
                Color   = new CollectionSKU(),
                Size    = new CollectionSKU(),
                Version = new CollectionSKU()
            };

            ProductInfo          product   = null;
            ProductBrokerageInfo probroker = null;
            ShopInfo             shop      = null;
            long gid = 0;

            #region 商品Id不合法
            if (long.TryParse(id, out gid))
            {
            }
            if (gid == 0)
            {
                //跳转到出错页面
                return(RedirectToAction("Error404", "Error", new { area = "Web" }));
            }
            #endregion



            #region 初始化商品和店铺
            probroker = _iDistributionService.GetDistributionProductInfo(gid);
            product   = _iProductService.GetProduct(gid);

            if (probroker == null)
            {
                return(RedirectToAction("Error404", "Error", new { area = "Web" }));
            }

            if (product == null)
            {
                //跳转到404页面
                return(RedirectToAction("Error404", "Error", new { area = "Web" }));
            }
            model.ProductDescription = product.ProductDescriptionInfo.ShowMobileDescription;

            model.DistributionAgentNum       = probroker.AgentNum.Value;
            model.DistributionSaleNum        = probroker.SaleNum.Value;
            model.DistributionCommission     = 0;
            model.ShopDistributionProductNum = _iDistributionService.GetShopDistributionProductCount(product.ShopId);
            decimal rate = probroker.rate;
            if (rate > 0)
            {
                model.DistributionCommission = (product.MinSalePrice * rate / 100);
                int _tmp = (int)(model.DistributionCommission * 100);
                //保留两位小数,但不四舍五入
                model.DistributionCommission = (decimal)(((decimal)_tmp) / (decimal)100);
            }

            //是否已代理
            List <long> proids = new List <long>();
            proids.Add(gid);
            List <long> canAgentIds = _iDistributionService.GetCanAgentProductId(proids, curUserId).ToList();
            model.DistributionIsAgent = true;
            if (canAgentIds.Count > 0)
            {
                model.DistributionIsAgent = false;
            }

            shop = ServiceHelper.Create <IShopService>().GetShop(product.ShopId);
            var mark = ShopServiceMark.GetShopComprehensiveMark(shop.Id);
            model.Shop.PackMark          = mark.PackMark;
            model.Shop.ServiceMark       = mark.ServiceMark;
            model.Shop.ComprehensiveMark = mark.ComprehensiveMark;
            var comm = ServiceHelper.Create <ICommentService>().GetCommentsByProductId(gid);
            model.Shop.Name        = shop.ShopName;
            model.Shop.ProductMark = (comm == null || comm.Count() == 0) ? 0 : comm.Average(p => (decimal)p.ReviewMark);
            model.Shop.Id          = product.ShopId;
            model.Shop.FreeFreight = shop.FreeFreight;
            detailModel.ProductNum = ServiceHelper.Create <IProductService>().GetShopOnsaleProducts(product.ShopId);
            bool isFavorite;
            if (CurrentUser == null)
            {
                isFavorite = false;
            }
            else
            {
                isFavorite = ServiceHelper.Create <IProductService>().IsFavorite(product.Id, CurrentUser.Id);
            }
            detailModel.IsFavorite = isFavorite;
            #endregion

            #region 商品规格

            ProductTypeInfo typeInfo     = _iTypeService.GetType(product.TypeId);
            string          colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
            string          sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
            string          versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
            model.ColorAlias   = colorAlias;
            model.SizeAlias    = sizeAlias;
            model.VersionAlias = versionAlias;

            if (product.SKUInfo != null && product.SKUInfo.Count() > 0)
            {
                long colorId = 0, sizeId = 0, versionId = 0;
                foreach (var sku in product.SKUInfo)
                {
                    var specs = sku.Id.Split('_');
                    if (specs.Count() > 0)
                    {
                        if (long.TryParse(specs[1], out colorId))
                        {
                        }
                        if (colorId != 0)
                        {
                            if (!model.Color.Any(v => v.Value.Equals(sku.Color)))
                            {
                                var c = product.SKUInfo.Where(s => s.Color.Equals(sku.Color)).Sum(s => s.Stock);
                                model.Color.Add(new ProductSKU
                                {
                                    //Name = "选择颜色",
                                    Name         = "选择" + colorAlias,
                                    EnabledClass = c != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Color.Any(c1 => c1.SelectedClass.Equals("selected")) && c != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = colorId,
                                    Value         = sku.Color,
                                    Img           = sku.ShowPic
                                });
                            }
                        }
                    }
                    if (specs.Count() > 1)
                    {
                        if (long.TryParse(specs[2], out sizeId))
                        {
                        }
                        if (sizeId != 0)
                        {
                            if (!model.Size.Any(v => v.Value.Equals(sku.Size)))
                            {
                                var ss = product.SKUInfo.Where(s => s.Size.Equals(sku.Size)).Sum(s1 => s1.Stock);
                                model.Size.Add(new ProductSKU
                                {
                                    //Name = "选择尺码",
                                    Name         = "选择" + sizeAlias,
                                    EnabledClass = ss != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Size.Any(s1 => s1.SelectedClass.Equals("selected")) && ss != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = sizeId,
                                    Value         = sku.Size
                                });
                            }
                        }
                    }

                    if (specs.Count() > 2)
                    {
                        if (long.TryParse(specs[3], out versionId))
                        {
                        }
                        if (versionId != 0)
                        {
                            if (!model.Version.Any(v => v.Value.Equals(sku.Version)))
                            {
                                var v = product.SKUInfo.Where(s => s.Version.Equals(sku.Version)).Sum(s => s.Stock);
                                model.Version.Add(new ProductSKU
                                {
                                    //Name = "选择版本",
                                    Name         = "选择" + versionAlias,
                                    EnabledClass = v != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Version.Any(v1 => v1.SelectedClass.Equals("selected")) && v != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = versionId,
                                    Value         = sku.Version
                                });
                            }
                        }
                    }
                }
                decimal min = 0, max = 0;
                min = product.SKUInfo.Where(s => s.Stock >= 0).Min(s => s.SalePrice);
                max = product.SKUInfo.Where(s => s.Stock >= 0).Max(s => s.SalePrice);
                if (min == 0 && max == 0)
                {
                    price = product.MinSalePrice.ToString("f2");
                }
                else if (max > min)
                {
                    price = string.Format("{0}-{1}", min.ToString("f2"), max.ToString("f2"));
                }
                else
                {
                    price = string.Format("{0}", min.ToString("f2"));
                }
            }
            ViewBag.Price = string.IsNullOrWhiteSpace(price) ? product.MinSalePrice.ToString("f2") : price;
            #endregion

            #region 获取店铺的评价统计
            var shopStatisticOrderComments = ServiceHelper.Create <IShopService>().GetShopStatisticOrderComments(product.ShopId);

            var productAndDescription = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescription).FirstOrDefault();
            var sellerServiceAttitude = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitude).FirstOrDefault();
            var sellerDeliverySpeed   = shopStatisticOrderComments.Where(c => c.CommentKey ==
                                                                         StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeed).FirstOrDefault();

            var productAndDescriptionPeer = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionPeer).FirstOrDefault();
            var sellerServiceAttitudePeer = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudePeer).FirstOrDefault();
            var sellerDeliverySpeedPeer   = shopStatisticOrderComments.Where(c => c.CommentKey ==
                                                                             StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedPeer).FirstOrDefault();

            var productAndDescriptionMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionMax).FirstOrDefault();
            var productAndDescriptionMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionMin).FirstOrDefault();

            var sellerServiceAttitudeMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudeMax).FirstOrDefault();
            var sellerServiceAttitudeMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudeMin).FirstOrDefault();

            var sellerDeliverySpeedMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedMax).FirstOrDefault();
            var sellerDeliverySpeedMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedMin).FirstOrDefault();

            decimal defaultValue = 5;
            //宝贝与描述
            if (productAndDescription != null && productAndDescriptionPeer != null)
            {
                detailModel.ProductAndDescription     = productAndDescription.CommentValue;
                detailModel.ProductAndDescriptionPeer = productAndDescriptionPeer.CommentValue;
                detailModel.ProductAndDescriptionMin  = productAndDescriptionMin.CommentValue;
                detailModel.ProductAndDescriptionMax  = productAndDescriptionMax.CommentValue;
            }
            else
            {
                detailModel.ProductAndDescription     = defaultValue;
                detailModel.ProductAndDescriptionPeer = defaultValue;
                detailModel.ProductAndDescriptionMin  = defaultValue;
                detailModel.ProductAndDescriptionMax  = defaultValue;
            }
            //卖家服务态度
            if (sellerServiceAttitude != null && sellerServiceAttitudePeer != null)
            {
                detailModel.SellerServiceAttitude     = sellerServiceAttitude.CommentValue;
                detailModel.SellerServiceAttitudePeer = sellerServiceAttitudePeer.CommentValue;
                detailModel.SellerServiceAttitudeMax  = sellerServiceAttitudeMax.CommentValue;
                detailModel.SellerServiceAttitudeMin  = sellerServiceAttitudeMin.CommentValue;
            }
            else
            {
                detailModel.SellerServiceAttitude     = defaultValue;
                detailModel.SellerServiceAttitudePeer = defaultValue;
                detailModel.SellerServiceAttitudeMax  = defaultValue;
                detailModel.SellerServiceAttitudeMin  = defaultValue;
            }
            //卖家发货速度
            if (sellerDeliverySpeedPeer != null && sellerDeliverySpeed != null)
            {
                detailModel.SellerDeliverySpeed     = sellerDeliverySpeed.CommentValue;
                detailModel.SellerDeliverySpeedPeer = sellerDeliverySpeedPeer.CommentValue;
                detailModel.SellerDeliverySpeedMax  = sellerDeliverySpeedMax != null ? sellerDeliverySpeedMax.CommentValue : 0;
                detailModel.sellerDeliverySpeedMin  = sellerDeliverySpeedMin != null ? sellerDeliverySpeedMin.CommentValue : 0;
            }
            else
            {
                detailModel.SellerDeliverySpeed     = defaultValue;
                detailModel.SellerDeliverySpeedPeer = defaultValue;
                detailModel.SellerDeliverySpeedMax  = defaultValue;
                detailModel.sellerDeliverySpeedMin  = defaultValue;
            }
            #endregion


            model.Product = product;

            //var comments = ServiceHelper.Create<ICommentService>().GetComments(new CommentQuery
            //{
            //    ProductID = product.Id,
            //    PageNo = 1,
            //    PageSize = 10000
            //});
            //detailModel.CommentCount = comments.Total;

            var com      = product.Himall_ProductComments.Where(item => !item.IsHidden.HasValue || item.IsHidden.Value == false);
            var comCount = com.Count();
            detailModel.CommentCount = comCount;

            var consultations = ServiceHelper.Create <IConsultationService>().GetConsultations(gid);

            //double total = product.Himall_ProductComments.Count();
            //double niceTotal = product.Himall_ProductComments.Count(item => item.ReviewMark >= 4);
            double total     = (double)comCount;
            double niceTotal = com.Count(item => item.ReviewMark >= 4);
            detailModel.NicePercent   = (int)((niceTotal / total) * 100);
            detailModel.Consultations = consultations.Count();
            long vShopId;
            if (shopService.GetVShopByShopId(shop.Id) == null)
            {
                vShopId = -1;
            }
            else
            {
                vShopId = shopService.GetVShopByShopId(shop.Id).Id;
            }
            detailModel.VShopId = vShopId;
            model.Shop.VShopId  = vShopId;
            var bonus = ServiceHelper.Create <IShopBonusService>().GetByShopId(shop.Id);
            if (bonus != null)
            {
                detailModel.BonusCount             = bonus.Count;
                detailModel.BonusGrantPrice        = bonus.GrantPrice;
                detailModel.BonusRandomAmountStart = bonus.RandomAmountStart;
                detailModel.BonusRandomAmountEnd   = bonus.RandomAmountEnd;
            }
            detailModel.CashDepositsObligation = ServiceHelper.Create <ICashDepositsService>().GetCashDepositsObligation(product.Id);
            var cashDepositModel = ServiceHelper.Create <ICashDepositsService>().GetCashDepositsObligation(product.Id);
            model.CashDepositsServer = cashDepositModel;
            model.VShopLog           = shopService.GetVShopLog(model.Shop.VShopId);
            model.FavoriteShopCount  = _iShopService.GetShopFavoritesCount(product.ShopId);

            ViewBag.DetailModel = detailModel;


            //分销信息

            return(View(model));
        }