From 99d23e7f9055d65c8490da2462685da0a7aaf157 Mon Sep 17 00:00:00 2001 From: zpc Date: Fri, 27 Sep 2024 13:28:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9F=B3=E4=B9=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cache/Special/ProductEntityCache.cs | 54 ++++++- .../HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs | 2 +- .../HuanMeng.MiaoYu.Code/Mall/ProductBLL.cs | 3 +- .../HuanMeng.MiaoYu.Code/Music/MusicBLL.cs | 147 +++++++++++++++++- .../HuanMeng.MiaoYu.Code/Users/UserBLL.cs | 4 +- .../HuanMeng.MiaoYu.Code/Users/UserInfoBLL.cs | 2 +- .../DbSqlServer/Db_MiaoYu/M_Songs.cs | 5 + .../DbSqlServer/Db_MiaoYu/MiaoYuContext.cs | 1 + .../Dto/Music/MusicSongInfoDto.cs | 17 +- .../Dto/Shop/ShopInfoDto.cs | 13 ++ .../EnumModel/Product/ProductType.cs | 11 +- .../EnumModel/UserMemoryCardType.cs | 2 +- .../Controllers/MusicController.cs | 42 +++++ 13 files changed, 289 insertions(+), 14 deletions(-) diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Cache/Special/ProductEntityCache.cs b/src/0-core/HuanMeng.MiaoYu.Code/Cache/Special/ProductEntityCache.cs index b17701d..8bfd77a 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Cache/Special/ProductEntityCache.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Cache/Special/ProductEntityCache.cs @@ -114,7 +114,7 @@ namespace HuanMeng.MiaoYu.Code.Cache.Special userOrderBy = new Dictionary(); } var list = this.DataList; - var productCaches = list.Where(it => it.ProductType == (int)ProductType.记忆卡).ToList(); + var productCaches = list.Where(it => it.ProductType == (int)ProductType.商店).ToList(); if (productCaches != null && productCaches.Count > 0) { @@ -136,9 +136,9 @@ namespace HuanMeng.MiaoYu.Code.Cache.Special ProductId = product.ProductId, PriceType = 0, ProductName = product.ProductName, - ProductDesc=product.ProductDesc, + ProductDesc = product.ProductDesc, PropId = product.Id, - PropType = (int)ProductType.记忆卡, + PropType = (int)ProductType.商店, ImgUrl = imgUrl, }; mallItemDtos.Add(t); @@ -146,5 +146,53 @@ namespace HuanMeng.MiaoYu.Code.Cache.Special } return mallItemDtos; } + + /// + /// + /// + /// + /// + /// + public virtual List GetMallItemDto(ProductType productType, Dictionary userOrderBy) + { + List mallItemDtos = new List(); + if (userOrderBy == null) + { + userOrderBy = new Dictionary(); + } + var list = this.DataList; + var productCaches = list.Where(it => it.ProductType == (int)productType).ToList(); + + if (productCaches != null && productCaches.Count > 0) + { + foreach (var product in productCaches) + { + + var imgUrl = product.ProductImg; + var price = product.Price; + if (product.IsFirstCharge && !userOrderBy.ContainsKey(product.ProductId)) + { + imgUrl = product.FirstChargeImg; + + price = product.FirstChargePrice ?? 0; + } + var t = new MallItemDto() + { + + Price = price.ToString(), + ProductId = product.ProductId, + PriceType = 1, + ProductName = product.ProductName, + ProductDesc = product.ProductDesc, + PropId = product.Id, + PropType = (int)productType, + ImgUrl = imgUrl, + }; + mallItemDtos.Add(t); + } + } + return mallItemDtos; + } + } } diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs b/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs index b8a0375..5580f9f 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs @@ -236,7 +236,7 @@ public class ChatBLL : MiaoYuBase } List mess = new List(); int maxToken = 7000; - // var _memoryCardType = userInfoBLL[Model.EnumModel.UserMemoryCardType.记忆卡, charact.Id]; + // var _memoryCardType = userInfoBLL[Model.EnumModel.UserMemoryCardType.商店, charact.Id]; (maxToken, var isMemoryCard, var card) = userInfoBLL.GetMemoryCardMaxToken(charact.Id); //await AddMessage(userChatSession, mess); //递归获取聊天记录 diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Mall/ProductBLL.cs b/src/0-core/HuanMeng.MiaoYu.Code/Mall/ProductBLL.cs index 810723b..f146782 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Mall/ProductBLL.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Mall/ProductBLL.cs @@ -23,7 +23,6 @@ namespace HuanMeng.MiaoYu.Code.Mall /// 获取我的页面产品列表 /// /// - public async Task> GetMyAccountInfoList() { MyAccountInfoDto myAccountInfoDto = new MyAccountInfoDto(); @@ -83,7 +82,7 @@ namespace HuanMeng.MiaoYu.Code.Mall ProductName = it.Name, PropName = it.Name, PriceType = 0, - PropType = (int)ProductType.记忆卡 + PropType = (int)ProductType.商店 }; myAccountInfoDto.Purchased.Add(purchasedItemDto); }); diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Music/MusicBLL.cs b/src/0-core/HuanMeng.MiaoYu.Code/Music/MusicBLL.cs index 8c9357d..fd69547 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Music/MusicBLL.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Music/MusicBLL.cs @@ -19,6 +19,9 @@ using HuanMeng.MiaoYu.Code.Users; using Org.BouncyCastle.Crypto; using HuanMeng.MiaoYu.Model.Dto; using HuanMeng.MiaoYu.Code.DataAccess; +using HuanMeng.MiaoYu.Code.Cache.Special; +using HuanMeng.MiaoYu.Model.Dto.Shop; +using HuanMeng.MiaoYu.Model.EnumModel.Product; namespace HuanMeng.MiaoYu.Code.Music { @@ -99,7 +102,32 @@ namespace HuanMeng.MiaoYu.Code.Music .OrderByDescending(it => it.CreationTimestamp).Take(50) .ToListAsync(); } + var data = Mapper.Map>(list); + if (_UserId > 0) + { + var fList = await Dao.daoDbMiaoYu.context.M_Favorites.Where(it => it.UserId == _UserId).Select(it => it.SongId).ToListAsync(); + var lList = await Dao.daoDbMiaoYu.context.M_Likes.Where(it => it.UserId == _UserId).Select(it => it.SongId).ToListAsync(); + if (fList == null) + { + fList = new List(); + } + if (lList == null) + { + lList = new List(); + } + data.ForEach(it => + { + if (fList.Contains(it.Id)) + { + it.IsFavorites = true; + } + if (lList.Contains(it.Id)) + { + it.IsLikes = true; + } + }); + } return new BaseResponse>(ResonseCode.Success, "", data); } @@ -331,6 +359,96 @@ namespace HuanMeng.MiaoYu.Code.Music await Dao.daoDbMiaoYu.context.SaveChangesAsync(); return new BaseResponse(ResonseCode.Success, "歌曲已取消公开", true); } + /// + /// 点赞和取消点赞 + /// + /// + /// + /// + + public async Task> MusicSongLike(int id) + { + var songs = await Dao.daoDbMiaoYu.context.M_Songs.Where(it => it.Id == id).FirstOrDefaultAsync(); + if (songs == null) + { + throw new Exception("歌曲不存在"); + } + if (songs.State == 0) + { + throw new Exception("请等待歌曲生成成功"); + } + var likes = await Dao.daoDbMiaoYu.context.M_Likes.FirstOrDefaultAsync(it => it.SongId == songs.Id && it.UserId == _UserId); + if (likes == null) + { + likes = new M_Likes() + { + LikedAt = DateTime.Now, + SongId = songs.Id, + UserId = _UserId + }; + Dao.daoDbMiaoYu.context.Add(likes); + songs.LikeCount++; + await Dao.daoDbMiaoYu.context.SaveChangesAsync(); + return new BaseResponse(ResonseCode.Success, "点赞成功", true) { }; + } + else + { + Dao.daoDbMiaoYu.context.M_Likes.Remove(likes); + songs.LikeCount--; + if (songs.LikeCount <= 0) + { + songs.LikeCount = 0; + } + await Dao.daoDbMiaoYu.context.SaveChangesAsync(); + return new BaseResponse(ResonseCode.Success, "取消点赞成功", true) { }; + } + + } + + /// + /// 收藏和取消收藏 + /// + /// + /// + /// + public async Task> MusicSongFavorites(int id) + { + var songs = await Dao.daoDbMiaoYu.context.M_Songs.Where(it => it.Id == id).FirstOrDefaultAsync(); + if (songs == null) + { + throw new Exception("歌曲不存在"); + } + if (songs.State == 0) + { + throw new Exception("请等待歌曲生成成功"); + } + var likes = await Dao.daoDbMiaoYu.context.M_Favorites.FirstOrDefaultAsync(it => it.SongId == songs.Id && it.UserId == _UserId); + if (likes == null) + { + likes = new M_Favorites() + { + FavoritedAt = DateTime.Now, + SongId = songs.Id, + UserId = _UserId, + }; + Dao.daoDbMiaoYu.context.Add(likes); + songs.FavoritesCount++; + await Dao.daoDbMiaoYu.context.SaveChangesAsync(); + return new BaseResponse(ResonseCode.Success, "收藏成功", true) { }; + } + else + { + Dao.daoDbMiaoYu.context.M_Favorites.Remove(likes); + songs.FavoritesCount--; + if (songs.FavoritesCount <= 0) + { + songs.FavoritesCount = 0; + } + await Dao.daoDbMiaoYu.context.SaveChangesAsync(); + return new BaseResponse(ResonseCode.Success, "取消收藏成功", true) { }; + } + + } /// /// @@ -361,10 +479,35 @@ namespace HuanMeng.MiaoYu.Code.Music SongInfoId = songInfoId, SpecialId = musicId1, State = 0, - Title = name - + Title = name, + FavoritesCount = 0, }; return m_Songs; } + + + /// + /// 商城 + /// + /// + public async Task> GetShopInfoList() + { + MShopInfoDto myAccountInfoDto = new MShopInfoDto(); + UserInfoBLL user = new UserInfoBLL(Dao, _UserId); + Dictionary orderDictionary = new Dictionary(); + if (_UserId > 0) + { + orderDictionary = Dao.daoDbMiaoYu.context.T_Order + .Where(it => it.UserId == _UserId) + .GroupBy(it => it.ProductId) + .ToDictionary(it => it.Key, it => it.Count()); + } + ProductEntityCache productEntityCache = new ProductEntityCache(this); + var list = productEntityCache.GetMallItemDto(ProductType.音乐点数商城, orderDictionary); + myAccountInfoDto.ProductList = list; + var list1 = productEntityCache.GetMallItemDto(ProductType.音乐VIP商城, orderDictionary); + myAccountInfoDto.VipList = list1; + return new BaseResponse(ResonseCode.Success, "", myAccountInfoDto); + } } } diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Users/UserBLL.cs b/src/0-core/HuanMeng.MiaoYu.Code/Users/UserBLL.cs index 9861560..2491ec2 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Users/UserBLL.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Users/UserBLL.cs @@ -134,9 +134,9 @@ namespace HuanMeng.MiaoYu.Code.Users //var Currency = user.GetUserCurrencyMoney(UserCurrencyType.语珠, Dao); var RemainingChatCount = userInfoBLL[UserCurrencyType.聊天次数].CurrencyMoney; //var RemainingChatCount = user.GetUserCurrencyMoney(UserCurrencyType.聊天次数, Dao); - //var memoryCard = userInfoBLL[UserCurrencyType.记忆卡].CurrencyMoney; + //var memoryCard = userInfoBLL[UserCurrencyType.商店].CurrencyMoney; var memoryCard = Dao.daoDbMiaoYu.context.T_User_MemoryCard.Where(it => it.UserId == _UserId && it.CharacterId == 0).Count(); - //var memoryCard = user.GetUserCurrencyMoney(UserCurrencyType.记忆卡, Dao); + //var memoryCard = user.GetUserCurrencyMoney(UserCurrencyType.商店, Dao); //获取聊天次数 var hasTalked = Dao.daoDbMiaoYu.context.T_User_Chat.Where(it => it.UserId == _UserId && !it.IsDelete && it.TotalCount > 0).Count(); List characters = new List(); diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Users/UserInfoBLL.cs b/src/0-core/HuanMeng.MiaoYu.Code/Users/UserInfoBLL.cs index c01022d..974595b 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Users/UserInfoBLL.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Users/UserInfoBLL.cs @@ -107,7 +107,7 @@ namespace HuanMeng.MiaoYu.Code.Users } /// - /// 记忆卡 + /// 商店 /// public Dictionary>>? UserMemoryCard { get; set; } /// diff --git a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/M_Songs.cs b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/M_Songs.cs index 7e6101a..bc43fd8 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/M_Songs.cs +++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/M_Songs.cs @@ -108,4 +108,9 @@ public partial class M_Songs: MultiTenantEntity /// 是否用户自定义风格 /// public virtual bool? IsUserGenre { get; set; } + + /// + /// 收藏数量 + /// + public virtual int FavoritesCount { get; set; } } diff --git a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/MiaoYuContext.cs b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/MiaoYuContext.cs index 9539c80..2ae940e 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/MiaoYuContext.cs +++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/MiaoYuContext.cs @@ -435,6 +435,7 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext .HasColumnType("datetime"); entity.Property(e => e.DownloadCount).HasComment("下载次数"); entity.Property(e => e.Duration).HasComment("歌曲时长"); + entity.Property(e => e.FavoritesCount).HasComment("收藏数量"); entity.Property(e => e.Genre) .HasMaxLength(200) .HasComment("音乐风格"); diff --git a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Music/MusicSongInfoDto.cs b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Music/MusicSongInfoDto.cs index 88b527b..55e0f04 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Music/MusicSongInfoDto.cs +++ b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Music/MusicSongInfoDto.cs @@ -43,6 +43,11 @@ namespace HuanMeng.MiaoYu.Model.Dto.Music /// public bool IsPublic { get; set; } + /// + /// 收藏数量 + /// + public virtual int FavoritesCount { get; set; } + /// /// 歌曲创建时间 /// @@ -87,7 +92,7 @@ namespace HuanMeng.MiaoYu.Model.Dto.Music public string CoverImage { get; set; } /// - /// 音乐状态,0生成功,1生成中 + /// 音乐状态,1生成中,1生成功 2 审核中 3审核成功 /// public virtual int State { get; set; } @@ -100,5 +105,15 @@ namespace HuanMeng.MiaoYu.Model.Dto.Music /// 是否用户自定义风格 /// public virtual bool? IsUserGenre { get; set; } + + /// + /// 是否点赞 + /// + public bool IsLikes { get; set; } + + /// + /// 是否收藏 + /// + public bool IsFavorites { get; set; } } } diff --git a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Shop/ShopInfoDto.cs b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Shop/ShopInfoDto.cs index d2af314..464b3d5 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Shop/ShopInfoDto.cs +++ b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Shop/ShopInfoDto.cs @@ -27,6 +27,19 @@ namespace HuanMeng.MiaoYu.Model.Dto.Shop public List Purchased { get; set; } } + /// + /// 商城页面实体 + /// + public class MShopInfoDto + { + /// + /// 商城在售 + /// + public List ProductList { get; set; } + + public List VipList { get; set; } + } + /// /// 商城在售 /// diff --git a/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/Product/ProductType.cs b/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/Product/ProductType.cs index c772e5d..d04f489 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/Product/ProductType.cs +++ b/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/Product/ProductType.cs @@ -18,6 +18,15 @@ namespace HuanMeng.MiaoYu.Model.EnumModel.Product /// /// /// - 记忆卡 = 1 + 商店 = 1, + + /// + /// + /// + 音乐点数商城 = 2, + /// + /// + /// + 音乐VIP商城 = 3 } } diff --git a/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/UserMemoryCardType.cs b/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/UserMemoryCardType.cs index 7eddc04..f71de40 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/UserMemoryCardType.cs +++ b/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/UserMemoryCardType.cs @@ -12,7 +12,7 @@ namespace HuanMeng.MiaoYu.Model.EnumModel public enum UserMemoryCardType { /// - /// 记忆卡 + /// 商店 /// 记忆卡 = 0, /// diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/MusicController.cs b/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/MusicController.cs index 1d524c0..6c1fbdd 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/MusicController.cs +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/MusicController.cs @@ -1,10 +1,13 @@ using HuanMeng.DotNetCore.Base; using HuanMeng.MiaoYu.Code.Cache; +using HuanMeng.MiaoYu.Code.Cache.Special; using HuanMeng.MiaoYu.Code.Music; using HuanMeng.MiaoYu.Code.Users; using HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu; using HuanMeng.MiaoYu.Model.Dto.Character; using HuanMeng.MiaoYu.Model.Dto.Music; +using HuanMeng.MiaoYu.Model.Dto.Shop; +using HuanMeng.MiaoYu.Model.EnumModel.Product; using HuanMeng.MiaoYu.Model.EnumModel.User; using HuanMeng.MiaoYu.WebApi.Base; @@ -140,5 +143,44 @@ namespace HuanMeng.MiaoYu.WebApi.Controllers MusicBLL musicBLL = new MusicBLL(ServiceProvider); return await musicBLL.MusicCancelSongsReview(musicReviewRequest.Id); } + + /// + /// 点赞和取消点赞 + /// + /// + /// + [HttpPost] + + public async Task> MusicSongLike([FromBody] MusicReviewRequest musicReviewRequest) + { + MusicBLL musicBLL = new MusicBLL(ServiceProvider); + return await musicBLL.MusicSongLike(musicReviewRequest.Id); + + } + + /// + /// 收藏和取消收藏 + /// + /// + /// + [HttpPost] + public async Task> MusicSongFavorites([FromBody] MusicReviewRequest musicReviewRequest) + { + MusicBLL musicBLL = new MusicBLL(ServiceProvider); + return await musicBLL.MusicSongFavorites(musicReviewRequest.Id); + + } + + /// + /// 商城 + /// + /// + [HttpGet] + public async Task> GetShopInfoList() + { + MusicBLL musicBLL = new MusicBLL(ServiceProvider); + return await musicBLL.GetShopInfoList(); + } + } }