public async Task <LayerTableJson> ProductList([FromBody] LayuiTableRequest search)
        {
            var response = new LayerTableJson()
            {
            };

            try
            {
                response = await _prodoctManager.LayuiProductListAsync(search, HttpContext.RequestAborted);
            }
            catch (Exception e)
            {
                response.Code = 500;
                response.Msg  = "商品列表查询失败,请重试";
                _logger.LogInformation($"商品列表查询失败异常:{JsonHelper.ToJson(e)}");
            }
            return(response);
        }
Exemple #2
0
        /// <summary>
        /// 兼容Layui表格数据结构得商品列表
        /// </summary>
        /// <param name="search"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <LayerTableJson> LayuiProductListAsync(LayuiTableRequest search, CancellationToken cancellationToken)
        {
            var response = new LayerTableJson()
            {
            };
            var entity = _ProductStore.IQueryableListAsync();

            if (!string.IsNullOrWhiteSpace(search.Name))
            {
                entity = entity.Where(y => y.Title.Contains(search.Name));
            }
            if (!string.IsNullOrWhiteSpace(search.CateId))
            {
                entity = entity.Where(y => y.CateId == search.CateId);
            }
            response.Count = await entity.CountAsync(cancellationToken);

            var list = await entity.Skip(((search.Page ?? 0) - 1) *search.Limit ?? 0).Take(search.Limit ?? 0).ToListAsync(cancellationToken);

            var data = _mapper.Map <List <ProductListResponse> >(list);
            var img  = await _filesStore.IQueryableListAsync().Where(y => data.Select(pro => pro.Id).Contains(y.ProductId) && !y.IsDeleted).ToListAsync(cancellationToken);

            data.ForEach(item =>
            {
                if (img.Where(y => y.ProductId == item.Id).Any())
                {
                    item.Files = img.Select(y => y.Url).ToList();
                }
                else
                {
                    item.Files = new List <string>()
                    {
                    };
                }
            });

            response.Data = data;
            return(response);
        }