/// <summary> /// 平台交易统计 /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns></returns> public static TradeStatisticModel GetPlatTradeStatistic(DateTime startDate, DateTime endDate) { var platVisit = _StatisticsService.GetPlatVisits(startDate, endDate); Mapper.CreateMap <List <PlatVisitsInfo>, List <TradeStatisticModel> >(); Mapper.CreateMap <PlatVisitsInfo, TradeStatisticModel>().ForMember(dest => dest.VistiCounts, op => op.MapFrom(src => src.VisitCounts)); var model = platVisit.Select(e => new TradeStatisticModel { VistiCounts = e.VisitCounts, Date = e.Date, OrderAmount = e.OrderAmount, OrderCount = e.OrderCount, OrderPayCount = e.OrderPayCount, OrderPayUserCount = e.OrderPayUserCount, OrderProductCount = e.OrderProductCount, OrderUserCount = e.OrderUserCount, SaleAmounts = e.SaleAmounts, SaleCounts = e.SaleCounts, StatisticFlag = e.StatisticFlag }); var tradeModel = new TradeStatisticModel { OrderUserCount = platVisit.Sum(e => e.OrderUserCount), OrderCount = platVisit.Sum(e => e.OrderCount), OrderProductCount = platVisit.Sum(e => e.OrderProductCount), OrderAmount = platVisit.Sum(e => e.OrderAmount), OrderPayUserCount = platVisit.Sum(e => e.OrderPayUserCount), OrderPayCount = platVisit.Sum(e => e.OrderPayCount), SaleCounts = platVisit.Sum(e => e.SaleCounts), SaleAmounts = platVisit.Sum(e => e.SaleAmounts), VistiCounts = platVisit.Sum(e => e.VisitCounts) }; tradeModel.ChartModelPayAmounts = GetChartDataModel <decimal>(startDate, endDate, model, item => item.SaleAmounts); tradeModel.ChartModelPayPieces = GetChartDataModel <long>(startDate, endDate, model, item => item.SaleCounts); tradeModel.ChartModelPayUsers = GetChartDataModel <long>(startDate, endDate, model, item => item.OrderPayUserCount); tradeModel.ChartModelOrderConversionsRates = GetChartDataModel <decimal>(startDate, endDate, model, item => { if (item.VistiCounts > 0) { return(Math.Round(Convert.ToDecimal(item.OrderUserCount) / item.VistiCounts * 100, 2)); } else { return(0); } }); tradeModel.ChartModelPayConversionsRates = GetChartDataModel <decimal>(startDate, endDate, model, item => { if (item.OrderUserCount > 0) { return(Math.Round(Convert.ToDecimal(item.OrderPayUserCount) / item.OrderUserCount * 100, 2)); } else { return(0); } } ); tradeModel.ChartModelTransactionConversionRate = GetChartDataModel <decimal>(startDate, endDate, model, item => { if (item.VistiCounts > 0) { return(Math.Round(Convert.ToDecimal(item.OrderPayUserCount) / item.VistiCounts * 100, 2)); } else { return(0); } } ); return(tradeModel); }
/// <summary> /// 店铺交易统计 /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <param name="shopId"></param> /// <returns></returns> public static TradeStatisticModel GetShopTradeStatistic(DateTime startDate, DateTime endDate, long shopId) { var shopVisit = _StatisticsService.GetShopVisits(startDate, endDate, shopId).ToList(); Mapper.CreateMap <ShopVistiInfo, TradeStatisticModel>(); Mapper.CreateMap <List <ShopVistiInfo>, List <TradeStatisticModel> >(); var model = shopVisit.Select(e => new TradeStatisticModel { VistiCounts = e.VistiCounts, Date = e.Date, OrderAmount = e.OrderAmount, OrderCount = e.OrderCount, OrderPayCount = e.OrderPayCount, OrderPayUserCount = e.OrderPayUserCount, OrderProductCount = e.OrderProductCount, OrderUserCount = e.OrderUserCount, SaleAmounts = e.SaleAmounts, SaleCounts = e.SaleCounts, StatisticFlag = e.StatisticFlag }); var tradeModel = new TradeStatisticModel { OrderUserCount = shopVisit.Sum(e => e.OrderUserCount), OrderCount = shopVisit.Sum(e => e.OrderCount), OrderProductCount = shopVisit.Sum(e => e.OrderProductCount), OrderAmount = shopVisit.Sum(e => e.OrderAmount), OrderPayUserCount = shopVisit.Sum(e => e.OrderPayUserCount), OrderPayCount = shopVisit.Sum(e => e.OrderPayCount), SaleCounts = shopVisit.Sum(e => e.SaleCounts), SaleAmounts = shopVisit.Sum(e => e.SaleAmounts), VistiCounts = shopVisit.Sum(e => e.VistiCounts) }; tradeModel.ChartModelPayAmounts = GetChartDataModel <decimal>(startDate, endDate, model, item => item.SaleAmounts); tradeModel.ChartModelPayPieces = GetChartDataModel <long>(startDate, endDate, model, item => item.SaleCounts); tradeModel.ChartModelPayUsers = GetChartDataModel <long>(startDate, endDate, model, item => item.OrderPayUserCount); tradeModel.ChartModelOrderConversionsRates = GetChartDataModel <decimal>(startDate, endDate, model, item => { if (item.VistiCounts > 0) { return(Math.Round(Convert.ToDecimal(item.OrderUserCount) / item.VistiCounts * 100, 2)); } else { return(0); } }); tradeModel.ChartModelPayConversionsRates = GetChartDataModel <decimal>(startDate, endDate, model, item => { if (item.OrderUserCount > 0) { return(Math.Round(Convert.ToDecimal(item.OrderPayUserCount) / item.OrderUserCount * 100, 2)); } else { return(0); } } ); tradeModel.ChartModelTransactionConversionRate = GetChartDataModel <decimal>(startDate, endDate, model, item => { if (item.VistiCounts > 0) { return(Math.Round(Convert.ToDecimal(item.OrderPayUserCount) / item.VistiCounts * 100, 2)); } else { return(0); } } ); return(tradeModel); }
public List <TradeStatisticModel> GetShopVisitsByRealTime(long shop, long?shopbranchId, DateTime begin, DateTime end) { if (begin > end) { throw new HimallException("时间段异常:开始时间大于结束时间!"); } var models = new List <TradeStatisticModel>(); var model = new TradeStatisticModel() { Date = begin }; //取浏览人数 var db = DbFactory.Default.Get <ShopVistiInfo>().Where(e => e.Date >= begin && e.Date < end); if (shop > 0) { db = db.Where(p => p.ShopId == shop); } if (shopbranchId.HasValue) { db = db.Where(p => p.ShopBranchId == shopbranchId); } model.VisitCounts = db.Sum <long>(d => d.VistiCounts);//浏览人数 #region 单量统计 var orders = DbFactory.Default.Get <OrderInfo>().Where(e => e.OrderDate >= begin && e.OrderDate < end); if (shop > 0) { orders = orders.Where(o => o.ShopId == shop); } if (shopbranchId.HasValue) { orders = orders.Where(o => o.ShopBranchId == shopbranchId); } var orderList = orders.ToList(); model.OrderCount = orderList.Count(); //订单数 model.OrderUserCount = orderList.Select(e => e.UserId).Distinct().Count(); //下单人数 model.OrderAmount = orderList.Sum(e => e.TotalAmount); //下单金额 var orderids = orderList.Select(p => p.Id).ToList <long>(); long orderProductQuantity = DbFactory.Default.Get <OrderItemInfo>() .Where(p => p.OrderId.ExIn(orderids)) .Sum <long>(p => p.Quantity); model.OrderProductCount = orderProductQuantity;//下单件数 #endregion #region 付款量统计 var payOrders = DbFactory.Default.Get <OrderInfo>().Where(e => e.PayDate >= begin && e.PayDate < end); if (shop > 0) { payOrders = payOrders.Where(o => o.ShopId == shop); } if (shopbranchId.HasValue) { payOrders = payOrders.Where(o => o.ShopBranchId == shopbranchId); } var payOrderList = payOrders.ToList(); model.OrderPayUserCount = payOrderList.Select(e => e.UserId).Distinct().Count(); //付款人数 model.OrderPayCount = payOrderList.Count(); //付款订单数 model.SaleAmounts = payOrderList.Sum(e => e.TotalAmount); //付款金额 orderids = payOrderList.Select(p => p.Id).ToList <long>(); orderProductQuantity = DbFactory.Default.Get <OrderItemInfo>().Where(p => p.OrderId.ExIn(orderids)).Sum <long>(p => p.Quantity); model.SaleCounts = orderProductQuantity;//付款下单件数 #endregion #region 退款量统计 var refunds = DbFactory.Default.Get <OrderRefundInfo>().Where(p => p.ManagerConfirmStatus == OrderRefundInfo.OrderRefundConfirmStatus.Confirmed); if (shop > 0) { refunds = refunds.Where(r => r.ShopId == shop); } if (shopbranchId.HasValue) { var ids = DbFactory.Default.Get <OrderInfo>().Where(o => o.ShopBranchId == shopbranchId.Value).Select(i => i.Id).ToList <long>(); refunds = refunds.Where(r => r.OrderId.ExIn(ids)); } refunds = refunds.Where(p => p.ManagerConfirmDate >= begin && p.ManagerConfirmDate <= end); var refundList = refunds.ToList(); model.OrderRefundProductCount = refundList.Sum(p => (long)p.ReturnQuantity); //退款件数 model.OrderRefundAmount = refundList.Sum(p => (decimal)p.Amount); //退款金额 var _refundOrderCount = refundList.Select(p => p.OrderId).Distinct().Count(); model.OrderRefundCount = _refundOrderCount;//退款订单数 #endregion models.Add(model); return(models); }