添加游戏收藏
This commit is contained in:
parent
72b2a6bc24
commit
ab179b7835
|
|
@ -1,10 +1,15 @@
|
|||
using CloudGaming.Api.Base;
|
||||
using CloudGaming.Code.Cache;
|
||||
using CloudGaming.Code.DataAccess;
|
||||
using CloudGaming.Code.Game;
|
||||
using CloudGaming.Code.MiddlewareExtend;
|
||||
using CloudGaming.DtoModel.Game;
|
||||
using CloudGaming.GameModel.Db.Db_Game;
|
||||
using CloudGaming.Model.DbSqlServer.Db_User;
|
||||
|
||||
using HuanMeng.DotNetCore.Base;
|
||||
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CloudGaming.Api.Controllers
|
||||
|
|
@ -55,11 +60,11 @@ namespace CloudGaming.Api.Controllers
|
|||
/// <param name="gameId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[RedisCache(2, 2, 0)]
|
||||
public GameInfoDto GetGameInfo([FromQuery] string gameId)
|
||||
//[RedisCache(2, 2, 0)]
|
||||
public async Task<GameInfoDto> GetGameInfo([FromQuery] string gameId)
|
||||
{
|
||||
GameBLL gamebll = new GameBLL(this.ServiceProvider);
|
||||
return gamebll.GetGameInfo(gameId);
|
||||
return await gamebll.GetGameInfo(gameId);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据游戏类型Id 获取游戏列表
|
||||
|
|
@ -87,5 +92,34 @@ namespace CloudGaming.Api.Controllers
|
|||
return gamebll.GameSearch(gameId);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 我的收藏列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<List<GameListDto>> GetGameCollect()
|
||||
{
|
||||
GameBLL gamebll = new GameBLL(this.ServiceProvider);
|
||||
return await gamebll.GetGameCollect();
|
||||
}
|
||||
/// <summary>
|
||||
/// 收藏游戏
|
||||
/// </summary>
|
||||
/// <param name="collectRequest"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<BaseResponse<bool>> GameCollect([FromBody] GameCollectRequest collectRequest)
|
||||
{
|
||||
if (string.IsNullOrEmpty(collectRequest.GameId))
|
||||
{
|
||||
return new BaseResponse<bool>(ResonseCode.Error, "游戏不能未空");
|
||||
}
|
||||
GameBLL gamebll = new GameBLL(this.ServiceProvider);
|
||||
return await gamebll.GameCollect(collectRequest.GameId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -461,5 +461,24 @@ namespace CloudGaming.Code.Account
|
|||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取游戏收藏记录
|
||||
/// </summary>
|
||||
/// <param name="userInfoCache"></param>
|
||||
/// <param name="dao"></param>
|
||||
/// <param name="database"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public static async Task<List<string>> GetUserGameCollect(this UserInfoCache userInfoCache, DAO dao, IDatabase database)
|
||||
{
|
||||
if (userInfoCache.GameCollects == null)
|
||||
{
|
||||
userInfoCache.GameCollects = new List<string>();
|
||||
var favorite = await dao.DaoUser.Context.T_User_GameFavorite.Where(it => it.UserId == userInfoCache.UserId).OrderByDescending(it => it.FavoriteTime).Select(it => it.GameId).ToListAsync();
|
||||
userInfoCache.GameCollects.AddRange(favorite ?? new List<string>());
|
||||
await SaveUserInfoCacheChangesAsync(userInfoCache, database);
|
||||
}
|
||||
return userInfoCache.GameCollects;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
using CloudGaming.Code.Account;
|
||||
using CloudGaming.Code.Cache;
|
||||
using CloudGaming.DtoModel.Game;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
|
@ -67,7 +69,7 @@ namespace CloudGaming.Code.Game
|
|||
/// </summary>
|
||||
/// <param name="gameId"></param>
|
||||
/// <returns></returns>
|
||||
public GameInfoDto GetGameInfo(string gameId)
|
||||
public async Task<GameInfoDto> GetGameInfo(string gameId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(gameId))
|
||||
{
|
||||
|
|
@ -79,6 +81,15 @@ namespace CloudGaming.Code.Game
|
|||
return null;
|
||||
}
|
||||
var gameInfo = Mapper.Map<GameInfoDto>(game);
|
||||
if (_UserId > 0)
|
||||
{
|
||||
//IsCollect
|
||||
var gameIds = await UserInfo.GetUserGameCollect(Dao, RedisCache);
|
||||
if (gameIds.Contains(gameId))
|
||||
{
|
||||
gameInfo.IsCollect = true;
|
||||
}
|
||||
}
|
||||
return gameInfo;
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +139,7 @@ namespace CloudGaming.Code.Game
|
|||
.ToList();
|
||||
|
||||
var gameIntroduceMatches = Cache.GameInfos
|
||||
.Where(it => it.GameIntroduce.Contains(gameName) )
|
||||
.Where(it => it.GameIntroduce.Contains(gameName))
|
||||
.Select(it => new GameListDto(it, ImageResStyle.中等LOGO))
|
||||
.ToList();
|
||||
|
||||
|
|
@ -146,5 +157,82 @@ namespace CloudGaming.Code.Game
|
|||
.ToList();
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 我的收藏
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<GameListDto>> GetGameCollect()
|
||||
{
|
||||
if (_UserId == 0)
|
||||
{
|
||||
return new List<GameListDto>();
|
||||
}
|
||||
var favorite = await Dao.DaoUser.Context.T_User_GameFavorite.Where(it => it.UserId == _UserId).OrderByDescending(it => it.FavoriteTime).ToListAsync();
|
||||
if (favorite == null || favorite.Count == 0)
|
||||
{
|
||||
return new List<GameListDto>();
|
||||
}
|
||||
List<GameListDto> list = new List<GameListDto>();
|
||||
var gameData = Cache.GameEntityCache;
|
||||
favorite.ForEach(it =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(it.GameId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var game = gameData[it.GameId];
|
||||
if (game == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var o = new GameListDto()
|
||||
{
|
||||
GameId = it.GameId,
|
||||
GameName = game.GameName ?? "",
|
||||
GameIconImage = game.ImageIconId
|
||||
};
|
||||
list.Add(o);
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="gameId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BaseResponse<bool>> GameCollect(string gameId)
|
||||
{
|
||||
var favorite = await Dao.DaoUser.Context.T_User_GameFavorite.Where(it => it.UserId == _UserId && it.GameId == gameId).OrderByDescending(it => it.FavoriteTime).FirstOrDefaultAsync();
|
||||
if (favorite != null)
|
||||
{
|
||||
Dao.DaoUser.Context.T_User_GameFavorite.Remove(favorite);
|
||||
await Dao.DaoUser.Context.SaveChangesAsync();
|
||||
var degameIds = await UserInfo.GetUserGameCollect(Dao, RedisCache);
|
||||
degameIds.Remove(gameId);
|
||||
await this.SaveUserInfoCacheChangesAsync();
|
||||
return new BaseResponse<bool>(ResonseCode.Success, "取消收藏成功");
|
||||
}
|
||||
var game = Cache.GameEntityCache[gameId];
|
||||
if (game == null)
|
||||
{
|
||||
throw MessageBox.ErrorShow("收藏的游戏不存在");
|
||||
}
|
||||
favorite = new T_User_GameFavorite()
|
||||
{
|
||||
FavoriteTime = DateTime.Now,
|
||||
GameId = gameId,
|
||||
UserId = _UserId,
|
||||
Desc = ""
|
||||
};
|
||||
|
||||
await Dao.DaoUser.Context.T_User_GameFavorite.AddAsync(favorite);
|
||||
await Dao.DaoUser.Context.SaveChangesAsync();
|
||||
var gameIds = await UserInfo.GetUserGameCollect(Dao, RedisCache);
|
||||
gameIds.Add(gameId);
|
||||
await this.SaveUserInfoCacheChangesAsync();
|
||||
return new BaseResponse<bool>(ResonseCode.Success, "收藏成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using CloudGaming.DtoModel.Account.User.Cache;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
|
@ -33,8 +34,16 @@ namespace CloudGaming.DtoModel.Account.User
|
|||
/// </summary>
|
||||
public Dictionary<string, int> BuyProductCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 七天签到功能
|
||||
/// </summary>
|
||||
public UserSevenDayCache? UserSevenDay { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 收藏的游戏列表
|
||||
/// </summary>
|
||||
public List<string> GameCollects { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudGaming.DtoModel.Game
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏收藏
|
||||
/// </summary>
|
||||
public class GameCollectRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏Id
|
||||
/// </summary>
|
||||
public string GameId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -85,5 +85,10 @@ namespace CloudGaming.DtoModel.Game
|
|||
/// </summary>
|
||||
[Images]
|
||||
public int GameShareUserIcon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏是否收藏
|
||||
/// </summary>
|
||||
public bool IsCollect { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,11 @@ public partial class CloudGamingUserContext : MultiTenantDbContext//DbContext
|
|||
/// </summary>
|
||||
public virtual DbSet<T_User_DiamondList> T_User_DiamondList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 我的游戏收藏
|
||||
/// </summary>
|
||||
public virtual DbSet<T_User_GameFavorite> T_User_GameFavorite { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 意向订单表
|
||||
/// </summary>
|
||||
|
|
@ -279,6 +284,35 @@ public partial class CloudGamingUserContext : MultiTenantDbContext//DbContext
|
|||
}
|
||||
});
|
||||
|
||||
modelBuilder.Entity<T_User_GameFavorite>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PK_T_USER_FAVORITE");
|
||||
|
||||
entity.ToTable(tb => tb.HasComment("我的游戏收藏"));
|
||||
|
||||
entity.HasIndex(e => e.UserId, "UserId");
|
||||
|
||||
entity.Property(e => e.Id).HasComment("主键");
|
||||
entity.Property(e => e.Desc)
|
||||
.HasMaxLength(50)
|
||||
.HasComment("备注")
|
||||
.UseCollation("Chinese_PRC_CI_AS");
|
||||
entity.Property(e => e.FavoriteTime)
|
||||
.HasComment("收藏时间")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.GameId)
|
||||
.HasMaxLength(100)
|
||||
.HasComment("游戏Id")
|
||||
.UseCollation("Chinese_PRC_CI_AS");
|
||||
entity.Property(e => e.TenantId).HasComment("租户");
|
||||
entity.Property(e => e.UserId).HasComment("用户Id");
|
||||
//添加全局筛选器
|
||||
if (this.TenantInfo != null)
|
||||
{
|
||||
entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
|
||||
}
|
||||
});
|
||||
|
||||
modelBuilder.Entity<T_User_IntentOrder>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PK__T_User_I__3214EC07D27A8CE9");
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
|
||||
namespace CloudGaming.Model.DbSqlServer.Db_User;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
|
||||
namespace CloudGaming.Model.DbSqlServer.Db_User;
|
||||
|
||||
/// <summary>
|
||||
/// 我的游戏收藏
|
||||
/// </summary>
|
||||
public partial class T_User_GameFavorite: MultiTenantEntity
|
||||
{
|
||||
public T_User_GameFavorite() { }
|
||||
|
||||
/// <summary>
|
||||
/// 主键
|
||||
/// </summary>
|
||||
public virtual int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户Id
|
||||
/// </summary>
|
||||
public virtual int UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏Id
|
||||
/// </summary>
|
||||
public virtual string GameId { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 收藏时间
|
||||
/// </summary>
|
||||
public virtual DateTime FavoriteTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public virtual string? Desc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属租户
|
||||
/// </summary>
|
||||
public override Guid TenantId { get; set; }
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user