/// <summary> /// 查询数据 /// </summary> /// <returns></returns> public ActionResult List(int?storeId) { GridRequest request = new GridRequest(Request); Expression <Func <Returned, bool> > predicate = FilterHelper.GetExpression <Returned>(request.FilterGroup); var count = 0; var query = _returnedContract.Returneds; //根据店铺权限筛选 var enabledStores = _storeContract.FilterStoreId(AuthorityHelper.OperatorId, _administratorContract, storeId); query = query.Where(r => enabledStores.Contains(r.StoreId.Value)); var list = query.Where <Returned, int>(predicate, request.PageCondition, out count) .Select(m => new { StoreName = m.Store.StoreName, MemberName = m.Member.RealName, ReturnedNumber = m.ReturnedNumber, RetailNumber = m.RetailNumber, EraseMoney = m.EraseMoney, Status = m.Status, Cash = m.Cash, Card = m.SwipCard, ConsumeScore = m.ConsumeScore, AchieveScore = m.AchieveScore, Balance = m.Balance, Coupon = m.Coupon, Id = m.Id, IsDeleted = m.IsDeleted, IsEnabled = m.IsEnabled, Sequence = m.Sequence, UpdatedTime = m.UpdatedTime, CreatedTime = m.CreatedTime, OperatorName = m.Operator.Member.MemberName, }).ToList(); var data = new GridData <object>(list, count, request.RequestInfo); return(Json(data, JsonRequestBehavior.AllowGet)); }
public ActionResult List(int?storeId) { try { var gr = new GridRequest(Request); Expression <Func <Retail, bool> > predict = FilterHelper.GetExpression <Retail>(gr.FilterGroup); var query = _retailContract.Retails.Where(predict) .Include(r => r.Operator.Member) .Include(r => r.Store); //根据店铺权限筛选 var enabledStores = _storeContract.FilterStoreId(AuthorityHelper.OperatorId, _administratorContract, storeId); query = query.Where(r => enabledStores.Contains(r.StoreId.Value)); //获取零售订单 var parentList = query.OrderByDescending(c => c.CreatedTime) .Skip(gr.PageCondition.PageIndex) .Take(gr.PageCondition.PageSize) .Select(x => new { Id = x.Id, Operator = x.Operator.Member.MemberName, OutStorageTime = x.OutStorageDatetime, ProductCount = x.RetailItems.Sum(t => t.RetailCount), ConsumeCount = x.ConsumeCount, RealName = x.Consumer.RealName, ConsumerId = x.ConsumerId, CouponNumber = x.CouponNumber, IsDeleted = x.IsDeleted, IsEnabled = x.IsEnabled, RetailNumber = x.RetailNumber, RetailState = x.RetailState, StoreName = x.Store.StoreName, HasStoreActivity = x.StoreActivityDiscount > 0, HasCoupon = x.CouponConsume > 0 }) .ToList() .Select(x => new { ParentId = "", ProductNumber = "", ProductPic = "", RetailPrice = "", SalesCampaignDiscuss = 10, State = x.RetailState.ToString(), x.ConsumeCount, x.ConsumerId, x.CouponNumber, x.Id, x.IsDeleted, x.IsEnabled, x.Operator, x.OutStorageTime, x.ProductCount, x.RealName, x.RetailNumber, x.StoreName, x.HasStoreActivity, x.HasCoupon }).ToList(); List <object> dataList = new List <object>(); //获取订单对应的零售明细list var parentIds = parentList.Select(p => p.Id).ToList(); var retailItemList = _retailItemContract.RetailItems.Where(item => parentIds.Contains(item.RetailId)) .Include(item => item.Product) .Include(item => item.Product.ProductOriginNumber) .Include(item => item.Product.Color) .Include(item => item.RetailInventorys) .ToList(); var retailItemIds = retailItemList.Select(item => item.Id).ToList(); //构造子项 foreach (var parent in parentList) { dataList.Add(parent); var retailItem = retailItemList.Where(item => item.RetailId == parent.Id).ToList(); foreach (var item in retailItem) { var inventoryList = item.RetailInventorys.Select(r => r.Inventory).ToList(); var child = inventoryList.Select(t => new { ConsumeCount = string.Empty, ConsumerId = "", CouponNumber = "", Id = "c" + item.Id, Operator = "", OutStorageTime = "", ParentId = parent.Id, ProductCount = 1, ProductNumber = t.ProductBarcode, ProductPic = t.Product.ThumbnailPath ?? t.Product.ProductOriginNumber.ThumbnailPath, item.SalesCampaignDiscount, RetailNumber = "", RetailPrice = item.ProductRetailPrice, //订单明细中的零售价 State = string.Empty, t.IsDeleted, t.IsEnabled, t.Product.Color.ColorName, t.Product.Color.IconPath, }); dataList.AddRange(child); } } GridData <object> gd = new GridData <object>(dataList, query.Count(), Request); return(Json(gd)); } catch (Exception ex) { return(Json(new OperationResult(OperationResultType.Error, ex.Message))); } }