public async Task <int> GetPurchaseRecordCountByHourAsync(GetPurchaseRecordsInput input)
        {
            var limitTime = await _memberConfigRepository.GetAll().Where(v => v.Type == DeployTypeEnum.扫码限制配置 && v.Code == DeployCodeEnum.时间限制).Select(v => v.Value).FirstOrDefaultAsync();

            var curTime    = DateTime.Now;
            var beforeHour = curTime.AddHours(-Convert.ToInt32(limitTime));
            var count      = await _purchaserecordRepository.GetAll().Where(v => v.OpenId == input.OpenId &&
                                                                            v.ProductId == input.ProductId &&
                                                                            v.ShopId == input.ShopId &&
                                                                            v.CreationTime <= curTime && v.CreationTime >= beforeHour
                                                                            ).CountAsync();

            return(count);
        }
        public async Task <APIResultDto> ExportShopExcel(GetPurchaseRecordsInput input)
        {
            try
            {
                var exportData = await GetShopDataNoPage(input);

                var result = new APIResultDto();
                result.Code = 0;
                result.Data = SaveShopDataExcel("店铺数据统计.xlsx", exportData);
                return(result);
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("ExportShopExcel errormsg{0} Exception{1}", ex.Message, ex);
                return(new APIResultDto()
                {
                    Code = 901, Msg = "网络忙...请待会儿再试!"
                });
            }
        }
        /// <summary>
        /// 获取PurchaseRecord的分页列表信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <PagedResultDto <PurchaseRecordListDto> > GetPagedPurchaseRecords(GetPurchaseRecordsInput input)
        {
            var query = _purchaserecordRepository.GetAll();
            //TODO:根据传入的参数添加过滤条件
            var purchaserecordCount = await query.CountAsync();

            var purchaserecords = await query
                                  .OrderBy(input.Sorting)
                                  .PageBy(input)
                                  .ToListAsync();

            //var purchaserecordListDtos = ObjectMapper.Map<List <PurchaseRecordListDto>>(purchaserecords);
            var purchaserecordListDtos = purchaserecords.MapTo <List <PurchaseRecordListDto> >();

            return(new PagedResultDto <PurchaseRecordListDto>(
                       purchaserecordCount,
                       purchaserecordListDtos
                       ));
        }
        /// <summary>
        /// 获取指定用户购买记录的分页列表信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <PagedResultDto <PurchaseRecordListDto> > GetPagedPurchaseRecordsByIdAsync(GetPurchaseRecordsInput input)
        {
            var query  = _purchaserecordRepository.GetAll().Where(v => v.OpenId == input.OpenId);
            var result = from p in query
                         select
                         new PurchaseRecordListDto()
            {
                Specification = p.Specification,
                CreationTime  = p.CreationTime,
                Integral      = p.Integral,
                Remark        = p.Remark,
                ShopName      = p.ShopName,
                Quantity      = p.Quantity
            };
            var purchaserecordCount = await result.CountAsync();

            var purchaserecords = await result
                                  .OrderByDescending(v => v.CreationTime)
                                  .PageBy(input)
                                  .ToListAsync();

            var purchaserecordListDtos = purchaserecords.MapTo <List <PurchaseRecordListDto> >();

            return(new PagedResultDto <PurchaseRecordListDto>(
                       purchaserecordCount,
                       purchaserecordListDtos
                       ));
        }
        /// <summary>
        /// Excel获取单个店铺数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private async Task <List <PurchaseRecordListDto> > GetShopDataNoPage(GetPurchaseRecordsInput input)
        {
            var user           = _weChatUserRepository.GetAll();
            var product        = _productRepository.GetAll();
            var purchaseRecord = _purchaserecordRepository.GetAll().Where(v => v.ShopId == input.ShopId);

            var entity = (from pr in purchaseRecord
                          join p in product on pr.ProductId equals p.Id
                          join u in user on pr.OpenId equals u.OpenId
                          group new { u.NickName, u.Phone, pr.Quantity, p.Price, pr.Integral, u.OpenId }
                          by new { u.OpenId, u.NickName, u.Phone } into g
                          select new PurchaseRecordListDto()
            {
                OpenId = g.Key.OpenId,
                Quantity = g.Sum(v => v.Quantity),
                Price = g.Sum(v => v.Price),
                Integral = g.Sum(v => v.Integral),
                Phone = g.Key.Phone,
                WeChatName = g.Key.NickName
            }).WhereIf(!string.IsNullOrEmpty(input.Name), s => s.WeChatName.Contains(input.Name));

            if (input.SortQuantityTotal != null && input.SortQuantityTotal == "ascend")
            {
                var purchaserecords = await entity.OrderByDescending(v => v.Quantity).PageBy(input).ToListAsync();

                //openId列表
                var openIdList = purchaserecords.Select(v => v.OpenId);
                //openId拼接字符串
                string openIds = string.Join(',', openIdList.ToArray());
                var    favouriteSpecification = await _purchaserecordRepository.GetShopFavouriteSpecificationAsync(input.ShopId.ToString(), openIds);

                foreach (var item in purchaserecords)
                {
                    item.FavouriteSpecification = favouriteSpecification.Where(u => u.OpenId == item.OpenId).First().Specification;
                }

                var purchaserecordListDtos = purchaserecords.MapTo <List <PurchaseRecordListDto> >();
                return(purchaserecordListDtos);
            }
            else if (input.SortQuantityTotal != null && input.SortQuantityTotal == "descend")
            {
                var purchaserecords = await entity.OrderBy(v => v.Quantity).PageBy(input).ToListAsync();

                //openId列表
                var openIdList = purchaserecords.Select(v => v.OpenId);
                //openId拼接字符串
                string openIds = string.Join(',', openIdList.ToArray());
                var    favouriteSpecification = await _purchaserecordRepository.GetShopFavouriteSpecificationAsync(input.ShopId.ToString(), openIds);

                foreach (var item in purchaserecords)
                {
                    item.FavouriteSpecification = favouriteSpecification.Where(u => u.OpenId == item.OpenId).First().Specification;
                }

                var purchaserecordListDtos = purchaserecords.MapTo <List <PurchaseRecordListDto> >();
                return(purchaserecordListDtos);
            }
            else if (input.SortPriceTotal != null && input.SortPriceTotal == "ascend")
            {
                var purchaserecords = await entity.OrderByDescending(v => v.Price).PageBy(input).ToListAsync();

                //openId列表
                var openIdList = purchaserecords.Select(v => v.OpenId);
                //openId拼接字符串
                string openIds = string.Join(',', openIdList.ToArray());
                var    favouriteSpecification = await _purchaserecordRepository.GetShopFavouriteSpecificationAsync(input.ShopId.ToString(), openIds);

                foreach (var item in purchaserecords)
                {
                    item.FavouriteSpecification = favouriteSpecification.Where(u => u.OpenId == item.OpenId).First().Specification;
                }

                var purchaserecordListDtos = purchaserecords.MapTo <List <PurchaseRecordListDto> >();
                return(purchaserecordListDtos);
            }
            else if (input.SortPriceTotal != null && input.SortPriceTotal == "descend")
            {
                var purchaserecords = await entity.OrderBy(v => v.Price).PageBy(input).ToListAsync();

                //openId列表
                var openIdList = purchaserecords.Select(v => v.OpenId);
                //openId拼接字符串
                string openIds = string.Join(',', openIdList.ToArray());
                var    favouriteSpecification = await _purchaserecordRepository.GetShopFavouriteSpecificationAsync(input.ShopId.ToString(), openIds);

                foreach (var item in purchaserecords)
                {
                    item.FavouriteSpecification = favouriteSpecification.Where(u => u.OpenId == item.OpenId).First().Specification;
                }

                var purchaserecordListDtos = purchaserecords.MapTo <List <PurchaseRecordListDto> >();
                return(purchaserecordListDtos);
            }
            else if (input.SortIntegralTotal != null && input.SortIntegralTotal == "ascend")
            {
                var purchaserecords = await entity.OrderByDescending(v => v.Integral).PageBy(input).ToListAsync();

                //openId列表
                var openIdList = purchaserecords.Select(v => v.OpenId);
                //openId拼接字符串
                string openIds = string.Join(',', openIdList.ToArray());
                var    favouriteSpecification = await _purchaserecordRepository.GetShopFavouriteSpecificationAsync(input.ShopId.ToString(), openIds);

                foreach (var item in purchaserecords)
                {
                    item.FavouriteSpecification = favouriteSpecification.Where(u => u.OpenId == item.OpenId).First().Specification;
                }
                var purchaserecordListDtos = purchaserecords.MapTo <List <PurchaseRecordListDto> >();
                return(purchaserecordListDtos);
            }
            else if (input.SortIntegralTotal != null && input.SortIntegralTotal == "descend")
            {
                var purchaserecords = await entity.OrderBy(v => v.Integral).PageBy(input).ToListAsync();

                //openId列表
                var openIdList = purchaserecords.Select(v => v.OpenId);
                //openId拼接字符串
                string openIds = string.Join(',', openIdList.ToArray());
                var    favouriteSpecification = await _purchaserecordRepository.GetShopFavouriteSpecificationAsync(input.ShopId.ToString(), openIds);

                foreach (var item in purchaserecords)
                {
                    item.FavouriteSpecification = favouriteSpecification.Where(u => u.OpenId == item.OpenId).First().Specification;
                }

                var purchaserecordListDtos = purchaserecords.MapTo <List <PurchaseRecordListDto> >();
                return(purchaserecordListDtos);
            }
            else
            {
                var purchaserecords = await entity.OrderByDescending(v => v.Price).PageBy(input).ToListAsync();

                //openId列表
                var openIdList = purchaserecords.Select(v => v.OpenId);
                //openId拼接字符串
                string openIds = string.Join(',', openIdList.ToArray());
                var    favouriteSpecification = await _purchaserecordRepository.GetShopFavouriteSpecificationAsync(input.ShopId.ToString(), openIds);

                foreach (var item in purchaserecords)
                {
                    item.FavouriteSpecification = favouriteSpecification.Where(u => u.OpenId == item.OpenId).First().Specification;
                }

                var purchaserecordListDtos = purchaserecords.MapTo <List <PurchaseRecordListDto> >();
                return(purchaserecordListDtos);
            }
        }