public async Task <IActionResult> GetRfFoodPageList([FromQuery] RfFoodView model, int pageIndex = 1, int pageSize = 10) { var totalCount = 0; var r = await _cache.GetOrCreate($"RfFoodController_GetRfFoodPageList_{model.GetHashCode()}_{pageIndex}_{pageSize})".ToLower(), async (entry) => { if (model.Category != null && model.Category > 0) { var categoryList = GlobalStaticCache.FoodCategoryList; model.CategoryList = categoryList.Where(t => t.Id == model.Category).Select(t => t.Id).ToList(); var categoryIds = categoryList.Where(t => t.PId == model.Category).Select(t => t.Id).ToList(); if (categoryIds.Any()) { model.CategoryList.AddRange(categoryIds); } foreach (var categoryId in categoryIds) { var categoryCIds = categoryList.Where(t => t.PId == categoryId).Select(t => t.Id).ToList(); if (categoryCIds.Any()) { model.CategoryList.AddRange(categoryCIds); } } } var list = await _server.GetRfFoodPageList(model, ref totalCount, pageIndex, pageSize); entry.SetAbsoluteExpiration(TimeSpan.FromMinutes(1)); return(list); }); return(OkResult(r, totalCount)); }
/// <summary> /// 获取餐饮店列表 /// </summary> /// <param name="search"></param> /// <param name="orderByStr"></param> /// <param name="totalCount"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public Task <List <RfFoodEntity> > FindRfFoodPageList(RfFoodView search, string orderByStr, ref int totalCount, int pageIndex = 1, int pageSize = 10) { return(Db.Queryable <RfFoodEntity>() .Where(t1 => t1.Status == (int)StatusEnum.可用) .WhereIF(!search.Name.IsNullOrWhiteSpace(), t1 => t1.Name.Contains(search.Name)) .WhereIF(search.CategoryList?.Count > 0, t1 => search.CategoryList.Contains(t1.FoodCategoryId)) .OrderBy(orderByStr) .Select("id, name, img_url, description, sort") .ToPageListAsync(pageIndex, pageSize, totalCount)); }
/// <summary> /// 按条件随机返回第一个食物ID /// </summary> /// <param name="search"></param> /// <returns></returns> public async Task <int> FindRfFoodByRand(RfFoodView search) { var model = await Db.Queryable <RfFoodEntity>() .Where(t1 => t1.Status == (int)StatusEnum.可用) .WhereIF(!search.Name.IsNullOrWhiteSpace(), t1 => t1.Name.Contains(search.Name)) .WhereIF(search.CategoryList?.Count > 0, t1 => search.CategoryList.Contains(t1.FoodCategoryId)) .OrderBy("rand()") .Select("SQL_NO_CACHE id") .FirstAsync(); return(model == null ? 0 : model.Id); }
public async Task <IActionResult> GetRfFoodByRand([FromQuery] RfFoodView query) { var id = await _server.GetRfFoodByRand(query); if (id > 0 && !query.OpenId.IsNullOrWhiteSpace()) { var model = await _server.GetRfFood(id) ?? new RfFoodEntity(); await _serverChooseFood.AddRfChooseFood(new RfChooseFoodEntity { FoodId = id, FoodName = model.Name, OpenId = query.OpenId }); } return(OkResult(id)); }
/// <summary> /// 按条件随机返回第一个食物ID /// </summary> /// <param name="search"></param> /// <returns></returns> public Task <int> GetRfFoodByRand(RfFoodView search) { return(_rfFoodRepository.FindRfFoodByRand(search)); }
/// <summary> /// 查询食物信息 /// </summary> /// <param name="search"></param> /// <param name="totalCount"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="orderByStr">默认主键倒序</param> /// <returns></returns> public Task <List <RfFoodEntity> > GetRfFoodPageList(RfFoodView search, ref int totalCount, int pageIndex = 1, int pageSize = 10, string orderByStr = "id") { return(_rfFoodRepository.FindRfFoodPageList(search, orderByStr, ref totalCount, pageIndex, pageSize)); }