This commit is contained in:
zpc 2024-09-27 13:28:52 +08:00
parent 313cf55c60
commit 99d23e7f90
13 changed files with 289 additions and 14 deletions

View File

@ -114,7 +114,7 @@ namespace HuanMeng.MiaoYu.Code.Cache.Special
userOrderBy = new Dictionary<string, int>();
}
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;
}
/// <summary>
///
/// </summary>
/// <param name="productType"></param>
/// <param name="userOrderBy"></param>
/// <returns></returns>
public virtual List<MallItemDto> GetMallItemDto(ProductType productType, Dictionary<string, int> userOrderBy)
{
List<MallItemDto> mallItemDtos = new List<MallItemDto>();
if (userOrderBy == null)
{
userOrderBy = new Dictionary<string, int>();
}
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;
}
}
}

View File

@ -236,7 +236,7 @@ public class ChatBLL : MiaoYuBase
}
List<ClaudeChatMessage> mess = new List<ClaudeChatMessage>();
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);
//递归获取聊天记录

View File

@ -23,7 +23,6 @@ namespace HuanMeng.MiaoYu.Code.Mall
/// 获取我的页面产品列表
/// </summary>
/// <returns></returns>
public async Task<BaseResponse<MyAccountInfoDto>> 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);
});

View File

@ -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<MusicSongInfoDto>>(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<int>();
}
if (lList == null)
{
lList = new List<int>();
}
data.ForEach(it =>
{
if (fList.Contains(it.Id))
{
it.IsFavorites = true;
}
if (lList.Contains(it.Id))
{
it.IsLikes = true;
}
});
}
return new BaseResponse<List<MusicSongInfoDto>>(ResonseCode.Success, "", data);
}
@ -331,6 +359,96 @@ namespace HuanMeng.MiaoYu.Code.Music
await Dao.daoDbMiaoYu.context.SaveChangesAsync();
return new BaseResponse<bool>(ResonseCode.Success, "歌曲已取消公开", true);
}
/// <summary>
/// 点赞和取消点赞
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public async Task<BaseResponse<bool>> 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<bool>(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<bool>(ResonseCode.Success, "取消点赞成功", true) { };
}
}
/// <summary>
/// 收藏和取消收藏
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public async Task<BaseResponse<bool>> 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<bool>(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<bool>(ResonseCode.Success, "取消收藏成功", true) { };
}
}
/// <summary>
///
@ -361,10 +479,35 @@ namespace HuanMeng.MiaoYu.Code.Music
SongInfoId = songInfoId,
SpecialId = musicId1,
State = 0,
Title = name
Title = name,
FavoritesCount = 0,
};
return m_Songs;
}
/// <summary>
/// 商城
/// </summary>
/// <returns></returns>
public async Task<BaseResponse<MShopInfoDto>> GetShopInfoList()
{
MShopInfoDto myAccountInfoDto = new MShopInfoDto();
UserInfoBLL user = new UserInfoBLL(Dao, _UserId);
Dictionary<string, int> orderDictionary = new Dictionary<string, int>();
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<MShopInfoDto>(ResonseCode.Success, "", myAccountInfoDto);
}
}
}

View File

@ -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<CreateCharacterInfo> characters = new List<CreateCharacterInfo>();

View File

@ -107,7 +107,7 @@ namespace HuanMeng.MiaoYu.Code.Users
}
/// <summary>
/// 记忆卡
/// 商店
/// </summary>
public Dictionary<int, Dictionary<UserMemoryCardType, List<T_User_MemoryCard>>>? UserMemoryCard { get; set; }
/// <summary>

View File

@ -108,4 +108,9 @@ public partial class M_Songs: MultiTenantEntity
/// 是否用户自定义风格
/// </summary>
public virtual bool? IsUserGenre { get; set; }
/// <summary>
/// 收藏数量
/// </summary>
public virtual int FavoritesCount { get; set; }
}

View File

@ -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("音乐风格");

View File

@ -43,6 +43,11 @@ namespace HuanMeng.MiaoYu.Model.Dto.Music
/// </summary>
public bool IsPublic { get; set; }
/// <summary>
/// 收藏数量
/// </summary>
public virtual int FavoritesCount { get; set; }
/// <summary>
/// 歌曲创建时间
/// </summary>
@ -87,7 +92,7 @@ namespace HuanMeng.MiaoYu.Model.Dto.Music
public string CoverImage { get; set; }
/// <summary>
/// 音乐状态,0生成功1生成中
/// 音乐状态,1生成中1生成功 2 审核中 3审核成功
/// </summary>
public virtual int State { get; set; }
@ -100,5 +105,15 @@ namespace HuanMeng.MiaoYu.Model.Dto.Music
/// 是否用户自定义风格
/// </summary>
public virtual bool? IsUserGenre { get; set; }
/// <summary>
/// 是否点赞
/// </summary>
public bool IsLikes { get; set; }
/// <summary>
/// 是否收藏
/// </summary>
public bool IsFavorites { get; set; }
}
}

View File

@ -27,6 +27,19 @@ namespace HuanMeng.MiaoYu.Model.Dto.Shop
public List<PurchasedItemDto> Purchased { get; set; }
}
/// <summary>
/// 商城页面实体
/// </summary>
public class MShopInfoDto
{
/// <summary>
/// 商城在售
/// </summary>
public List<MallItemDto> ProductList { get; set; }
public List<MallItemDto> VipList { get; set; }
}
/// <summary>
/// 商城在售
/// </summary>

View File

@ -18,6 +18,15 @@ namespace HuanMeng.MiaoYu.Model.EnumModel.Product
/// <summary>
///
/// </summary>
= 1
= 1,
/// <summary>
///
/// </summary>
= 2,
/// <summary>
///
/// </summary>
VIP商城 = 3
}
}

View File

@ -12,7 +12,7 @@ namespace HuanMeng.MiaoYu.Model.EnumModel
public enum UserMemoryCardType
{
/// <summary>
/// 记忆卡
/// 商店
/// </summary>
= 0,
/// <summary>

View File

@ -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);
}
/// <summary>
/// 点赞和取消点赞
/// </summary>
/// <param name="musicReviewRequest"></param>
/// <returns></returns>
[HttpPost]
public async Task<BaseResponse<bool>> MusicSongLike([FromBody] MusicReviewRequest musicReviewRequest)
{
MusicBLL musicBLL = new MusicBLL(ServiceProvider);
return await musicBLL.MusicSongLike(musicReviewRequest.Id);
}
/// <summary>
/// 收藏和取消收藏
/// </summary>
/// <param name="musicReviewRequest"></param>
/// <returns></returns>
[HttpPost]
public async Task<BaseResponse<bool>> MusicSongFavorites([FromBody] MusicReviewRequest musicReviewRequest)
{
MusicBLL musicBLL = new MusicBLL(ServiceProvider);
return await musicBLL.MusicSongFavorites(musicReviewRequest.Id);
}
/// <summary>
/// 商城
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<BaseResponse<MShopInfoDto>> GetShopInfoList()
{
MusicBLL musicBLL = new MusicBLL(ServiceProvider);
return await musicBLL.GetShopInfoList();
}
}
}