public static object GetOrderDetail(string orderId, string userCode, short type) { if (string.IsNullOrWhiteSpace(orderId)) { throw new MessageException("订单号为空!"); } if (string.IsNullOrWhiteSpace(userCode)) { throw new MessageException("用户编号为空!"); } var query = from a in BaseService <VwOrder> .CurrentRepository.QueryEntity join b in BaseService <IndentOrderList> .CurrentRepository.QueryEntity on a.IndentOrderId equals b.IndentOrderId join c in BaseService <VwProduct> .CurrentRepository.QueryEntity on new { a.CompanyId, b.Barcode } equals new { c.CompanyId, c.Barcode } where a.CompanyId == Sys.SysCommonRules.CompanyId && a.IndentOrderId == orderId select new { a, c.ProductCode, c.Barcode, c.Title, SysPrice = b.SysPrice ?? c.SysPrice, c.SubUnit, b.IndentNum, b.DeliveryNum, b.Subtotal, b.Nature }; var list = query.ToList(); if (!list.Any()) { return(null); } var order = list.Select(o => o.a).FirstOrDefault(); var details = list.Where(o => o.Nature == 0).Select(o => new Detail() { ProductCode = o.ProductCode, Barcode = o.Barcode, Title = o.Title, IndentNum = o.IndentNum, DeliveryNum = o.DeliveryNum, SysPrice = o.SysPrice, SubUnit = o.SubUnit, Subtotal = o.Subtotal, Nature = "" }).ToList(); foreach (var gift in list.Where(o => o.Nature == 1)) { var gt = details.FirstOrDefault(o => o.Barcode == gift.Barcode && o.Nature == "赠品"); if (gt == null) { details.Add(new Detail() { ProductCode = gift.ProductCode, Barcode = gift.Barcode, Title = gift.Title, IndentNum = gift.IndentNum, DeliveryNum = gift.DeliveryNum, SysPrice = gift.SysPrice, SubUnit = gift.SubUnit, Subtotal = gift.Subtotal, Nature = "赠品" }); } else { gt.IndentNum += gift.IndentNum; gt.Subtotal += gift.Subtotal; } } var obj = new { OrderId = order.IndentOrderId, order.StoreTitle, order.RecipientsTitle, order.SupplierTitle, order.OrderTotal, order.ShippingAddress, order.DeliveryDate, StateTitle = GetStateTitle(order.State, type), Details = details }; var user = UserInfoService.Find(o => o.CompanyId == Sys.SysCommonRules.CompanyId && o.UserCode == userCode); if (user == null) { throw new MessageException("用户编码不存在!"); } ReaderService.Add(type, user.UID, new List <int>() { order.Id }); return(obj); }