/// <summary> /// 预售订单列表 /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public ActionResult GetPreSaleOrderlist(DateTime?startTime, DateTime?endTime, long?orderId, string mobile, int?status, int pageIndex = 1, int pageSize = 30) { var predicate = PredicateBuilder.True <PreSaleOrder>(); predicate = predicate.And(p => p.DeleteTag == 0 && p.Status != 0); if (startTime.HasValue && endTime.HasValue) { predicate = predicate.And(p => p.CreateTime >= startTime.Value && p.CreateTime <= endTime.Value); } if (orderId.HasValue) { predicate = predicate.And(p => p.OrderId == orderId.Value); } if (!string.IsNullOrEmpty(mobile)) { predicate = predicate.And(p => p.Phone == mobile); } if (status.HasValue) { predicate = predicate.And(p => p.Status == status.Value); } var data = PreSaleOrderService.GetPreSaleOrderCollection(predicate, p => p.OrderId, "desc", pageIndex, pageSize); return(Content(JsonHelper.ToJson(new { items = data, TotalCount = data.TotalCount, PageIndex = data.PageIndex, PageSize = data.PageSize, PageCount = data.PageCount }), "application/javascript")); }
public ActionResult GetExportOrderList(DateTime?startTime, DateTime?endTime, long?orderId, string mobile, int?status) { IWorkbook workbook = new XSSFWorkbook(); ISheet sheet = workbook.CreateSheet("预售订单列表"); var predicate = PredicateBuilder.True <PreSaleOrder>(); predicate = predicate.And(p => p.DeleteTag == 0 && p.Status != 0); if (startTime.HasValue && endTime.HasValue) { predicate = predicate.And(p => p.CreateTime >= startTime.Value && p.CreateTime <= endTime.Value); } if (orderId.HasValue) { predicate = predicate.And(p => p.OrderId == orderId.Value); } if (!string.IsNullOrEmpty(mobile)) { predicate = predicate.And(p => p.Phone == mobile); } if (status.HasValue) { predicate = predicate.And(p => p.Status == status.Value); } var preSaleOrders = PreSaleOrderService.GetPreSaleOrderCollection(predicate, p => p.OrderId, "desc", 1, int.MaxValue); var columnLength = 10; var rowLength = preSaleOrders.Count; //头部 IRow headRow = sheet.CreateRow(0); headRow.CreateCell(0).SetCellValue("预售订单编号"); headRow.CreateCell(1).SetCellValue("手机号"); headRow.CreateCell(2).SetCellValue("产品名称"); headRow.CreateCell(3).SetCellValue("购买数量"); headRow.CreateCell(4).SetCellValue("总价"); headRow.CreateCell(5).SetCellValue("收货地址"); headRow.CreateCell(6).SetCellValue("运单单号"); headRow.CreateCell(7).SetCellValue("订单状态"); headRow.CreateCell(8).SetCellValue("收货人"); headRow.CreateCell(9).SetCellValue("下单时间"); IRow row; ICell cell; for (int i = 0; i < rowLength; i++) { var order = preSaleOrders[i]; row = sheet.CreateRow(i + 1); for (int j = 0; j < columnLength; j++) { cell = row.CreateCell(j); string cellValue = string.Empty; switch (j) { case 0: cellValue = order.OrderId.ToString(); sheet.SetColumnWidth(j, 256 * 20); break; case 1: cellValue = order.Phone; sheet.SetColumnWidth(j, 256 * 15); break; case 2: cellValue = order.PreSaleProduct.Name; sheet.SetColumnWidth(j, 256 * 10); break; case 3: cellValue = order.Count.ToString(); sheet.SetColumnWidth(j, 256 * 20); break; case 4: cellValue = order.TotalMoney.ToString(); sheet.SetColumnWidth(j, 256 * 15); break; case 5: cellValue = order.Area.FullName + order.Address; sheet.SetColumnWidth(j, 256 * 20); break; case 6: cellValue = order.ExpressDelivery; break; case 7: cellValue = order.StatusDesc; break; case 8: cellValue = order.Receiver; break; case 9: cellValue = order.CreateTime.ToString(); break; } cell.SetCellValue(cellValue); } } var fileName = string.Format("预售订单-{0}.xlsx", DateTime.Now.ToString("yyyyMMddhhmmss")); MemoryStream stream = new MemoryStream(); workbook.Write(stream); return(File(stream.ToArray(), "application/vnd.ms-excel", fileName)); }