|
@@ -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;
|
|
|
}
|
|
|
}
|