void StatisticPayProduct(DateTime statisticStartDate, DateTime statisticEndDate)
        {
            Himall.Entity.Entities entity = new Himall.Entity.Entities();

            //时间段内已支付预约单
            var payOrders = from o in entity.OrderInfo
                            join i in entity.OrderItemInfo on o.Id equals i.OrderId
                            where o.PayDate.HasValue && o.PayDate.Value >= statisticStartDate && o.PayDate.Value < statisticEndDate
                            select new
            {
                OrderId              = o.Id,
                OrderDate            = o.OrderDate,
                ShopId               = o.ShopId,
                ProductId            = i.ProductId,
                ProductName          = i.ProductName,
                TotalAmount          = i.RealTotalPrice,   //实际上是金额
                OrderProductQuantity = i.Quantity,
                UserId               = o.UserId
            };

            var payOrderGroups = payOrders.GroupBy(e => e.ProductId);

            List <ProductVistiInfo> productVisitRange = new List <ProductVistiInfo>();
            var pids             = payOrderGroups.Select(e => e.Key).Distinct();
            var oldProductVisits = entity.ProductVistiInfo.Where(e => e.Date == statisticStartDate && pids.Contains(e.ProductId)).ToList();

            foreach (var g in payOrderGroups)
            {
                ProductVistiInfo productVisit = oldProductVisits.FirstOrDefault(e => e.ProductId == g.Key);
                if (productVisit == null)
                {
                    productVisit = new ProductVistiInfo();
                    productVisitRange.Add(productVisit);
                    //使用量、使用金额在预约单逻辑里有实时处理,如果没有记录则进行统计
                    productVisit.SaleCounts  = g.Sum(e => e.OrderProductQuantity);
                    productVisit.SaleAmounts = g.Sum(e => e.TotalAmount);
                }
                productVisit.Date          = statisticStartDate;
                productVisit.ProductId     = g.Key;
                productVisit.PayUserCounts = g.Select(e => e.UserId).Distinct().Count();
                productVisit.StatisticFlag = true;
                var item = g.FirstOrDefault();
                if (item != null)
                {
                    productVisit.ShopId = item.ShopId;
                }
            }
            //将没有付款记录的统计信息,统一修改为已统计
            var noPayOrdersStatistic = oldProductVisits.Where(e => !pids.Any(p => p == e.ProductId));

            foreach (var v in noPayOrdersStatistic)
            {
                v.StatisticFlag = true;
            }
            entity.ProductVistiInfo.AddRange(productVisitRange);
            entity.SaveChanges();
        }
        public void AutoOrderComment()
        {
            try
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    Himall.Entity.Entities entity = new Himall.Entity.Entities();

                    //获取所有的评分数据
                    var lstOrderComments = (from p in entity.OrderCommentInfo
                                            group p by p.ShopId into g
                                            select new OrderCommentsModel
                    {
                        ShopId = g.Key,
                        AvgDeliveryMark = g.Average(p => p.DeliveryMark),
                        AvgPackMark = g.Average(p => p.PackMark),
                        AvgServiceMark = g.Average(p => p.ServiceMark),
                        CategoryIds = entity.BusinessCategoryInfo.Where(c => c.ShopId == g.Key).Select(c => c.CategoryId).ToList()
                    }
                                            ).ToList();



                    foreach (var item in lstOrderComments)
                    {
                        //获取同行业的店铺
                        List <OrderCommentsModel> peerShops = new List <OrderCommentsModel>();

                        foreach (var cId in item.CategoryIds)
                        {
                            var shops = lstOrderComments.Where(c => c.CategoryIds.Contains(cId)).Select(c => c);
                            if (shops != null && shops.Count() > 0)
                            {
                                peerShops.AddRange(shops);
                            }
                        }
                        var avgPackMarkPeerShops     = peerShops.Count != 0 ? peerShops.Average(c => c.AvgPackMark) : 0d;
                        var avgDeliveryMarkPeerShops = peerShops.Count != 0 ? peerShops.Average(c => c.AvgDeliveryMark) : 0d;
                        var avgServiceMarkPeerShops  = peerShops.Count != 0 ? peerShops.Average(c => c.AvgServiceMark) : 0d;


                        var productAndDescriptionMax = peerShops.Count != 0 ? lstOrderComments.Where(c => peerShops.Where(o => o.ShopId == c.ShopId).Count() > 0).Max(c => c.AvgPackMark) : 0;
                        var productAndDescriptionMin = peerShops.Count != 0 ? lstOrderComments.Where(c => peerShops.Where(o => o.ShopId == c.ShopId).Count() > 0).Min(c => c.AvgPackMark) : 0;
                        var sellerServiceAttitudeMax = peerShops.Count != 0 ? lstOrderComments.Where(c => peerShops.Where(o => o.ShopId == c.ShopId).Count() > 0).Max(c => c.AvgServiceMark) : 0;
                        var sellerServiceAttitudeMin = peerShops.Count != 0 ? lstOrderComments.Where(c => peerShops.Where(o => o.ShopId == c.ShopId).Count() > 0).Min(c => c.AvgServiceMark) : 0;
                        var sellerDeliverySpeedMax   = peerShops.Count != 0 ? lstOrderComments.Where(c => peerShops.Where(o => o.ShopId == c.ShopId).Count() > 0).Max(c => c.AvgDeliveryMark) : 0;
                        var sellerDeliverySpeedMin   = peerShops.Count != 0 ? lstOrderComments.Where(c => peerShops.Where(o => o.ShopId == c.ShopId).Count() > 0).Min(c => c.AvgDeliveryMark) : 0;
                        //宝贝与描述相符
                        Save(entity, new StatisticOrderCommentsInfo
                        {
                            ShopId       = item.ShopId,
                            CommentKey   = StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescription,
                            CommentValue = (decimal)item.AvgPackMark
                        });

                        //宝贝与描述相符 同行比较
                        Save(entity, new StatisticOrderCommentsInfo
                        {
                            ShopId       = item.ShopId,
                            CommentKey   = StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionPeer,
                            CommentValue = (decimal)avgPackMarkPeerShops
                        });

                        //宝贝与描述相符 同行业商家最高得分
                        Save(entity, new StatisticOrderCommentsInfo
                        {
                            ShopId       = item.ShopId,
                            CommentKey   = StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionMax,
                            CommentValue = (decimal)productAndDescriptionMax
                        });

                        //宝贝与描述相符 同行业商家最低得分
                        Save(entity, new StatisticOrderCommentsInfo
                        {
                            ShopId       = item.ShopId,
                            CommentKey   = StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionMin,
                            CommentValue = (decimal)productAndDescriptionMin
                        });

                        //卖家的服务态度
                        Save(entity, new StatisticOrderCommentsInfo
                        {
                            ShopId       = item.ShopId,
                            CommentKey   = StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitude,
                            CommentValue = (decimal)item.AvgServiceMark
                        });
                        //卖家的服务态度  同行业比对
                        Save(entity, new StatisticOrderCommentsInfo
                        {
                            ShopId       = item.ShopId,
                            CommentKey   = StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudePeer,
                            CommentValue = (decimal)avgServiceMarkPeerShops
                        });

                        //卖家服务态度 同行业商家最高得分
                        Save(entity, new StatisticOrderCommentsInfo
                        {
                            ShopId       = item.ShopId,
                            CommentKey   = StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudeMax,
                            CommentValue = (decimal)sellerServiceAttitudeMax
                        });
                        //卖家服务态度 同行业商家最低得分
                        Save(entity, new StatisticOrderCommentsInfo
                        {
                            ShopId       = item.ShopId,
                            CommentKey   = StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudeMin,
                            CommentValue = (decimal)sellerServiceAttitudeMin
                        });

                        //卖家的发货速度
                        Save(entity, new StatisticOrderCommentsInfo
                        {
                            ShopId       = item.ShopId,
                            CommentKey   = StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeed,
                            CommentValue = (decimal)item.AvgDeliveryMark
                        });
                        //卖家的发货速度  同行业比对
                        Save(entity, new StatisticOrderCommentsInfo
                        {
                            ShopId       = item.ShopId,
                            CommentKey   = StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedPeer,
                            CommentValue = (decimal)avgDeliveryMarkPeerShops
                        });
                        //卖家发货速度 同行业商家最高得分
                        Save(entity, new StatisticOrderCommentsInfo
                        {
                            ShopId       = item.ShopId,
                            CommentKey   = StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedMax,
                            CommentValue = (decimal)sellerDeliverySpeedMax
                        });
                        //卖家发货速度 同行业商家最低得分
                        Save(entity, new StatisticOrderCommentsInfo
                        {
                            ShopId       = item.ShopId,
                            CommentKey   = StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedMin,
                            CommentValue = (decimal)sellerDeliverySpeedMin
                        });
                    }



                    int rows = entity.SaveChanges();
                    transaction.Complete();
                    //  Log.Error("没bug:"+rows);
                }
            }
            catch (Exception ex)
            {
                string error = ex.Message;
                //    Log.Error("有bug:" + ex.Message + ":" + ex.StackTrace);
            }
        }