public DataGridModel <BranchShopFeat> GetBranchShopFeat(DateTime?startDate = null, DateTime?endDate = null, int pageNo = 1, int pageSize = 10) { if (!startDate.HasValue) { startDate = DateTime.Now.Date; } if (!endDate.HasValue) { endDate = DateTime.Now; } else { endDate = endDate.Value.Date.AddDays(1); } CheckShopManageLogin(); var shop = CurrentShop; long shopId = shop.Id; BranchShopFeatsQuery query = new BranchShopFeatsQuery(); query.EndDate = endDate; query.StartDate = startDate; query.ShopId = shopId; query.PageNo = pageNo; query.PageSize = pageSize; var model = OrderAndSaleStatisticsApplication.GetBranchShopFeat(query); DataGridModel <BranchShopFeat> result = new DataGridModel <BranchShopFeat>() { rows = model.Models, total = model.Total }; return(result); }
public QueryPageModel <BranchShopFeat> GetBranchShopFeat(BranchShopFeatsQuery query) { if (query.StartDate > query.EndDate) { throw new HimallException("时间段异常:开始时间大于结束时间!"); } //var orders = Context.OrderInfo.Where(p => p.ShopId == query.ShopId && p.ShopBranchId.HasValue && p.ShopBranchId.Value!=0); var orders = DbFactory.Default.Get <OrderInfo>().Where(p => p.ShopId == query.ShopId && p.ShopBranchId.ExIsNotNull() && p.ShopBranchId != 0 && p.OrderStatus != OrderInfo.OrderOperateStatus.Close); if (query.StartDate.HasValue) { orders.Where(p => p.PayDate >= query.StartDate); } if (query.EndDate.HasValue) { orders.Where(p => p.PayDate < query.EndDate); } orders.GroupBy(a => a.ShopBranchId).Select(b => new { BranchShopId = b.ShopBranchId, ShopId = query.ShopId, SaleAmount = b.ActualPayAmount.ExSum(), Rank = b.ExRowNo() }).OrderByDescending(x => "SaleAmount"); var datas = orders.ToPagedList <BranchShopFeat>(query.PageNo, query.PageSize); //foreach (var t in datas) //{ // index++; // t.Rank += index; //} QueryPageModel <BranchShopFeat> pageModel = new QueryPageModel <BranchShopFeat>() { Models = datas, Total = datas.TotalRecordCount }; return(pageModel); }
/// <summary> /// 店铺下的所有门店销售排行 /// </summary> /// <param name="query"></param> /// <returns></returns> public static QueryPageModel <BranchShopFeat> GetBranchShopFeat(BranchShopFeatsQuery query) { var model = _iOrderAndSaleStatisticsService.GetBranchShopFeat(query); var ids = model.Models.Select(a => a.BranchShopId).ToList(); if (ids != null && ids.Count() > 0) { var branchShop = ShopBranchApplication.GetShopBranchByIds(ids); foreach (var m in model.Models) { var branch = branchShop.Where(a => a.Id == m.BranchShopId).FirstOrDefault(); if (branch != null) { m.BranchShopName = branch.ShopBranchName; } } } return(model); }
public QueryPageModel <BranchShopFeat> GetBranchShopFeat(BranchShopFeatsQuery query) { if (query.StartDate > query.EndDate) { throw new HimallException("时间段异常:开始时间大于结束时间!"); } var orders = Context.OrderInfo.Where(p => p.ShopId == query.ShopId && p.ShopBranchId.HasValue && p.ShopBranchId.Value != 0); orders = orders.Where(p => p.OrderStatus != OrderInfo.OrderOperateStatus.Close); if (query.StartDate.HasValue) { orders = orders.Where(p => p.PayDate >= query.StartDate); } if (query.EndDate.HasValue) { orders = orders.Where(p => p.PayDate <= query.EndDate); } var result = orders.GroupBy(a => a.ShopBranchId).ToList().Select(b => new BranchShopFeat() { BranchShopId = b.Key.Value, ShopId = query.ShopId, SaleAmount = b.Sum(x => (decimal?)x.ActualPayAmount).GetValueOrDefault(), }).OrderByDescending(x => x.SaleAmount).ToList(); var index = 0; foreach (var t in result) { index++; t.Rank += index; } int total = 0; var datas = result.AsQueryable().GetPage(out total, p => p.OrderBy(o => o.Rank), query.PageNo, query.PageSize); QueryPageModel <BranchShopFeat> pageModel = new QueryPageModel <BranchShopFeat>() { Models = datas.ToList(), Total = total }; return(pageModel); }