Ejemplo n.º 1
0
        /// <summary>
        ///     list
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public PresaleProductItemApiOutput GetPresaleProducts(PresaleProductApiInput input)
        {
            input.PriceStyleId = _presaleProductStyleId;
            var model = Repository <IPresaleProductRepository>().GetPresaleProducts(input, out var count);

            model.ForEach(r => {
                r.ThumbnailUrl = Resolve <IApiService>().ApiImageUrl(r.ThumbnailUrl);
                r.CostPrice    = decimal.Round(r.CostPrice, 2);
            });
            var apiOutput = new PresaleProductItemApiOutput {
                ProductItems = model,
                TotalSize    = count / input.PageSize + 1
            };

            return(apiOutput);
        }
Ejemplo n.º 2
0
        public List <PresaleProductItem> GetPresaleProducts(PresaleProductApiInput input, out long count)
        {
            if (input.PageIndex < 0)
            {
                throw new ArgumentNullException("pageIndex", "pageindex has to be greater than 1");
            }

            if (input.PageSize > 100)
            {
                input.PageSize = 100;
            }

            if (input.StartPrice > input.EndPrice)
            {
                throw new ArgumentNullException("price", "开始区间不大于结束区间");
            }

            //where
            var sqlWhere = string.Empty;

            if (input.PriceStyleId.HasValue)
            {
                sqlWhere += $" AND presale.PriceStyleId ='{input.PriceStyleId}'";
            }

            if (!string.IsNullOrEmpty(input.ProductName))
            {
                sqlWhere += $" AND product.Name Like '%{input.ProductName}%'";
            }

            if (!string.IsNullOrEmpty(input.CategoryId))
            {
                sqlWhere += $" AND product.CategoryId='{input.CategoryId}'";
            }

            if (input.StartPrice > 0 && input.EndPrice > 0)
            {
                sqlWhere += $" AND presale.VirtualPrice>={input.StartPrice} AND presale.VirtualPrice<={input.EndPrice}";
            }
            //status
            var status = (int)GoodsStatus.Online;

            sqlWhere += $" AND product.ProductStatus= {status}  AND product.StoreId>0 AND presale.Status={status}";

            //count
            var sqlCount = $@"SELECT COUNT(presale.Id) [Count]
                            FROM Shop_PresaleProduct AS presale
                            INNER JOIN Shop_Product AS product ON presale.ProductId = product.Id AND presale.PriceStyleId=product.PriceStyleId
                            INNER JOIN Shop_Category AS category ON category.Id = product.CategoryId
                            LEFT JOIN Shop_ProductSku AS sku ON sku.Id = presale.SkuId
                            where 1=1 {sqlWhere}";

            count = RepositoryContext.ExecuteScalar(sqlCount)?.ConvertToLong() ?? 0;

            //datas
            var sql    = $@"SELECT TOP {input.PageSize} * FROM (
                        SELECT  ROW_NUMBER() OVER (ORDER BY presale.CreateTime) AS RowNumber,
                                presale.Id,
                                presale.ProductId,
                                product.Name AS ProductName,
                                product.ThumbnailUrl,
                                sku.PropertyValueDesc AS SkuName,
                                sku.CostPrice,
                                category.Name AS ProductTypeName,
                                presale.VirtualPrice,
                                presale.Stock,
                                presale.QuantitySold,
                                presale.Status,
                                presale.Sort
                        FROM Shop_PresaleProduct AS presale
                        INNER JOIN Shop_Product AS product ON presale.ProductId = product.Id AND presale.PriceStyleId=product.PriceStyleId
                        INNER JOIN Shop_Category AS category ON category.Id = product.CategoryId
                        LEFT JOIN Shop_ProductSku AS sku ON sku.Id = presale.SkuId
                        where 1=1 {sqlWhere}
                    ) as A
                   WHERE RowNumber > {input.PageSize}*({input.PageIndex}-1) ";
            var result = new List <PresaleProductItem>();

            using (var dr = RepositoryContext.ExecuteDataReader(sql)) {
                while (dr.Read())
                {
                    result.Add(ReadProduct(dr));
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public ApiResult <PresaleProductItemApiOutput> PresaleAreaList([FromQuery] PresaleProductApiInput parameter)
        {
            var apiOutput = Resolve <IPresaleProductService>().GetPresaleProducts(parameter);

            return(ApiResult.Success(apiOutput));
        }