李昊 4 anos atrás
pai
commit
476b1be4c7

+ 2 - 1
gx_api/GxPress/Api/GxPress.Api/WebControllers/WebMediaController.cs

@@ -60,7 +60,7 @@ namespace GxPress.Api.WebControllers
         [AllowAnonymous]
         public async Task<BookMediaResult> GetBookMediaResult(int id)
         {
-            var result = await mediaService.GetBookMediaResultAsync(id);
+            var result = await mediaService.GetBookMediaResultAsync(id, _loginContext.AccountId);
             if (_loginContext.AccountId > 0 && result.FreeProportion == 0)
                 result.IsBuy = true;
             else if (_loginContext.AccountId > 0)
@@ -92,6 +92,7 @@ namespace GxPress.Api.WebControllers
         [AllowAnonymous]
         public async Task<string> GetBookMediaContentResultAsync(BookCatalogRequest request)
         {
+            request.UserId = _loginContext.AccountId;
             return await mediaService.GetBookMediaContentResultAsync(request);
         }
         /// <summary>

+ 6 - 1
gx_api/GxPress/Model/GxPress.Request/Media/MediaRequest.cs

@@ -233,6 +233,11 @@ namespace GxPress.Request.Media
         /// 路径
         /// </summary>
         /// <value></value>
-        public string Path{get;set;}
+        public string Path { get; set; }
+        /// <summary>
+        /// 用户ID
+        /// </summary>
+        /// <value></value>
+        public int UserId { get; set; }
     }
 }

+ 18 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/Epub/EpubService.cs

@@ -8,15 +8,21 @@ using VersOne.Epub;
 using System;
 using System.Threading.Tasks;
 using GxPress.Common.Tools;
+using GxPress.Repository.Interface;
+using GxPress.Repository.Interface.Order;
 
 namespace GxPress.Service.Implement.Epub
 {
     public class EpubService : IEpubService
     {
         private readonly IMediaRepository mediaRepository;
-        public EpubService(IMediaRepository mediaRepository)
+        private readonly IUserRepository userRepository;
+        private readonly IOrderRepository orderRepository;
+        public EpubService(IMediaRepository mediaRepository, IUserRepository userRepository, IOrderRepository orderRepository)
         {
             this.mediaRepository = mediaRepository;
+            this.userRepository = userRepository;
+            this.orderRepository = orderRepository;
         }
         /// <summary>
         /// 获取书籍目录
@@ -60,6 +66,17 @@ namespace GxPress.Service.Implement.Epub
                 return string.Empty;
             //获取media
             var media = await mediaRepository.GetAsync(request.MediaId);
+            if (request.UserId > 0)
+            {
+                var user = await userRepository.GetAsync(request.UserId);
+                if (user.IsVip && user.EndTime > DateTime.Now)
+                    media.FreeProportion = 0;
+                else
+                {
+                    if (await orderRepository.GetExistsAsync(request.UserId, request.MediaId))
+                        media.FreeProportion = 0;
+                }
+            }
             var sectionValue = 0;
             if (media.FreeProportion > 0)
             {

+ 21 - 3
gx_api/GxPress/Service/GxPress.Service.Implement/Media/MediaService.cs

@@ -9,6 +9,8 @@ using GxPress.Result.Category;
 using GxPress.Service.Interface.Epub;
 using GxPress.Request.Media;
 using System;
+using GxPress.Repository.Interface;
+using GxPress.Repository.Interface.Order;
 
 namespace GxPress.Service.Implement.Media
 {
@@ -19,13 +21,17 @@ namespace GxPress.Service.Implement.Media
         private readonly IMapper _mapper;
         private readonly IEpubService epubService;
         private readonly IMediaLibraryRepository mediaLibraryRepository;
-        public MediaService(ICategoryRepository categoryRepository, IMediaRepository mediaRepository, IMapper _mapper, IEpubService epubService, IMediaLibraryRepository mediaLibraryRepository)
+        private readonly IUserRepository userRepository;
+        private readonly IOrderRepository orderRepository;
+        public MediaService(ICategoryRepository categoryRepository, IMediaRepository mediaRepository, IMapper _mapper, IEpubService epubService, IMediaLibraryRepository mediaLibraryRepository, IUserRepository userRepository, IOrderRepository orderRepository)
         {
             this.categoryRepository = categoryRepository;
             this.mediaRepository = mediaRepository;
             this._mapper = _mapper;
             this.epubService = epubService;
             this.mediaLibraryRepository = mediaLibraryRepository;
+            this.userRepository = userRepository;
+            this.orderRepository = orderRepository;
         }
         public async Task<bool> InsertAsync(MediaResult result)
         {
@@ -64,8 +70,9 @@ namespace GxPress.Service.Implement.Media
         /// 获取书籍详情
         /// </summary>
         /// <param name="id"></param>
+        /// <param name="userId"></param>
         /// <returns></returns>
-        public async Task<BookMediaResult> GetBookMediaResultAsync(int id)
+        public async Task<BookMediaResult> GetBookMediaResultAsync(int id, int userId)
         {
             var result = await mediaRepository.GetBookMediaResultAsync(id);
             if (result == null)
@@ -79,6 +86,17 @@ namespace GxPress.Service.Implement.Media
             //书籍
             //获取media
             var media = await mediaRepository.GetAsync(id);
+            if (userId > 0)
+            {
+                var user = await userRepository.GetAsync(userId);
+                if (user.IsVip && user.EndTime > DateTime.Now)
+                    media.FreeProportion = 0;
+                else
+                {
+                    if (await orderRepository.GetExistsAsync(userId, id))
+                        media.FreeProportion = 0;
+                }
+            }
             var sectionValue = 0;
             result.BookCatalogResults = epubService.GetCatalog("wwwroot" + mediaLibrary.FileUrl);
             if (media.FreeProportion > 0)
@@ -87,7 +105,7 @@ namespace GxPress.Service.Implement.Media
                 sectionValue = Convert.ToInt32(result.BookCatalogResults.Count * freeProportion);
                 foreach (var item in result.BookCatalogResults)
                 {
-                    if (item.Id <=sectionValue)
+                    if (item.Id <= sectionValue)
                         item.IsRead = true;
                 }
             }

+ 1 - 1
gx_api/GxPress/Service/GxPress.Service.Interface/Media/IMediaService.cs

@@ -13,7 +13,7 @@ namespace GxPress.Service.Interface.Media
         /// </summary>
         /// <param name="id"></param>
         /// <returns></returns>
-        Task<BookMediaResult> GetBookMediaResultAsync(int id);
+        Task<BookMediaResult> GetBookMediaResultAsync(int id, int userId);
 
         /// <summary>
         /// 获取章节内容