1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using Ant.Core.SqlServer;
- using Ant.Core.Utils;
- using Ant.Core.WebApi.Model;
- using Central.Control.WebApi.Cache;
- using Central.Control.WebApi.DbEntity;
- using Central.Control.WebApi.EFDbContext;
- using Central.Control.WebApi.Enum;
- using Central.Control.WebApi.Models.Response;
- using Central.Control.WebApi.Service.Interface;
- using Microsoft.Extensions.Caching.Memory;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Web;
- namespace Central.Control.WebApi.Service
- {
- /// <summary>
- ///
- /// </summary>
- public class ProductService: IProductService
- {
- /// <summary>
- ///
- /// </summary>
- public readonly static string ImagePrefix = ConfigurationManager.AppSettings["ImagePrefix"].ToString();
- private readonly ICacheHelper _cacheHelper;
- private readonly IDbContext _dbContent;
- /// <summary>
- ///
- /// </summary>
- /// <param name="dbContent"></param>
- public ProductService(
- ICacheHelper cacheHelper,
- IDbContext dbContent)
- {
- _cacheHelper = cacheHelper;
- _dbContent = dbContent;
- }
- /// <summary>
- /// 商品列表
- /// </summary>
- /// <param name="kw"></param>
- /// <param name="skip"></param>
- /// <param name="limit"></param>
- /// <returns></returns>
- public PagedApiResult<ProductResponseDto> Query(string kw = "", int skip = 0, int limit = 1)
- {
- var query = _dbContent.Set<YW_Product>().Where(p => p.IsDelete == 0 && p.Sale == SaleEnum.On);
- // kw搜索
- query = query.WhereIf(!string.IsNullOrWhiteSpace(kw), p => p.Name.Contains(kw));
- // total
- var total = query.Count();
- // 查询结果
- var queryResult = query.OrderByDescending(p => p.CreateDT).Skip(skip).Take(limit).ToList();
- List<ProductResponseDto> result = new List<ProductResponseDto>();
- queryResult.ForEach(item =>
- {
- var current = SafeClone<YW_Product, ProductResponseDto>.Trans(item);
- // 图片转换
- current.Img = $"{ImagePrefix}{current.Img}";
- result.Add(current);
- });
- return new PagedApiResult<ProductResponseDto>(result, total, skip, limit);
- }
- }
- }
|