Пример #1
0
        public object GetVshopIndexProduct(long pid)
        {
            var productInfo = ServiceProvider.Instance <IProductService> .Create.GetProduct(pid);

            if (productInfo != null)
            {
                decimal discount   = 1M;
                long    SelfShopId = 0;
                var     CartInfo   = new Entities.ShoppingCartInfo();
                long    userId     = 0;
                if (CurrentUser != null)
                {
                    userId   = CurrentUser.Id;
                    discount = CurrentUser.MemberDiscount;
                    var shopInfo = ShopApplication.GetSelfShop();
                    SelfShopId = shopInfo.Id;
                    CartInfo   = ServiceProvider.Instance <ICartService> .Create.GetCart(CurrentUser.Id);
                }

                decimal MinSalePrice = 0M;
                long    activeId     = 0;
                int     activetype   = 0;
                var     limitBuy     = ServiceProvider.Instance <ILimitTimeBuyService> .Create.GetLimitTimeMarketItemByProductId(pid);

                if (limitBuy != null)
                {
                    MinSalePrice = limitBuy.MinPrice;
                    activeId     = limitBuy.Id;
                    activetype   = 1;
                }

                long stock = 0;
                var  skus  = ProductManagerApplication.GetSKUs(productInfo.Id);
                stock = skus.Sum(x => x.Stock);
                if (productInfo.MaxBuyCount > 0)
                {
                    stock = productInfo.MaxBuyCount;
                }
                if (productInfo.AuditStatus == Entities.ProductInfo.ProductAuditStatus.Audited)
                {
                    var ChoiceProducts = new
                    {
                        ProductId       = pid,
                        ProductName     = productInfo.ProductName,
                        SalePrice       = productInfo.MinSalePrice.ToString("0.##"),
                        ThumbnailUrl160 = productInfo.ImagePath,
                        MarketPrice     = productInfo.MarketPrice.ToString("0.##"),
                        HasSKU          = productInfo.HasSKU,
                        SkuId           = GetSkuIdByProductId(pid),
                        ActiveId        = activeId,
                        ActiveType      = activetype,//获取该商品是否参与活动
                        Stock           = stock,
                        IsVirtual       = productInfo.ProductType == 1
                    };
                    return(Json(ChoiceProducts));
                }
                return(ErrorResult <dynamic>("商品已下架!"));
            }
            return(ErrorResult <dynamic>("商品信息有误!"));
        }
Пример #2
0
        public JsonResult GetSalePrice()
        {
            //会员折扣
            decimal discount = 1M;
            long    shopId   = 0;

            if (CurrentUser != null)
            {
                discount = CurrentUser.MemberDiscount;
                var shopInfo = ShopApplication.GetSelfShop();
                shopId = shopInfo.Id;
            }

            var list = LimitTimeApplication.GetLimitProducts();

            return(Json(new { success = true, SelfShopId = shopId, Discount = discount, LimitProducts = list }, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public JsonResult GetSalePrice()
        {
            //会员折扣
            decimal discount = 1M;
            long    shopId   = 0;

            if (CurrentUser != null)
            {
                discount = CurrentUser.MemberDiscount;
                var shopInfo = ShopApplication.GetSelfShop();
                shopId = shopInfo.Id;
            }

            var limit = LimitTimeApplication.GetLimitProducts();
            var fight = FightGroupApplication.GetFightGroupPrice();

            return(Json <dynamic>(success: true, data: new { SelfShopId = shopId, Discount = discount, LimitProducts = limit, FightProducts = fight }));
        }
Пример #4
0
        public object GetIndexProductData(string openId = "", int pageIndex = 10, int pageSize = 1)
        {
            //CheckUserLogin();
            var homeProducts = ServiceProvider.Instance <IWXSmallProgramService> .Create.GetWXSmallHomeProducts().OrderBy(item => item.Id).Skip((pageIndex - 1) * pageSize).Take(pageSize);

            decimal          discount           = 1M;
            long             SelfShopId         = 0;
            ShoppingCartInfo CartInfo           = new ShoppingCartInfo();
            var                     ids         = homeProducts.Select(d => d.Id).ToArray();
            List <object>           productList = new List <object>();
            List <ShoppingCartItem> cartitems   = new List <ShoppingCartItem>();

            if (CurrentUser != null)
            {
                discount = CurrentUser.MemberDiscount;
                var shopInfo = ShopApplication.GetSelfShop();
                SelfShopId = shopInfo.Id;
                CartInfo   = ServiceProvider.Instance <ICartService> .Create.GetCart(CurrentUser.Id);

                cartitems = CartApplication.GetCartQuantityByIds(CurrentUser.Id, ids);
            }

            var limit = LimitTimeApplication.GetLimitProducts();

            //var fight = FightGroupApplication.GetFightGroupPrice();

            foreach (var item in homeProducts)
            {
                long activeId   = 0;
                int  activetype = 0;
                item.ImagePath = Core.HimallIO.GetRomoteProductSizeImage(Core.HimallIO.GetImagePath(item.ImagePath), 1, (int)Himall.CommonModel.ImageSize.Size_350);
                if (item.ShopId == SelfShopId)
                {
                    item.MinSalePrice = item.MinSalePrice * discount;
                }
                var limitBuy = ServiceProvider.Instance <ILimitTimeBuyService> .Create.GetLimitTimeMarketItemByProductId(item.Id);

                if (limitBuy != null)
                {
                    item.MinSalePrice = limitBuy.MinPrice;
                    activeId          = limitBuy.Id;
                    activetype        = 1;
                }
                int quantity = 0;
                quantity = cartitems.Where(d => d.ProductId == item.Id).Sum(d => d.Quantity);
                //火拼
                //if (activeInfo != null)
                //{
                //    item.MinSalePrice = activeInfo.MiniGroupPrice;
                //    activeId = activeInfo.Id;
                //    activetype = 2;
                //}
                var ChoiceProducts = new
                {
                    ProductId       = item.Id,
                    ProductName     = item.ProductName,
                    SalePrice       = item.MinSalePrice.ToString("0.##"),
                    ThumbnailUrl160 = item.ImagePath,
                    MarketPrice     = item.MarketPrice.ToString("0.##"),
                    CartQuantity    = quantity,
                    HasSKU          = item.HasSKU,
                    SkuId           = GetSkuIdByProductId(item.Id), //d.Himall_Products d.Field<string>("SkuId"),
                    ActiveId        = activeId,
                    ActiveType      = activetype                    //获取该商品是否参与活动
                };
                productList.Add(ChoiceProducts);
            }
            var json = new
            {
                Status = "OK",
                Data   = new {
                    ChoiceProducts = productList
                }
            };

            return(json);
        }
Пример #5
0
        public object GetVShop(long id, bool sv = false)
        {
            //Json(ErrorResult<int>("取消失败,该订单已删除或者不属于当前用户!"));
            var vshopService = ServiceProvider.Instance <IVShopService> .Create;
            var vshop        = vshopService.GetVShop(id);

            if (vshop == null)
            {
                return(ErrorResult <bool>("未开通微店!", code: -4));
            }
            if (vshop.State == Entities.VShopInfo.VShopStates.Close)
            {
                return(ErrorResult <bool>("商家暂未开通微店!", code: -5));
            }
            if (!vshop.IsOpen)
            {
                return(ErrorResult <bool>("此微店已关闭!", code: -3));
            }
            var s = ShopApplication.GetShop(vshop.ShopId);

            if (null != s && s.ShopStatus == Entities.ShopInfo.ShopAuditStatus.HasExpired)
            {
                return(ErrorResult <bool>("此店铺已过期!", code: -1));
            }
            //throw new MallApiException("此店铺已过期");
            if (null != s && s.ShopStatus == Entities.ShopInfo.ShopAuditStatus.Freeze)
            {
                return(ErrorResult <bool>("此店铺已冻结!", code: -2));
            }

            //throw new MallApiException("此店铺已冻结");

            //轮播图配置只有商家微店首页配置页面可配置,现在移动端都读的这个数据
            var slideImgs = ServiceProvider.Instance <ISlideAdsService> .Create.GetSlidAds(vshop.ShopId, Entities.SlideAdInfo.SlideAdType.VShopHome).ToList();

            //首页商品现在只有商家配置微信首页,APP读的也是这个数据所以平台类型选的的微信端
            var homeProducts = ServiceProvider.Instance <IMobileHomeProductsService> .Create.GetMobileHomeProducts(vshop.ShopId, PlatformType.WeiXin, 1, 8);

            #region 价格更新
            //会员折扣
            decimal discount   = 1M;
            long    SelfShopId = 0;
            if (CurrentUser != null)
            {
                discount = CurrentUser.MemberDiscount;
                var shopInfo = ShopApplication.GetSelfShop();
                SelfShopId = shopInfo.Id;
            }

            var limit = LimitTimeApplication.GetLimitProducts();
            var fight = FightGroupApplication.GetFightGroupPrice();

            var products    = new List <ProductItem>();
            var productData = ProductManagerApplication.GetProducts(homeProducts.Models.Select(p => p.ProductId));
            foreach (var item in homeProducts.Models)
            {
                var product = productData.FirstOrDefault(p => p.Id == item.ProductId);
                var pitem   = new ProductItem();
                pitem.Id          = item.ProductId;
                pitem.ImageUrl    = Core.MallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Mall.CommonModel.ImageSize.Size_350);
                pitem.Name        = product.ProductName;
                pitem.MarketPrice = product.MarketPrice;
                pitem.SalePrice   = product.MinSalePrice;
                if (item.ShopId == SelfShopId)
                {
                    pitem.SalePrice = product.MinSalePrice * discount;
                }
                var isLimit = limit.Where(r => r.ProductId == item.ProductId).FirstOrDefault();
                var isFight = fight.Where(r => r.ProductId == item.ProductId).FirstOrDefault();
                if (isLimit != null)
                {
                    pitem.SalePrice = isLimit.MinPrice;
                }
                if (isFight != null)
                {
                    pitem.SalePrice = isFight.ActivePrice;
                }
                products.Add(pitem);
            }
            #endregion
            var banner = ServiceProvider.Instance <INavigationService> .Create.GetSellerNavigations(vshop.ShopId, Core.PlatformType.WeiXin).ToList();

            var couponInfo = GetCouponList(vshop.ShopId);

            var SlideAds = slideImgs.ToArray().Select(item => new HomeSlideAdsModel()
            {
                ImageUrl = Core.MallIO.GetRomoteImagePath(item.ImageUrl), Url = item.Url
            });

            var Banner   = banner;
            var Products = products;

            bool favoriteShop = false;
            if (CurrentUser != null)
            {
                favoriteShop = ServiceProvider.Instance <IShopService> .Create.IsFavoriteShop(CurrentUser.Id, vshop.ShopId);
            }
            string followUrl = "";
            //快速关注
            var vshopSetting = ServiceProvider.Instance <IVShopService> .Create.GetVShopSetting(vshop.ShopId);

            if (vshopSetting != null)
            {
                followUrl = vshopSetting.FollowUrl;
            }
            var model = new
            {
                Id = vshop.Id,
                //Logo = "http://" + Url.Request.RequestUri.Host + vshop.Logo,
                Logo      = Core.MallIO.GetRomoteImagePath(vshop.StrLogo),
                Name      = vshop.Name,
                ShopId    = vshop.ShopId,
                Favorite  = favoriteShop,
                State     = vshop.State,
                FollowUrl = followUrl
            };

            // 客服
            var customerServices = CustomerServiceApplication.GetMobileCustomerServiceAndMQ(vshop.ShopId);

            //统计访问量
            if (!sv)
            {
                vshopService.LogVisit(id);
                //统计店铺访问人数
                StatisticApplication.StatisticShopVisitUserCount(vshop.ShopId);
            }
            dynamic result = new ExpandoObject();
            result.VShop            = model;
            result.SlideImgs        = SlideAds;
            result.Products         = products;
            result.Banner           = banner;
            result.Coupon           = couponInfo;
            result.CustomerServices = customerServices;
            return(Json(new { result }));
        }
Пример #6
0
        public ActionResult Detail(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Error404", "Error", new { area = "Web" }));
            }
            string price = "";

            #region 定义Model和变量

            LimitTimeProductDetailModel model = new LimitTimeProductDetailModel
            {
                MainId = long.Parse(id),
                HotAttentionProducts = new List <HotProductInfo>(),
                HotSaleProducts      = new List <HotProductInfo>(),
                Product      = new Entities.ProductInfo(),
                Shop         = new ShopInfoModel(),
                ShopCategory = new List <CategoryJsonModel>(),
                Color        = new CollectionSKU(),
                Size         = new CollectionSKU(),
                Version      = new CollectionSKU()
            };

            FlashSaleModel    market = null;
            Entities.ShopInfo shop   = null;

            long gid = 0, mid = 0;

            #endregion


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


            #region 初始化商品和店铺

            market = _iLimitTimeBuyService.Get(mid);

            switch (market.Status)
            {
            case Entities.FlashSaleInfo.FlashSaleStatus.Ended:
                return(RedirectToAction("Detail", "Product", new { id = market.ProductId }));

            case Entities.FlashSaleInfo.FlashSaleStatus.Cancelled:
                return(RedirectToAction("Detail", "Product", new { id = market.ProductId }));
            }
            if (market.Status != Entities.FlashSaleInfo.FlashSaleStatus.Ongoing)
            {
                return(RedirectToAction("Home"));
            }
            model.FlashSale = market;
            if (market == null || market.Id == 0 || market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing)
            {
                //可能参数是商品ID
                market = market == null?_iLimitTimeBuyService.GetFlaseSaleByProductId(mid) : market;

                if (market == null)
                {
                    //跳转到404页面
                    return(RedirectToAction("Error404", "Error", new { area = "Mobile" }));
                }
                if (market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing)
                {
                    return(RedirectToAction("Detail", "Product", new { id = market.ProductId }));
                }
            }

            model.MaxSaleCount = market.LimitCountOfThePeople;
            model.Title        = market.Title;

            shop            = _iShopService.GetShop(market.ShopId);
            model.Shop.Name = shop.ShopName;
            #endregion

            #region 商品描述
            var product = _iProductService.GetProduct(market.ProductId);
            gid = market.ProductId;


            var brandModel = ServiceApplication.Create <IBrandService>().GetBrand(product.BrandId);
            product.BrandName = brandModel == null ? "" : brandModel.Name;
            if (CurrentUser != null && CurrentUser.Id > 0)
            {
                product.IsFavorite = ProductManagerApplication.IsFavorite(product.Id, CurrentUser.Id);
            }
            model.Product = product;
            model.Skus    = ProductManagerApplication.GetSKUsByProduct(new List <long> {
                product.Id
            });
            var description = ProductManagerApplication.GetProductDescription(product.Id);
            model.ProductDescription = description.Description;
            if (description.DescriptionPrefixId != 0)
            {
                var desc = _iProductDescriptionTemplateService
                           .GetTemplate(description.DescriptionPrefixId, product.ShopId);
                model.DescriptionPrefix = desc == null ? "" : desc.Content;
            }

            if (description.DescriptiondSuffixId != 0)
            {
                var desc = _iProductDescriptionTemplateService
                           .GetTemplate(description.DescriptiondSuffixId, product.ShopId);
                model.DescriptiondSuffix = desc == null ? "" : desc.Content;
            }

            #endregion

            #region 店铺

            var categories = _iShopCategoryService.GetShopCategory(product.ShopId);
            List <Entities.ShopCategoryInfo> allcate = categories.ToList();
            foreach (var main in allcate.Where(s => s.ParentCategoryId == 0))
            {
                var topC = new CategoryJsonModel()
                {
                    Name        = main.Name,
                    Id          = main.Id.ToString(),
                    SubCategory = new List <SecondLevelCategory>()
                };
                foreach (var secondItem in allcate.Where(s => s.ParentCategoryId == main.Id))
                {
                    var secondC = new SecondLevelCategory()
                    {
                        Name = secondItem.Name,
                        Id   = secondItem.Id.ToString(),
                    };

                    topC.SubCategory.Add(secondC);
                }
                model.ShopCategory.Add(topC);
            }
            model.CashDeposits = _iCashDepositsService.GetCashDepositsObligation(product.Id);

            #endregion

            #region 热门销售

            //会员折扣
            decimal discount   = 1M;
            long    SelfShopId = 0;
            if (CurrentUser != null)
            {
                discount = CurrentUser.MemberDiscount;
                var shopInfo = ShopApplication.GetSelfShop();
                SelfShopId = shopInfo.Id;
            }
            var sale = _iProductService.GetHotSaleProduct(shop.Id, 5);
            if (sale != null)
            {
                foreach (var item in sale.ToArray())
                {
                    var salePrice = item.MinSalePrice;
                    if (item.ShopId == SelfShopId)
                    {
                        salePrice = item.MinSalePrice * discount;
                    }
                    var limitBuy = LimitTimeApplication.GetLimitTimeMarketItemByProductId(item.Id);
                    if (limitBuy != null)
                    {
                        salePrice = limitBuy.MinPrice;
                    }
                    model.HotSaleProducts.Add(new HotProductInfo
                    {
                        ImgPath   = item.ImagePath,
                        Name      = item.ProductName,
                        Price     = Math.Round(salePrice, 2),
                        Id        = item.Id,
                        SaleCount = (int)item.SaleCounts + Mall.Core.Helper.TypeHelper.ObjectToInt(item.VirtualSaleCounts)
                    });
                }
            }

            #endregion

            #region 热门关注

            var hot = _iProductService.GetHotConcernedProduct(shop.Id, 5);
            if (hot != null)
            {
                foreach (var item in hot.ToArray())
                {
                    model.HotAttentionProducts.Add(new HotProductInfo
                    {
                        ImgPath   = item.ImagePath,
                        Name      = item.ProductName,
                        Price     = item.MinSalePrice,
                        Id        = item.Id,
                        SaleCount = (int)item.ConcernedCount
                    });
                }
            }
            #endregion

            #region 商品规格

            Entities.TypeInfo 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;
            if (product != null)
            {
                colorAlias   = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias;
                sizeAlias    = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias;
                versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias;
            }
            model.ColorAlias   = colorAlias;
            model.SizeAlias    = sizeAlias;
            model.VersionAlias = versionAlias;
            var skus = _iProductService.GetSKUs(product.Id);
            if (skus.Count > 0)
            {
                long colorId = 0, sizeId = 0, versionId = 0;
                foreach (var sku in skus)
                {
                    var specs = sku.Id.Split('_');
                    if (specs.Count() > 0 && !string.IsNullOrEmpty(sku.Color))
                    {
                        if (long.TryParse(specs[1], out colorId))
                        {
                        }
                        if (colorId != 0)
                        {
                            if (!model.Color.Any(v => v.Value.Equals(sku.Color)))
                            {
                                var c = skus.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           = Mall.Core.MallIO.GetImagePath(sku.ShowPic)
                                });
                            }
                        }
                    }
                    if (specs.Count() > 1 && !string.IsNullOrEmpty(sku.Size))
                    {
                        if (long.TryParse(specs[2], out sizeId))
                        {
                        }
                        if (sizeId != 0)
                        {
                            if (!model.Size.Any(v => v.Value.Equals(sku.Size)))
                            {
                                var ss = skus.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 && !string.IsNullOrEmpty(sku.Version))
                    {
                        if (long.TryParse(specs[3], out versionId))
                        {
                        }
                        if (versionId != 0)
                        {
                            if (!model.Version.Any(v => v.Value.Equals(sku.Version)))
                            {
                                var v = skus.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
                                });
                            }
                        }
                    }
                }

                price = ProductWebApplication.GetProductPriceStr(product, skus, discount);//最小价或区间价文本
            }
            model.Price = string.IsNullOrWhiteSpace(price) ? product.MinSalePrice.ToString("f2") : price;
            #endregion

            #region 商品属性
            List <TypeAttributesModel> ProductAttrs = new List <TypeAttributesModel>();
            var prodAttrs = ProductManagerApplication.GetProductAttributes(product.Id);
            foreach (var attr in prodAttrs)
            {
                if (!ProductAttrs.Any(p => p.AttrId == attr.AttributeId))
                {
                    var attribute = _iTypeService.GetAttribute(attr.AttributeId);
                    var values    = _iTypeService.GetAttributeValues(attr.AttributeId);
                    var attrModel = new TypeAttributesModel()
                    {
                        AttrId     = attr.AttributeId,
                        AttrValues = new List <TypeAttrValue>(),
                        Name       = attribute.Name
                    };
                    foreach (var attrV in values)
                    {
                        if (prodAttrs.Any(p => p.ValueId == attrV.Id))
                        {
                            attrModel.AttrValues.Add(new TypeAttrValue
                            {
                                Id   = attrV.Id.ToString(),
                                Name = attrV.Value
                            });
                        }
                    }
                    ProductAttrs.Add(attrModel);
                }
                else
                {
                    var attrTemp = ProductAttrs.FirstOrDefault(p => p.AttrId == attr.AttributeId);
                    var values   = _iTypeService.GetAttributeValues(attr.AttributeId);
                    if (!attrTemp.AttrValues.Any(p => p.Id == attr.ValueId.ToString()))
                    {
                        attrTemp.AttrValues.Add(new TypeAttrValue
                        {
                            Id   = attr.ValueId.ToString(),
                            Name = values.FirstOrDefault(a => a.Id == attr.ValueId).Value
                        });
                    }
                }
            }
            model.ProductAttrs = ProductAttrs;
            #endregion

            #region 获取评论、咨询数量

            model.CommentCount = CommentApplication.GetCommentCountByProduct(product.Id);

            var consultations = _iConsultationService.GetConsultations(gid);
            model.Consultations = consultations.Count();

            #endregion

            #region 累加浏览次数、 加入历史记录
            if (CurrentUser != null)
            {
                BrowseHistrory.AddBrowsingProduct(product.Id, CurrentUser.Id);
            }
            else
            {
                BrowseHistrory.AddBrowsingProduct(product.Id);
            }

            //_iProductService.LogProductVisti(gid);
            //统计商品浏览量、店铺浏览人数
            StatisticApplication.StatisticVisitCount(product.Id, product.ShopId);
            #endregion

            #region 红包
            var bonus = ServiceApplication.Create <IShopBonusService>().GetByShopId(product.ShopId);
            if (bonus != null)
            {
                model.GrantPrice = bonus.GrantPrice;
            }
            else
            {
                model.GrantPrice = 0;
            }
            #endregion

            #region 获取店铺的评价统计

            var shopStatisticOrderComments = _iShopService.GetShopStatisticOrderComments(shop.Id);

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

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

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

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

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

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

            #region 客服
            model.Service = ServiceApplication.Create <ICustomerService>().GetCustomerService(shop.Id).Where(c => c.Type == Entities.CustomerServiceInfo.ServiceType.PreSale && c.TerminalType == Entities.CustomerServiceInfo.ServiceTerminalType.PC).OrderBy(m => m.Tool);
            #endregion

            #region 开团提醒场景二维码
            var siteSetting = SiteSettingApplication.SiteSettings;
            if (DateTime.Parse(model.FlashSale.BeginDate) > DateTime.Now && WXIsConfig(siteSetting.WeixinAppId, siteSetting.WeixinAppSecret))
            {
                try
                {
                    var         token   = AccessTokenContainer.TryGetAccessToken(siteSetting.WeixinAppId, siteSetting.WeixinAppSecret);
                    SceneHelper helper  = new SceneHelper();
                    SceneModel  scene   = new SceneModel(QR_SCENE_Type.FlashSaleRemind, model.FlashSale.Id);
                    int         sceneId = helper.SetModel(scene);
                    var         ticket  = QrCodeApi.Create(token, 86400, sceneId, Senparc.Weixin.MP.QrCode_ActionName.QR_LIMIT_SCENE, null).ticket;
                    ViewBag.ticket = ticket;
                }
                catch { }
            }
            #endregion

            model.Logined    = (null != CurrentUser) ? 1 : 0;
            model.EnabledBuy = product.AuditStatus == Entities.ProductInfo.ProductAuditStatus.Audited && DateTime.Parse(market.BeginDate) <= DateTime.Now && DateTime.Parse(market.EndDate) > DateTime.Now && product.SaleStatus == Entities.ProductInfo.ProductSaleStatus.OnSale;
            if (market.Status == FlashSaleInfo.FlashSaleStatus.Ongoing && DateTime.Parse(market.BeginDate) < DateTime.Now && DateTime.Parse(market.EndDate) > DateTime.Now)
            {
                TimeSpan end   = new TimeSpan(DateTime.Parse(market.EndDate).Ticks);
                TimeSpan start = new TimeSpan(DateTime.Now.Ticks);
                TimeSpan ts    = end.Subtract(start);
                model.Second = ts.TotalSeconds < 0 ? 0 : ts.TotalSeconds;
            }
            else if (market.Status == FlashSaleInfo.FlashSaleStatus.Ongoing && DateTime.Parse(market.BeginDate) > DateTime.Now)
            {
                TimeSpan end   = new TimeSpan(DateTime.Parse(market.BeginDate).Ticks);
                TimeSpan start = new TimeSpan(DateTime.Now.Ticks);
                TimeSpan ts    = end.Subtract(start);
                model.Second = ts.TotalSeconds < 0 ? 0 : ts.TotalSeconds;
            }

            //补充当前店铺红包功能
            ViewBag.isShopPage     = true;
            ViewBag.CurShopId      = product.ShopId;
            TempData["isShopPage"] = true;
            TempData["CurShopId"]  = product.ShopId;

            ViewBag.Keyword          = SiteSettings.Keyword;
            ViewBag.Quantity         = market.Quantity;//总活动库存
            model.VirtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(product.Id);
            model.FreightTemplate    = FreightTemplateApplication.GetFreightTemplate(product.FreightTemplateId);
            return(View(model));
        }
Пример #7
0
        /// <summary>
        /// 首页商品信息
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public JsonResult <Result <List <dynamic> > > GetIndexProductData(string openId = "", int pageIndex = 1, int pageSize = 10)
        {
            var homeProducts = ServiceProvider.Instance <IWXSmallProgramService> .Create.GetWXSmallHomeProducts(pageIndex, pageSize);

            decimal discount    = 1M;
            long    SelfShopId  = 0;
            var     CartInfo    = new Himall.Entities.ShoppingCartInfo();
            var     ids         = homeProducts.Models.Select(p => p.Id).ToList();
            var     productList = new List <dynamic>();
            var     cartitems   = new List <Himall.Entities.ShoppingCartItem>();
            long    userId      = 0;

            if (CurrentUser != null)
            {
                userId   = CurrentUser.Id;
                discount = CurrentUser.MemberDiscount;
                var shopInfo = ShopApplication.GetSelfShop();
                SelfShopId = shopInfo.Id;
                CartInfo   = ServiceProvider.Instance <ICartService> .Create.GetCart(CurrentUser.Id);

                cartitems = CartApplication.GetCartQuantityByIds(CurrentUser.Id, ids);
            }

            foreach (var item in homeProducts.Models)
            {
                long activeId   = 0;
                int  activetype = 0;
                item.ImagePath = Core.HimallIO.GetRomoteProductSizeImage(Core.HimallIO.GetImagePath(item.ImagePath), 1, (int)Himall.CommonModel.ImageSize.Size_350);
                if (item.ShopId == SelfShopId)
                {
                    item.MinSalePrice = item.MinSalePrice * discount;
                }
                var limitBuy = ServiceProvider.Instance <ILimitTimeBuyService> .Create.GetLimitTimeMarketItemByProductId(item.Id);

                if (limitBuy != null)
                {
                    item.MinSalePrice = limitBuy.MinPrice;
                    activeId          = limitBuy.Id;
                    activetype        = 1;
                }
                int quantity = 0;
                quantity = cartitems.Where(d => d.ProductId == item.Id).Sum(d => d.Quantity);

                long stock = 0;

                var productInfo = ServiceProvider.Instance <IProductService> .Create.GetProduct(item.Id);

                if (productInfo != null)
                {
                    var skus = ProductManagerApplication.GetSKUs(productInfo.Id);
                    stock = skus.Sum(x => x.Stock);
                    if (productInfo.MaxBuyCount > 0)
                    {
                        stock = productInfo.MaxBuyCount;
                    }
                }
                if (productInfo.AuditStatus == Entities.ProductInfo.ProductAuditStatus.Audited)
                {
                    var ChoiceProducts = new
                    {
                        ProductId       = item.Id,
                        ProductName     = item.ProductName,
                        SalePrice       = item.MinSalePrice.ToString("0.##"),
                        ThumbnailUrl160 = item.ImagePath,
                        MarketPrice     = item.MarketPrice.ToString("0.##"),
                        CartQuantity    = quantity,
                        HasSKU          = item.HasSKU,
                        SkuId           = GetSkuIdByProductId(item.Id),
                        ActiveId        = activeId,
                        ActiveType      = activetype,//获取该商品是否参与活动
                        Stock           = stock,
                        IsVirtual       = item.ProductType == 1
                    };
                    productList.Add(ChoiceProducts);
                }
            }
            return(JsonResult(productList));
        }
Пример #8
0
        public object GetSearchProducts(
            string keywords = "", /* 搜索关键字 */
            long cid        = 0,  /* 分类ID */
            long b_id       = 0,  /* 品牌ID */
            string a_id     = "", /* 属性ID, 表现形式:attrId_attrValueId */
            int orderKey    = 1,  /* 排序项(1:默认,2:销量,3:价格,4:评论数,5:上架时间) */
            int orderType   = 1,  /* 排序方式(1:升序,2:降序) */
            int pageNo      = 1,  /*页码*/
            int pageSize    = 10, /*每页显示数据量*/
            long vshopId    = 0,
            long sid        = 0   /*商家ID*/
            )
        {
            if (string.IsNullOrEmpty(keywords) && vshopId == 0 && cid <= 0 && b_id <= 0 && a_id == "")
            {
                keywords = Application.SiteSettingApplication.GetSiteSettings().Keyword;
            }
            #region 初始化查询Model
            SearchProductQuery model = new SearchProductQuery();
            model.VShopId = vshopId;
            model.ShopId  = sid;
            model.BrandId = b_id;
            if (vshopId == 0 && cid != 0)
            {
                var catelist = ServiceProvider.Instance <ICategoryService> .Create.GetCategories();

                var cate = catelist.FirstOrDefault(r => r.Id == cid);
                if (cate.Depth == 1)
                {
                    model.FirstCateId = cid;
                }
                else if (cate.Depth == 2)
                {
                    model.SecondCateId = cid;
                }
                else if (cate.Depth == 3)
                {
                    model.ThirdCateId = cid;
                }
            }
            else if (vshopId != 0 && cid != 0)
            {
                model.ShopCategoryId = cid;
            }
            model.AttrValIds = a_id.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            model.Keyword    = keywords;
            model.OrderKey   = orderKey;
            model.OrderType  = orderType == 1;
            model.PageNumber = pageNo;
            model.PageSize   = pageSize;
            #endregion
            SearchProductResult result = ServiceProvider.Instance <ISearchProductService> .Create.SearchProduct(model);

            int total = result.Total;
            //当查询的结果少于一页时用like进行补偿(与PC端同步)
            if (result.Total < pageSize)
            {
                model.IsLikeSearch = true;
                SearchProductResult result2 = ServiceProvider.Instance <ISearchProductService> .Create.SearchProduct(model);

                var idList1 = result.Data.Select(a => a.ProductId).ToList();
                var nresult = result2.Data.Where(a => !idList1.Contains(a.ProductId)).ToList();
                if (nresult.Count > 0)
                {
                    result.Total += nresult.Count;
                    result.Data.AddRange(nresult);
                }
            }
            total = result.Total;

            #region 价格更新
            //会员折扣
            decimal discount   = 1M;
            long    SelfShopId = 0;
            if (CurrentUser != null)
            {
                discount = CurrentUser.MemberDiscount;
                var shopInfo = ShopApplication.GetSelfShop();
                SelfShopId = shopInfo.Id;
            }

            var limit = LimitTimeApplication.GetLimitProducts();
            var fight = FightGroupApplication.GetFightGroupPrice();

            foreach (var item in result.Data)
            {
                item.ImagePath = Core.HimallIO.GetRomoteProductSizeImage(Core.HimallIO.GetImagePath(item.ImagePath), 1, (int)Himall.CommonModel.ImageSize.Size_350);
                if (item.ShopId == SelfShopId)
                {
                    item.SalePrice = item.SalePrice * discount;
                }
                var isLimit = limit.Where(r => r.ProductId == item.ProductId).FirstOrDefault();
                var isFight = fight.Where(r => r.ProductId == item.ProductId).FirstOrDefault();
                if (isLimit != null)
                {
                    item.SalePrice = isLimit.MinPrice;
                }
                if (isFight != null)
                {
                    item.SalePrice = isFight.ActivePrice;
                }
            }
            #endregion

            return(Json(new
            {
                Success = "true",
                Product = result.Data,
                keywords = model.Keyword,
                Total = total,
                cid = cid,
                b_id = b_id,
                a_id = a_id,
                orderKey = orderKey,
                orderType = orderType
            }));
        }