diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Music/MusicBLL.cs b/src/0-core/HuanMeng.MiaoYu.Code/Music/MusicBLL.cs index a33e456..1973dd9 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Music/MusicBLL.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Music/MusicBLL.cs @@ -85,14 +85,15 @@ namespace HuanMeng.MiaoYu.Code.Music var Currency = userInfoBLL[UserCurrencyType.音乐点数]?.CurrencyMoney; string sqlString = $@"select isnull(sum(PlayCount),0) PlayCount,isnull(sum(LikeCount),0) LikeCount,isnull(sum(DownloadCount),0) DownloadCount from M_Songs where AuthorId={_UserId}"; var info = Dao.daoDbMiaoYu.context.Database.SqlQueryRaw(sqlString).FirstOrDefault(); - + var songVipInfo = IsMusicVipInfo(); List characters = new List(); return new BaseResponse(ResonseCode.Success, "请求成功", new MusicUserDto { NickName = user.NickName, UserId = user.Id, UserIconUrl = string.IsNullOrEmpty(user?.UserIconUrl) ? "https://cos.shhuanmeng.com/default.png" : user?.UserIconUrl, - Vip = 0, + Vip = songVipInfo.isVip ? 1 : 0, + VipExpirationAt= songVipInfo.expirationAt, DownloadCount = info.DownloadCount, LikeCount = info.LikeCount, PlayCount = info.PlayCount, @@ -208,6 +209,17 @@ namespace HuanMeng.MiaoYu.Code.Music return new BaseResponse>(ResonseCode.Success, "", data); } + private bool IsMusicVip() + { + var songVip = Dao.daoDbMiaoYu.context.M_SongVIP.FirstOrDefault(it => it.UserId == _UserId && it.ExpirationAt > DateTime.Now); + return songVip != null; + } + + private (bool isVip, DateTime? expirationAt) IsMusicVipInfo() + { + var songVip = Dao.daoDbMiaoYu.context.M_SongVIP.FirstOrDefault(it => it.UserId == _UserId && it.ExpirationAt > DateTime.Now); + return (songVip != null, songVip != null ? songVip?.ExpirationAt : null); + } /// /// 创建音乐 @@ -221,12 +233,9 @@ namespace HuanMeng.MiaoYu.Code.Music { throw new Exception("请先登录"); } - var songVip = Dao.daoDbMiaoYu.context.M_SongVIP.FirstOrDefault(it => it.UserId == _UserId && it.ExpirationAt > DateTime.Now); - bool isSongVip = false; - if (songVip != null) - { - isSongVip = true; - } + + bool isSongVip = IsMusicVip(); + UserInfoBLL userInfoBLL = new UserInfoBLL(Dao, _UserId); diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Music/MusicService.cs b/src/0-core/HuanMeng.MiaoYu.Code/Music/MusicService.cs index 37e2bc4..638c5a1 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Music/MusicService.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Music/MusicService.cs @@ -76,19 +76,28 @@ namespace HuanMeng.MiaoYu.Code.Music var httpClient = httpFactory.CreateClient(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); httpClient.DefaultRequestHeaders.Add("authorization", "Bearer hk-ylg6c31000042000fef54b80aec96b39e83b36f6e551440b"); + //31214f23-329f-4b8f-b7e7-0443f17f174b var url = $"https://api.openai-hk.com/suno/feed/{songs.SpecialId}"; var response = await httpClient.GetAsync(url); if (response == null || !response.IsSuccessStatusCode) { - //throw new Exception("创建音乐失败"); - songs.State = -1; - dao.daoDbMiaoYu.context.SaveChanges(); + if (DateTime.Now.Subtract(songs.CreationTimestamp).TotalDays > 1) + { + //throw new Exception("创建音乐失败"); + songs.State = -1; + dao.daoDbMiaoYu.context.SaveChanges(); + } continue; } var responseContent = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseContent)) { - songs.State = -1; + if (DateTime.Now.Subtract(songs.CreationTimestamp).TotalDays > 1) + { + //throw new Exception("创建音乐失败"); + songs.State = -1; + dao.daoDbMiaoYu.context.SaveChanges(); + } dao.daoDbMiaoYu.context.SaveChanges(); continue; } @@ -129,7 +138,7 @@ namespace HuanMeng.MiaoYu.Code.Music } } - Thread.Sleep(1000 * 5); + Thread.Sleep(1000 * 30); } } diff --git a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Music/MusicUserDto.cs b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Music/MusicUserDto.cs index 34b3d93..6084658 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Music/MusicUserDto.cs +++ b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Music/MusicUserDto.cs @@ -36,5 +36,10 @@ namespace HuanMeng.MiaoYu.Model.Dto.Music /// 是否有Vip /// public int Vip { get; set; } + + /// + /// vip到期时间 + /// + public DateTime? VipExpirationAt { get; set; } } }