/// <summary> /// 获取商品列表 /// </summary> /// <param name="sortby">排序规则</param> /// <param name="topNumber">条数</param> /// <returns></returns> public IEnumerable <PointGift> GetPointGifts(SortBy_PointGift sortby, int topNumber) { Sql sql = GetSql_GetPointGifts(string.Empty, null, true, 0, 0, sortby, topNumber); return(GetTopEntities(topNumber, CachingExpirationType.UsualObjectCollection, () => { return string.Format("GetPointGifts::SortBy_PointGift-{0},TopNumber-{1}", sortby, topNumber); }, () => { return sql; })); }
/// <summary> /// 商品排行 /// </summary> /// <param name="nameKeyword">关键字</param> /// <param name="categoryId">类别id</param> /// <param name="sortBy">排序</param> /// <param name="maxPrice">某个区间的最大价格</param> /// <param name="minPrice">某个区间的最小价格</param> /// <param name="pageSize">每页多少条</param> /// <param name="pageIndex">第几页</param> /// <returns></returns> public ActionResult Rank(string nameKeyword = null, long?categoryId = null, SortBy_PointGift sortBy = SortBy_PointGift.Sales_Desc, int maxPrice = 0, int minPrice = 0, int pageSize = 20, int pageIndex = 1) { //获取用户配置的价格区间 Dictionary <int, int> price = PriceSetting.Get(); ViewData["price"] = price; pageResourceManager.InsertTitlePart("商品排行"); //获取类别 IEnumerable <Category> childCategories = null; if (categoryId.HasValue && categoryId.Value > 0) { var category = categoryService.Get(categoryId.Value); if (category != null) { if (category.ChildCount > 0) { childCategories = category.Children; } else//若是叶子节点,则取同辈分类 { if (category.Parent != null) { childCategories = category.Parent.Children; } } List <Category> allParentCategories = new List <Category>(); //递归获取所有父级类别,若不是叶子节点,则包含其自身 RecursiveGetAllParentCategories(category.ChildCount > 0 ? category : category.Parent, ref allParentCategories); ViewData["allParentCategories"] = allParentCategories; ViewData["currentCategory"] = category; } } if (childCategories == null) { childCategories = categoryService.GetRootCategories(TenantTypeIds.Instance().PointGift()); } ViewData["childCategories"] = childCategories; PagingDataSet <PointGift> gifts = pointMallService.GetGifts(nameKeyword, categoryId, sortBy, maxPrice, minPrice, pageSize, pageIndex); return(View(gifts)); }
/// <summary> /// 获取商品列表 /// </summary> /// <param name="sortby">排序规则</param> /// <param name="topNumber">条数</param> /// <returns></returns> public IEnumerable <PointGift> GetGifts(SortBy_PointGift sortby, int topNumber) { return(giftRepository.GetPointGifts(sortby, topNumber)); }
/// <summary> /// 获取商品列表 /// </summary> /// <param name="nameKeyword">商品名称关键字</param> /// <param name="categoryId">类别ID</param> /// <param name="sortBy">排序规则</param> /// <param name="maxPrice">最大单价</param> /// <param name="minPrice">最小单价</param> /// <param name="pageSize">分页大小</param> /// <param name="pageIndex">页码</param> /// <returns></returns> public PagingDataSet <PointGift> GetGifts(string nameKeyword, long?categoryId, SortBy_PointGift sortBy = SortBy_PointGift.DateCreated_Desc, int maxPrice = 0, int minPrice = 0, int pageSize = 20, int pageIndex = 1) { return(giftRepository.GetPointGifts(nameKeyword, categoryId, sortBy, maxPrice, minPrice, pageSize, pageIndex)); }
/// <summary> /// 商品排行 /// </summary> /// <param name="siteUrls"></param> /// <param name="nameKeyword">商品名称</param> /// <param name="categoryId">商品类别Id</param> /// <param name="sortBy">排序</param> /// <param name="maxPrice">某个区间的最大价格</param> /// <param name="minPrice">某个区间的最低价格</param> /// <returns></returns> public static string Rank(this SiteUrls siteUrls, string nameKeyword = null, long?categoryId = null, SortBy_PointGift sortBy = SortBy_PointGift.Sales_Desc, int maxPrice = 0, int minPrice = 0) { RouteValueDictionary dic = new RouteValueDictionary(); if (!string.IsNullOrEmpty(nameKeyword)) { dic.Add("nameKeyword", nameKeyword); } if (categoryId.HasValue) { dic.Add("categoryId", categoryId); } dic.Add("sortBy", sortBy); dic.Add("maxPrice", maxPrice); dic.Add("minPrice", minPrice); return(CachedUrlHelper.Action("Rank", "ChannelPointMall", PointMallAreaName, dic)); }
/// <summary> /// 获取Sql语句 /// </summary> /// <param name="nameKeyword">商品名称关键字</param> /// <param name="categoryId">类别ID</param> /// <param name="isEnabled">是否上架</param> /// <param name="maxPrice">最大单价</param> /// <param name="minPrice">最小单价</param> /// <param name="sortBy">排序依据</param> /// <param name="topNumber">取出所需条数</param> /// <returns></returns> private Sql GetSql_GetPointGifts(string nameKeyword, long?categoryId, bool?isEnabled, int maxPrice, int minPrice, SortBy_PointGift sortBy, int topNumber) { Sql sql = Sql.Builder; Sql sql_Where = Sql.Builder; Sql sql_Orderby = Sql.Builder; sql.Select("spb_PointGifts.*") .From("spb_PointGifts"); if (!string.IsNullOrEmpty(nameKeyword)) { sql_Where.Where("spb_PointGifts.Name like @0", "%" + StringUtility.StripSQLInjection(nameKeyword) + "%"); } if (categoryId.HasValue) { if (categoryId != 0) { IEnumerable <Category> categories = new CategoryService().GetDescendants(categoryId.Value); List <long> categoryIds = new List <long> { categoryId.Value }; if (categories != null && categories.Count() > 0) { categoryIds.AddRange(categories.Select(n => n.CategoryId)); } sql.LeftJoin(string.Format("(select tn_ItemsInCategories.*,tn_Categories.CategoryName from tn_ItemsInCategories left join tn_Categories on tn_ItemsInCategories.CategoryId=tn_Categories.CategoryId where tn_ItemsInCategories.CategoryId in({0})) tn_ItemsInCategories", string.Join(",", categoryIds))) .On("spb_PointGifts.GiftId=tn_ItemsInCategories.ItemId"); sql_Where.Where("tn_ItemsInCategories.CategoryId in (@categoryIds)", new { categoryIds = categoryIds }); } } if (isEnabled.HasValue) { sql_Where.Where("spb_PointGifts.IsEnabled = @0", isEnabled); } if (maxPrice != 0 && minPrice != 0) { sql_Where.Where("spb_PointGifts.Price>= @0 and spb_PointGifts.Price<=@1", minPrice, maxPrice); } if (minPrice != 0 && maxPrice == 0) { sql_Where.Where("spb_PointGifts.Price>= @0", minPrice); } if (minPrice == 0 && maxPrice != 0) { sql_Where.Where("spb_PointGifts.Price>= 0 and spb_PointGifts.Price<=@0", maxPrice); } CountService countService = new CountService(TenantTypeIds.Instance().PointGift()); string countTableName = countService.GetTableName_Counts(); switch (sortBy) { case SortBy_PointGift.DateCreated_Desc: sql_Orderby.OrderBy("spb_PointGifts.LastModified desc"); break; case SortBy_PointGift.HitTimes_Desc: sql.LeftJoin(countTableName).On("spb_PointGifts.GiftId = " + countTableName + ".ObjectId"); sql_Where.Where(countTableName + ".CountType = @0 or " + countTableName + ".CountType is null", CountTypes.Instance().HitTimes()); sql_Orderby.OrderBy(countTableName + ".StatisticsCount desc"); break; case SortBy_PointGift.Price_Asc: sql_Orderby.OrderBy("spb_PointGifts.Price"); break; case SortBy_PointGift.Price_Desc: sql_Orderby.OrderBy("spb_PointGifts.Price desc"); break; case SortBy_PointGift.Sales_Desc: sql_Orderby.OrderBy("spb_PointGifts.ExchangedCount desc"); break; } sql.Append(sql_Where) .Append(sql_Orderby); return(sql); }
/// <summary> /// 获取商品列表(用于频道) /// </summary> /// <param name="nameKeyword">商品名称关键字</param> /// <param name="categoryId">类别ID</param> /// <param name="sortBy">排序规则</param> /// <param name="maxPrice">最大单价</param> /// <param name="minPrice">最小单价</param> /// <param name="pageSize">分页大小</param> /// <param name="pageIndex">页码</param> public PagingDataSet <PointGift> GetPointGifts(string nameKeyword, long?categoryId, SortBy_PointGift sortBy, int maxPrice, int minPrice, int pageSize, int pageIndex) { Sql sql = GetSql_GetPointGifts(nameKeyword, categoryId, true, maxPrice, minPrice, sortBy, 0); return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.UsualObjectCollection, () => { return string.Format("GetPointGifts::CategoryId-{0};SortBy_PointGift-{1},NameKeyword-{2},MaxPrice-{3},MinPrice-{4}", categoryId, sortBy, nameKeyword, maxPrice, minPrice); }, () => { return sql; })); }