Beispiel #1
0
        public BaseApiResponse GoodsList(GoodsListRequest request)
        {
            request.CheckNotNull(nameof(request));
            int pageSize = 10;
            IEnumerable <QueryServices.Dtos.GoodsAlias> goodses = null;

            if (request.Type.Equals("Search"))
            {
                goodses = new SearchEngine().SearchGoods(request.Search, "", null, null);
            }
            if (request.Type.Equals("Category"))
            {
                goodses = _goodsQueryService.CategoryGoodses(request.CategoryId);
            }
            //排序
            if (request.Sort.Equals("销量"))
            {
                goodses = goodses.OrderByDescending(x => x.SellOut);//根据销量
            }
            else if (request.Sort.Equals("新品"))
            {
                goodses = goodses.OrderByDescending(x => x.CreatedOn);//根据发布时间
            }
            else
            {
                goodses = goodses.OrderByDescending(x => x.CreatedOn);
            }
            var total = goodses.Count();

            //分页
            var pageGoodses = goodses.Skip(pageSize * (request.Page - 1)).Take(pageSize);

            return(new GoodsListResponse
            {
                Total = total,
                Goodses = pageGoodses.Select(x => new Goods
                {
                    Id = x.Id,
                    Pics = x.Pics.Split("|", true).Select(img => img.ToOssStyleUrl(OssImageStyles.GoodsMainPic.ToDescription())).ToList(),
                    Name = x.Name,
                    Price = x.Price,
                    OriginalPrice = x.OriginalPrice,
                    Benevolence = x.Benevolence,
                    SellOut = x.SellOut
                }).ToList()
            });
        }
Beispiel #2
0
        public BaseApiResponse CategoryGoods([FromBody] CategoryGoodsRequest request)
        {
            request.CheckNotNull(nameof(request));

            var goodses = _goodsQueryService.CategoryGoodses(request.Id);

            return(new GoodsAlisesResponse
            {
                Goodses = goodses.Select(x => new GoodsAlis
                {
                    Id = x.Id,
                    Name = x.Name,
                    Pic = x.Pics.Split("|", true).Length > 0? x.Pics.Split("|", true)[0] : "",
                    Price = x.Price
                }).ToList()
            });
        }