李昊 il y a 4 ans
Parent
commit
1f572afc92

+ 16 - 5
gx_api/GxPress/Api/GxPress.Api/WebControllers/WebMediaController.cs

@@ -12,7 +12,7 @@ using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.StaticFiles;
 using Microsoft.Net.Http.Headers;
-
+using GxPress.Repository.Interface.Order;
 namespace GxPress.Api.WebControllers
 {
     /// <summary>
@@ -29,14 +29,15 @@ namespace GxPress.Api.WebControllers
         private IHttpContextAccessor _contextAccessor;
         private readonly IMediaLibraryRepository mediaLibraryRepository;
         private HttpContext _context { get { return _contextAccessor.HttpContext; } }
-
-        public WebMediaController(IMediaRepository mediaRepository, ILoginContext _loginContext, IMediaService mediaService, IHttpContextAccessor contextAccessor, IMediaLibraryRepository mediaLibraryRepository)
+        private readonly IOrderRepository orderRepository;
+        public WebMediaController(IMediaRepository mediaRepository, ILoginContext _loginContext, IMediaService mediaService, IHttpContextAccessor contextAccessor, IMediaLibraryRepository mediaLibraryRepository, IOrderRepository orderRepository)
         {
             this.mediaRepository = mediaRepository;
             this._loginContext = _loginContext;
             this.mediaService = mediaService;
             _contextAccessor = contextAccessor;
             this.mediaLibraryRepository = mediaLibraryRepository;
+            this.orderRepository = orderRepository;
         }
         /// <summary>
         /// 详情
@@ -59,7 +60,12 @@ namespace GxPress.Api.WebControllers
         [AllowAnonymous]
         public async Task<BookMediaResult> GetBookMediaResult(int id)
         {
-            return await mediaService.GetBookMediaResultAsync(id);
+            var result = await mediaService.GetBookMediaResultAsync(id);
+            if (_loginContext.AccountId > 0 && result.FreeProportion == 0)
+                result.IsBuy = true;
+            else if (_loginContext.AccountId > 0)
+                result.IsBuy = await orderRepository.GetExistsAsync(_loginContext.AccountId, id);
+            return result;
         }
         /// <summary>
         /// 获取视频详情
@@ -70,7 +76,12 @@ namespace GxPress.Api.WebControllers
         [AllowAnonymous]
         public async Task<VideoMediaResult> GetVideoMediaResultAsync(int id)
         {
-            return await mediaService.GetVideoMediaResultAsync(id);
+            var result = await mediaService.GetVideoMediaResultAsync(id);
+            if (_loginContext.AccountId > 0 && result.FreeProportion == 0)
+                result.IsBuy = true;
+            else if (_loginContext.AccountId > 0)
+                result.IsBuy = await orderRepository.GetExistsAsync(_loginContext.AccountId, id);
+            return result;
         }
         /// <summary>
         /// 获取章节内容

+ 5 - 0
gx_api/GxPress/Model/GxPress.Result/Media/BookMediaResult.cs

@@ -128,6 +128,11 @@ namespace GxPress.Result.Media
         /// </summary>
         /// <value></value>
         public decimal CommentScore { get; set; }
+        /// <summary>
+        /// 是否购买
+        /// </summary>
+        /// <value></value>
+        public bool IsBuy { get; set; }
     }
 
     /// <summary>

+ 6 - 0
gx_api/GxPress/Model/GxPress.Result/Media/VideoMediaResult.cs

@@ -127,5 +127,11 @@ namespace GxPress.Result.Media
         /// </summary>
         /// <value></value>
         public decimal CommentScore { get; set; }
+
+        /// <summary>
+        /// 是否购买
+        /// </summary>
+        /// <value></value>
+        public bool IsBuy { get; set; }
     }
 }

+ 5 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/Order/OrderRepository.cs

@@ -128,5 +128,10 @@ namespace GxPress.Repository.Implement.Order
         {
             return await _repository.UpdateAsync(order);
         }
+
+        public async Task<bool> GetExistsAsync(int userId, int mediaId)
+        {
+            return await _repository.ExistsAsync(Q.Where(nameof(Entity.Order.Order.UserId), userId).Where(nameof(Entity.Order.Order.OrderType), 1).Where(nameof(Entity.Order.Order.MediaId), mediaId));
+        }
     }
 }

+ 1 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/Order/IOrderRepository.cs

@@ -33,5 +33,6 @@ namespace GxPress.Repository.Interface.Order
         /// <returns></returns>
         Task<Entity.Order.Order> GetOrderAsync(string orderNumber);
         Task<bool> UpdateAsync(Entity.Order.Order order);
+        Task<bool> GetExistsAsync(int userId, int mediaId);
     }
 }