public async Task <ActionResult> GeneratePackageCode(int packageId) { var isSuccess = false; var msg = string.Empty; var packageDetail = BeautyServicePackageManager.GetBeautyServicePackageDetails(packageId); if (packageDetail != null && packageDetail.Any()) { var packageCodes = BeautyServicePackageManager.GetBeautyServicePackageCodesByPackageId(packageId); if (packageCodes != null && packageCodes.Any()) { msg = "之前已经生成兑换码了"; } else { isSuccess = await BeautyServicePackageManager.GeneratePackageCodes(packageId); if (!isSuccess) { msg = "生成兑换码失败"; } else { isSuccess = true; msg = "兑换码生成成功"; } } } else { msg = "礼包下没有产品"; } return(Json(new { IsSuccess = isSuccess, Msg = msg }, JsonRequestBehavior.AllowGet)); }
public FileResult ExportPackageCodes(int packageId, string name) { var packageCodes = BeautyServicePackageManager.GetBeautyServicePackageCodesByPackageId(packageId); var workbook = new XSSFWorkbook(); var sheet = workbook.CreateSheet(); var row = sheet.CreateRow(0); var cell = null as ICell; var cellNum = 0; #region title row.CreateCell(cellNum++).SetCellValue("兑换码"); row.CreateCell(cellNum++).SetCellValue("开始时间"); row.CreateCell(cellNum++).SetCellValue("结束时间"); cellNum = 0; sheet.SetColumnWidth(cellNum++, 20 * 256); sheet.SetColumnWidth(cellNum++, 20 * 256); sheet.SetColumnWidth(cellNum++, 20 * 256); #endregion #region content if (packageCodes != null && packageCodes.Any()) { var i = 0; foreach (var item in packageCodes) { cellNum = 0; row = sheet.CreateRow(i + 1); row.CreateCell(cellNum++).SetCellValue(item.PackageCode); row.CreateCell(cellNum++).SetCellValue(item.StartTime.ToString("yyyyMMdd")); row.CreateCell(cellNum++).SetCellValue(item.EndTime.ToString("yyyyMMdd")); i++; } } #endregion var ms = new MemoryStream(); workbook.Write(ms); return(File(ms.ToArray(), "application/x-xls", $"{name}_兑换码_{DateTime.Now.ToString("yyyyMMdd HHmmss")}.xlsx")); }