public IActionResult Package([FromServices] IMemberScoreService memberScoreService, [FromServices] IArticleService articleService, string id) { if (CoreContextProvider.CurrentMember == null) { return(ErrorPage("用户未登录,请登录!")); } var topic = _ArticleTopicService.GetForm(id); if (topic == null) { return(ErrorPage("该专题不存在,购买失败!")); } var buyResult = memberScoreService .MarketBuy(CoreContextProvider.CurrentMember.UserId, ScoreType.buytopic, id, topic.PackageAmount, topic.CreatorUserId); if (buyResult.Success) { var files = articleService.GetPackageByTopicId(id); //文件 byte[] fileBytes; var contentType = FileHelper.GetContentType("zip"); var resourceType = "zip"; fileBytes = FileDownHelper.DownloadZip(files.ToDictionary(k => k.Code, v => v.Text)); return(File(fileBytes, contentType, $"{topic.Title}.{resourceType}")); } return(ErrorPage("购买后下载文件失败!")); }
public IActionResult Download(string aid) { var downloadResult = _ArticleService.ClientDownLoad(aid); if (downloadResult.Success && downloadResult.Data != null && !downloadResult.Data.Attachment.IsEmpty()) { byte[] fileBytes; var files = downloadResult.Data.Attachment.Split(','); var contentType = FileHelper.GetContentType("zip"); var resourceType = "zip"; if (files.Length == 1) { resourceType = downloadResult.Data.ResourceType ?? FileHelper.GetExtension(FileHelper.MapFilePath(files[0])); contentType = FileHelper.GetContentType(resourceType); fileBytes = FileDownHelper.DownLoad(files[0]); } else { fileBytes = FileDownHelper.DownloadZip(files.ToDictionary(k => k, v => v)); } return(File(fileBytes, contentType, $"{downloadResult.Data.Title}.{resourceType}")); } return(ErrorPage(downloadResult.Message ?? "下载失败!")); }