Exemple #1
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 }));
        }
Exemple #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 limit = LimitTimeApplication.GetLimitProducts();
            var fight = FightGroupApplication.GetFightGroupPrice();

            return(Json(new { success = true, SelfShopId = shopId, Discount = discount, LimitProducts = limit, FightProducts = fight }, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
        //APP首页配置共用于安卓和IOS,这里的平台类型写的为IOS,安卓调用首页接口数据时平台类型也选IOS
        public APPHome Get(int pageNo, int pageSize)
        {
            var slideImageSettings = ServiceProvider.Instance <ISlideAdsService> .Create.GetSlidAds(0, Entities.SlideAdInfo.SlideAdType.IOSShopHome);

            var images = ServiceProvider.Instance <ISlideAdsService> .Create.GetImageAds(0, Himall.CommonModel.ImageAdsType.APPSpecial).ToList();

            var     mhproser      = ServiceProvider.Instance <IMobileHomeProductsService> .Create;
            var     data          = mhproser.GetMobileHomeProducts(0, PlatformType.IOS, pageNo, pageSize);
            var     totalProducts = data.Total;
            var     homeProducts  = data.Models;
            decimal discount      = 1M;

            if (CurrentUser != null)
            {
                discount = CurrentUser.MemberDiscount;
            }
            var products = new List <HomeProduct>();

            var limitService = ServiceProvider.Instance <ILimitTimeBuyService> .Create;
            var fight        = FightGroupApplication.GetFightGroupPrice();
            var allProducts  = ProductManagerApplication.GetProducts(homeProducts.Select(p => p.ProductId));
            var allShops     = ShopApplication.GetShops(allProducts.Select(p => p.ShopId));

            foreach (var item in homeProducts)
            {
                var     limitBuy     = limitService.GetLimitTimeMarketItemByProductId(item.ProductId);
                var     product      = allProducts.FirstOrDefault(p => p.Id == item.ProductId);
                var     shop         = allShops.FirstOrDefault(p => p.Id == product.ShopId);
                decimal minSalePrice = shop.IsSelf ? product.MinSalePrice * discount : product.MinSalePrice;
                if (limitBuy != null)
                {
                    minSalePrice = limitBuy.MinPrice; //限时购不打折
                }
                var  isFight  = fight.Where(r => r.ProductId == item.ProductId).FirstOrDefault();
                long activeId = 0;
                if (isFight != null)
                {
                    minSalePrice = isFight.ActivePrice;
                    activeId     = isFight.ActiveId;
                }
                products.Add(new HomeProduct()
                {
                    Id           = item.ProductId.ToString(),
                    ImageUrl     = HimallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)CommonModel.ImageSize.Size_220),
                    Name         = product.ProductName,
                    MarketPrice  = product.MarketPrice.ToString(),
                    SalePrice    = minSalePrice.ToString("f2"),
                    Discount     = product.MarketPrice <= 0 ? "0" : (minSalePrice / product.MarketPrice).ToString("0.0"),
                    Url          = Core.HimallIO.GetRomoteImagePath("/m-ios/product/detail/" + item.ProductId),
                    FightGroupId = activeId
                });
            }

            var iconSettings = ServiceProvider.Instance <ISlideAdsService> .Create.GetSlidAds(0, Entities.SlideAdInfo.SlideAdType.APPIcon);

            var icon = iconSettings.ToArray().Select(item => new HomeSlides {
                Desc = item.Description, ImageUrl = Core.HimallIO.GetRomoteImagePath(item.ImageUrl), Url = item.Url
            });

            var services = CustomerServiceApplication.GetPlatformCustomerService(true, true);
            //var meiqia = CustomerServiceApplication.GetPlatformCustomerService(true, false).FirstOrDefault(p => p.Tool == Entities.CustomerServiceInfo.ServiceTool.MeiQia);
            //if (meiqia != null)
            //    services.Insert(0, meiqia);

            APPHome appHome = new APPHome();

            appHome.success = true;
            //2017年9月1号 商城首页接口修改(把原广告图片的去掉,只保留商品)
            appHome.TotalProduct = totalProducts;
            appHome.Icon         = icon;
            //appHome.Slide = slides;//轮播图数组
            //appHome.Topic = homeImage;//专题数组
            appHome.Product          = products;
            appHome.CustomerServices = services;
            return(appHome);
        }
Exemple #4
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 }));
        }
        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*/
            )
        {
            var  siteSetingInfo = SiteSettingApplication.SiteSettings;
            bool isShow         = siteSetingInfo.ProductSaleCountOnOff == 1;

            if (string.IsNullOrEmpty(keywords) && vshopId == 0 && cid <= 0 && b_id <= 0 && a_id == "")
            {
                keywords = siteSetingInfo.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 != null)
                {
                    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);
                }
                //补充数据后,重新排序
                Func <IEnumerable <ProductView>, IOrderedEnumerable <ProductView> > orderby     = null;
                Func <IEnumerable <ProductView>, IOrderedEnumerable <ProductView> > orderByDesc = null;
                switch (model.OrderKey)
                {
                case 2:
                    //order.Append(" ORDER BY SaleCount ");
                    orderby     = e => e.OrderBy(p => p.SaleCount + Himall.Core.Helper.TypeHelper.ObjectToInt(p.VirtualSaleCounts));
                    orderByDesc = e => e.OrderByDescending(p => p.SaleCount + Himall.Core.Helper.TypeHelper.ObjectToInt(p.VirtualSaleCounts));
                    break;

                case 3:
                    //order.Append(" ORDER BY SalePrice ");
                    orderby     = e => e.OrderBy(p => p.SalePrice);
                    orderByDesc = e => e.OrderByDescending(p => p.SalePrice);
                    break;

                case 4:
                    //order.Append(" ORDER BY Comments ");
                    orderby     = e => e.OrderBy(p => p.Comments);
                    orderByDesc = e => e.OrderByDescending(p => p.Comments);
                    break;

                default:
                    //order.Append(" ORDER BY Id ");
                    //orderby = e => e.OrderBy(p => p.ProductId);
                    //orderByDesc = e => e.OrderByDescending(p => p.ProductId);
                    //break;
                    //按最新的排序规则作为默认排序【序号越大,在前台展示的商品越靠前,序号一致时,优先销量排前,销量一致时,优先上架时间排前】
                    if (isShow)
                    {
                        orderByDesc = e => e.OrderByDescending(p => p.DisplaySequence).ThenByDescending(p => p.SaleCount + Himall.Core.Helper.TypeHelper.ObjectToInt(p.VirtualSaleCounts)).ThenByDescending(p => p.ProductId);
                    }
                    else
                    {
                        orderByDesc = e => e.OrderByDescending(p => p.DisplaySequence).ThenByDescending(p => p.ProductId);
                    }
                    break;
                }
                if (model.OrderKey > 1)
                {
                    if (model.OrderType)
                    {
                        result.Data = orderby(result.Data).ToList();
                    }
                    else
                    {
                        result.Data = orderByDesc(result.Data).ToList();
                    }
                }
                else
                {
                    result.Data = orderByDesc(result.Data).ToList();
                }
            }
            total = result.Total;

            //补商品状态
            foreach (var item in result.Data)
            {
                var pro = ServiceProvider.Instance <IProductService> .Create.GetProduct(item.ProductId);

                var skus = ProductManagerApplication.GetSKUs(pro.Id);
                if (pro == null || skus == null)
                {
                    continue;
                }
                if (pro.SaleStatus == Entities.ProductInfo.ProductSaleStatus.OnSale && pro.AuditStatus == Entities.ProductInfo.ProductAuditStatus.Audited)
                {
                    item.ShowStatus = 0;
                    if (skus.Sum(d => d.Stock) < 1)
                    {
                        item.ShowStatus = 2;
                    }
                }
                else
                {
                    if (pro.AuditStatus == Entities.ProductInfo.ProductAuditStatus.Audited && pro.SaleStatus == Entities.ProductInfo.ProductSaleStatus.InStock)
                    {
                        item.ShowStatus = 3;
                    }
                    else
                    {
                        item.ShowStatus = 1;
                    }
                }
            }
            #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;
                    item.FightGroupId = isFight.ActiveId;
                }
            }
            #endregion

            return(new
            {
                success = true,
                Product = result.Data,
                total = total,
                keywords = model.Keyword,
                cid = cid,
                b_id = b_id,
                a_id = a_id,
                orderKey = orderKey,
                orderType = orderType,
                isSaleCountOnOff = isShow
            });
        }
Exemple #6
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
            }));
        }