diff --git a/src/CloudGaming/Api/CloudGaming.Api/.versionDescribe b/src/CloudGaming/Api/CloudGaming.Api/.versionDescribe index 7334cd5..0af2b22 100644 --- a/src/CloudGaming/Api/CloudGaming.Api/.versionDescribe +++ b/src/CloudGaming/Api/CloudGaming.Api/.versionDescribe @@ -1,4 +1,7 @@ -### 20241119 +### 20241126 +1. 增加玩游戏等接口 + +### 20241119 1. 增加兑换码接口(测试兑换码:test) 2. 增加首页排行榜接口 3. 增加游玩历史接口 diff --git a/src/CloudGaming/Api/CloudGaming.Api/Controllers/PlayGameController.cs b/src/CloudGaming/Api/CloudGaming.Api/Controllers/PlayGameController.cs index 8f17d02..1ca3893 100644 --- a/src/CloudGaming/Api/CloudGaming.Api/Controllers/PlayGameController.cs +++ b/src/CloudGaming/Api/CloudGaming.Api/Controllers/PlayGameController.cs @@ -1,53 +1,144 @@ using CloudGaming.Api.Base; using CloudGaming.Code.Contract; +using CloudGaming.Code.DataAccess; using CloudGaming.Code.Game; +using CloudGaming.DtoModel.Account.User; +using CloudGaming.DtoModel.Game; using CloudGaming.DtoModel.JY; using CloudGaming.DtoModel.PlayGame; +using CloudGaming.Model.DbSqlServer.Db_Phone; using HuanMeng.DotNetCore.Base; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; -using Refit; -namespace CloudGaming.Api.Controllers +namespace CloudGaming.Api.Controllers; + +/// +/// 玩游戏接口 +/// +public class PlayGameController : CloudGamingControllerBase { - - public class PlayGameController : CloudGamingControllerBase + private IJYApi JYApi; + public PlayGameController(IServiceProvider _serviceProvider, IJYApi jYApi) : base(_serviceProvider) { - private IJYApi JYApi; - public PlayGameController(IServiceProvider _serviceProvider, IJYApi jYApi) : base(_serviceProvider) - { - JYApi = jYApi; - } + JYApi = jYApi; + } - /// - /// 获取token接口 - /// - /// - /// - [HttpPost] - public async Task GetTokenAsync([FromBody] RequestBaseModel requestBaseModel) - { + /// + /// 获取token接口 + /// + /// + /// + [HttpPost] + [Authorize] + public async Task> GetTokenAsync([FromBody] RequestBaseModel requestBaseModel) + { - PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi); - return await playGameBLL.GetTokenAsync(requestBaseModel); - } + PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi); + return await playGameBLL.GetTokenAsync(requestBaseModel); + } - /// - /// 开始游戏 - /// - /// - /// - [HttpPost] - public async Task> PlayGameAsync([FromBody] PlayGameRequest playGameRequest) - { - PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi); - return await playGameBLL.PlayGameAsync(playGameRequest); + /// + /// 开始游戏 + /// + /// + /// + [HttpPost] + [Authorize] + public async Task> PlayGameAsync([FromBody] PlayGameRequest playGameRequest) + { + PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi); + return await playGameBLL.PlayGameAsync(playGameRequest); - } + } + + /// + /// 游戏心跳 + /// + /// + /// + [HttpPost] + [Authorize] + public async Task PlayGameHeartbeat([FromBody] GameRequest gameRequest) + { + PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi); + return await playGameBLL.PlayGameHeartbeat(gameRequest.GameId); + + } + + + + /// + /// 游戏排队 + /// + /// + /// + [HttpPost] + [Authorize] + public async Task> PlayGameQueueAsync(GameRequest gameRequest) + { + PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi); + return await playGameBLL.PlayGameQueueAsync(gameRequest); + } + + /// + /// 取消排队 + /// + /// + /// + [HttpPost] + [Authorize] + public async Task> CancelQueueAsync(GameRequest gameRequest) + { + PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi); + return await playGameBLL.CancelQueueAsync(gameRequest); + } + + /// + /// 切换视频等级 + /// + /// + /// + [HttpPost] + [Authorize] + public async Task> DisplayGrade([FromBody] DisplayGradeRequest displayGradeRequest) + { + + PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi); + return await playGameBLL.DisplayGrade(displayGradeRequest.DisplayGrade, displayGradeRequest.GameId); + } + + + /// + /// 获取可重连的会话列表 + /// + /// + /// + [HttpPost] + [Authorize] + public async Task> GetMyScList([FromBody] RequestBaseModel requestBaseModel) + { + PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi); + return await playGameBLL.GetMyScList(requestBaseModel.Sn); + + } + + /// + /// 重连会话 + /// + /// + /// + [HttpPost] + [Authorize] + public async Task> ReconPlayGame([FromBody] ReconPlayGameSettings reconPlayGameSettings) + { + PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi); + return await playGameBLL.ReconPlayGame(reconPlayGameSettings); } } diff --git a/src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrency/DiamondConsumeMoney.cs b/src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrency/DiamondConsumeMoney.cs index 3ae8747..16cdf5c 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrency/DiamondConsumeMoney.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrency/DiamondConsumeMoney.cs @@ -60,16 +60,12 @@ public class DiamondConsumeMoney(DAO dao, int userId, UserCurrencyType userCurre return true; } - /// /// /// - /// - /// - /// /// /// - /// 余额不足 + /// public async Task AddUserCurrencyAsync(decimal money) { var currency = await dao.DaoUser.Context.T_User_Currency.Where(it => it.CurrencyType == (int)userCurrencyType && it.UserId == userId).FirstOrDefaultAsync(); diff --git a/src/CloudGaming/Code/CloudGaming.Code/AppExtend/JwtTokenManageExtension.cs b/src/CloudGaming/Code/CloudGaming.Code/AppExtend/JwtTokenManageExtension.cs index ff1658d..9cc7f79 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/AppExtend/JwtTokenManageExtension.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/AppExtend/JwtTokenManageExtension.cs @@ -11,6 +11,7 @@ using Microsoft.IdentityModel.Tokens; using System.Text.Json; using CloudGaming.Code.ExceptionExtend; using Microsoft.AspNetCore.Http; +using SKIT.FlurlHttpClient.Wechat.TenpayV3.Models; namespace CloudGaming.Code.AppExtend { @@ -129,7 +130,7 @@ namespace CloudGaming.Code.AppExtend context.Fail(new LoginExpiredException(ResponseCode.LoginExpired, "用户在其它设备登录")); return; } - + }, // 处理认证失败的事件 OnAuthenticationFailed = context => @@ -148,15 +149,19 @@ namespace CloudGaming.Code.AppExtend //var result = JsonSerializer.Serialize(new { error = context.AuthenticateFailure.Message }); return context.Response.WriteAsync(str); // 写入响应 } - context.Response.Clear(); // 清空现有响应内容 - context.Response.StatusCode = StatusCodes.Status200OK; // 设置状态码为403 Forbidden - // 返回自定义的错误消息 - var result = new BaseResponse(ResponseCode.JwtError, "", null); - return context.Response.WriteAsync(result.ToString()); + + //context.Response.Clear(); // 清空现有响应内容 + //context.Response.StatusCode = StatusCodes.Status200OK; // 设置状态码为403 Forbidden + + //// 返回自定义的错误消息 + //var result = new BaseResponse(ResponseCode.JwtError, "", null); + //return context.Response.WriteAsync(result.ToString()); + return Task.CompletedTask; }, // 在认证失败并被 Challenge 时触发该事件 OnChallenge = context => { + if (context.AuthenticateFailure is LoginExpiredException loginExpired) { context.HandleResponse(); // 确保不再执行默认的挑战响应 @@ -168,6 +173,10 @@ namespace CloudGaming.Code.AppExtend //var result = JsonSerializer.Serialize(new { error = context.AuthenticateFailure.Message }); return context.Response.WriteAsync(str); // 写入响应 } + else + { + context.Response.Clear(); + } // 构建自定义的 JSON 响应 var result = new BaseResponse(ResponseCode.UserNotLogin, "用户未登录", null); // 如果已经有错误消息,则根据错误原因返回自定义状态码 @@ -176,7 +185,7 @@ namespace CloudGaming.Code.AppExtend result.Message = context.AuthenticateFailure.Message; } context.HandleResponse(); // 确保不再执行默认的挑战响应 - context.Response.Clear(); // 清空现有响应内容 + // 清空现有响应内容 context.Response.StatusCode = StatusCodes.Status200OK; // 设置状态码为403 Forbidden context.Response.ContentType = "application/json"; return context.Response.WriteAsync(result.ToString()); // 写入响应 diff --git a/src/CloudGaming/Code/CloudGaming.Code/Game/GameBLL.cs b/src/CloudGaming/Code/CloudGaming.Code/Game/GameBLL.cs index e21458f..50119e3 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Game/GameBLL.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Game/GameBLL.cs @@ -273,7 +273,7 @@ namespace CloudGaming.Code.Game return new List(); } List gameHistoryListDtos = new List(); - var list = await Dao.DaoPhone.Context.T_User_GameList.Where(it => it.UserId == _UserId).OrderByDescending(it => it.UpdateTime).ToListAsync(); + var list = await Dao.DaoPhone.Context.T_User_PlayGameTime.Where(it => it.UserId == _UserId).OrderByDescending(it => it.UpdateTime).ToListAsync(); var gameList = Cache.GameEntityCache; list?.ForEach(it => { @@ -300,7 +300,7 @@ namespace CloudGaming.Code.Game GamePlayTimeInfoDto gamePlayTimeInfoDto = new GamePlayTimeInfoDto(); List gamePlayTimeDtos = new List(); //游玩记录 - var list = await Dao.DaoPhone.Context.T_User_GameList.Where(it => it.GameId == gameId).OrderByDescending(it => it.PlayTime).Take(50).ToListAsync(); + var list = await Dao.DaoPhone.Context.T_User_PlayGameTime.Where(it => it.GameId == gameId).OrderByDescending(it => it.PlayTime).Take(50).ToListAsync(); #region 排行榜数据 var topList = list.Take(10).ToList(); var userIds = topList.Select(it => it.UserId).ToList(); @@ -333,7 +333,7 @@ namespace CloudGaming.Code.Game if (_UserId > 0) { //查找当前用户游玩记录 - var userGame = await Dao.DaoPhone.Context.T_User_GameList.Where(it => it.GameId == gameId && it.UserId == _UserId).FirstOrDefaultAsync(); + var userGame = await Dao.DaoPhone.Context.T_User_PlayGameTime.Where(it => it.GameId == gameId && it.UserId == _UserId).FirstOrDefaultAsync(); if (userGame != null) { //计算用户排名,看看是否进入前50名 diff --git a/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameBLL.cs b/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameBLL.cs index 461d801..ee34721 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameBLL.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameBLL.cs @@ -29,515 +29,494 @@ using System.Text.Json; using System.Threading.Tasks; -namespace CloudGaming.Code.Game +namespace CloudGaming.Code.Game; + +/// +/// +/// +public class PlayGameBLL : CloudGamingBase { + private IJYApi JYApi { get; set; } + public PlayGameBLL(IServiceProvider serviceProvider, IJYApi jYApi) : base(serviceProvider) + { + JYApi = jYApi; + } + /// /// /// - public class PlayGameBLL : CloudGamingBase + /// + /// + public async Task> GetTokenAsync(RequestBaseModel requestBaseModel) { - private IJYApi JYApi { get; set; } - public PlayGameBLL(IServiceProvider serviceProvider, IJYApi jYApi) : base(serviceProvider) + if (_UserId == 0) { - JYApi = jYApi; + throw MessageBox.ErrorShow("请先登录"); + } + if (string.IsNullOrEmpty(requestBaseModel.Sn)) + { + throw MessageBox.ErrorShow("设备号不能为空"); + } + //requestBaseModel.Sn = Guid.NewGuid().ToString(); + JYRequestParameter requestParameter = new JYRequestParameter(requestBaseModel.Sn, _UserId); + var data = await JYApi.GetToken(requestParameter); + //Console.WriteLine(jyResponseData.TotalMilliseconds); + if (data.IsSuccess) + { + return new BaseResponse(ResponseCode.Success, "", data?.Data ?? new GetTokenModel()); + } + throw data.ToMessageBox(); + } + + /// + /// 启动游戏方法 + /// + /// 启动游戏的请求参数 + /// 包含操作结果的响应对象 + public async Task> PlayGameAsync(PlayGameRequest playGameRequest) + { + // 检查用户是否已登录 + if (_UserId == 0) + { + throw MessageBox.ErrorShow("请先登录"); } - /// - /// - /// - /// - /// - public async Task GetTokenAsync(RequestBaseModel requestBaseModel) + // 检查游戏是否存在 + var gameCache = Cache.GameEntityCache; + var gameInfo = gameCache[playGameRequest.GameId]; + if (gameInfo == null) { - if (_UserId == 0) - { - throw MessageBox.ErrorShow("请先登录"); - } - if (string.IsNullOrEmpty(requestBaseModel.Sn)) - { - throw MessageBox.ErrorShow("设备号不能为空"); - } - //requestBaseModel.Sn = Guid.NewGuid().ToString(); - JYRequestParameter requestParameter = new JYRequestParameter(requestBaseModel.Sn, _UserId); - var data = await JYApi.GetToken(requestParameter); - //Console.WriteLine(data.TotalMilliseconds); - if (data.IsSuccess) - { - return data?.Data?.Token ?? ""; - } - throw data.ToMessageBox(); + throw MessageBox.ErrorShow("游戏不存在"); } - /// - /// 启动游戏方法 - /// - /// 启动游戏的请求参数 - /// 包含操作结果的响应对象 - public async Task> PlayGameAsync(PlayGameRequest playGameRequest) + // 检查用户钻石是否足够 + if (UserInfo.Diamond <= 0) { - // 检查用户是否已登录 - if (_UserId == 0) - { - throw MessageBox.ErrorShow("请先登录"); - } - - // 检查游戏是否存在 - var gameCache = Cache.GameEntityCache; - var gameInfo = gameCache[playGameRequest.GameId]; - if (gameInfo == null) - { - throw MessageBox.ErrorShow("游戏不存在"); - } - - // 检查用户钻石是否足够 - if (UserInfo.Diamond <= 0) - { - throw MessageBox.Show(ResponseCode.NotMoney, "钻石不足"); - } - - // 获取用户和游戏信息 - var userInfo = UserInfo; - PlayGameUserInfo gameInfoCache = await PlayGameExtend.GetPlayGameUserInfoCacheAsync(this, userInfo, gameInfo); - - // 检查游戏状态 - if (gameInfoCache != null) - { - switch (gameInfoCache.GameStatus) - { - case PlayGameStatus.游戏中: - case PlayGameStatus.开始游戏: - throw MessageBox.Show(ResponseCode.Error, "已在游戏中"); - - case PlayGameStatus.排队中: - throw MessageBox.Show(ResponseCode.Error, "用户正在排队中"); - } - } - - // 配置启动游戏设置 - var playGameSettings = new PlayGameSettings(playGameRequest.Sn, _UserId) - { - GameKey = gameInfo.GameCloudId ?? playGameRequest.GameId, - QueueGrade = UserInfo.IsPay ? 5 : 1, - DisplayGrade = 1, - HangUpTimer = 300, // 挂机时间 5 分钟 - ModelName = playGameRequest.ModelName, - StartResolution = "1080P", - }; - playGameRequest.Cpu = playGameRequest.Cpu; - - // 调用游戏启动接口 - var data = await JYApi.PlayGame(playGameSettings); - - //T_User_PlayGmaeLog playGameLog = await AddPlayGmaeLog(gameInfoCache, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 用户尝试启动游戏;", data.ResponseStr, data.ResponseContent); - - var response = new BaseResponse(); - // 用户进入排队 - if (data.IsLineUp) - { - var gameResponse = JsonConvert.DeserializeObject>(data.ResponseContent); - - gameInfoCache?.PlayQueueStart(gameResponse?.Data?.PlayQueueId ?? 0, gameResponse?.Data?.QueuePos ?? 0, playGameSettings.QueueGrade); - //playGameLog.DescribeContent += "用户进入排队状态;"; - response = new BaseResponse(ResponseCode.StartQueue, "开始排队", data.Data); - } - else if (data.IsSuccess) - { - // 游戏启动成功 - var gameResponse = JsonConvert.DeserializeObject>(data.ResponseContent); - // 创建游戏记录和日志 - var userGameList = new T_User_GameList - { - Channel = AppRequestInfo.Channel, - CreateTime = DateTime.Now, - GameId = playGameRequest.GameId, - Status = (int)PlayGameStatus.开始游戏, - UpdateTime = DateTime.Now, - UserId = _UserId - }; - var userGameLog = new T_User_GameLog - { - Cpu = playGameRequest.Cpu, - CreateTime = DateTime.Now, - DisplayGrade = playGameSettings.DisplayGrade, - GameId = playGameRequest.GameId, - Gamekey = gameInfo.GameCloudId, - IP = HttpContextAccessor.HttpContext.GetClientIpAddress(), - ModelName = playGameRequest.ModelName, - QueueGrade = playGameSettings.QueueGrade, - ScId = (gameResponse?.Data?.ScId ?? 0).ToString(), - Status = (int)PlayGameStatus.开始游戏, - UpdateTime = DateTime.Now, - UserId = _UserId, - UserKey = gameResponse?.Data?.UserKey ?? "", - SessionId = gameInfoCache?.SessionId - }; - - //playGameLog.DescribeContent += "游戏启动成功;"; - - // 保存数据 - await Dao.DaoPhone.Context.T_User_GameLog.AddAsync(userGameLog); - await Dao.DaoPhone.Context.T_User_GameList.AddAsync(userGameList); - await Dao.DaoPhone.Context.SaveChangesAsync(); - gameInfoCache?.PlayGameStart(gameResponse?.Data?.ScId ?? 0, userGameList.Id, playGameSettings.DisplayGrade); - response = new BaseResponse(ResponseCode.Success, "", data.Data); - } - else // 游戏启动失败 - { - gameInfoCache?.PlayGameError(); - //playGameLog.DescribeContent += "游戏启动失败;"; - await Dao.DaoPhone.Context.SaveChangesAsync(); - response = new BaseResponse(ResponseCode.Error, data.Msg, data.Data); - } - - - await Dao.DaoPhone.Context.SaveChangesAsync(); - - // 保存游戏缓存状态 - await gameInfoCache.SaveChangesAsync(this); - return response; + throw MessageBox.Show(ResponseCode.NotMoney, "钻石不足"); } - /// - /// 游戏心跳 - /// - /// - /// - public async Task PlayGameHeartbeat(string gameId) + // 获取用户和游戏信息 + var userInfo = UserInfo; + PlayGameUserInfo gameInfoCache = await PlayGameExtend.GetPlayGameUserInfoCacheAsync(this, userInfo, gameInfo); + + // 检查游戏状态 + if (gameInfoCache != null) { - - // 检查用户是否已登录 - if (_UserId == 0) + switch (gameInfoCache.GameStatus) { - throw MessageBox.ErrorShow("请先登录"); + case PlayGameStatus.游戏中: + case PlayGameStatus.开始游戏: + throw MessageBox.Show(ResponseCode.Error, "已在游戏中"); + + case PlayGameStatus.排队中: + throw MessageBox.Show(ResponseCode.Error, "用户正在排队中"); } - - // 检查游戏是否存在 - var gameCache = Cache.GameEntityCache; - var gameInfo = gameCache[gameId]; - if (gameInfo == null) - { - throw MessageBox.ErrorShow("游戏不存在"); - } - var userInfo = UserInfo; - PlayGameUserInfo gameInfoCache = await PlayGameExtend.GetPlayGameUserInfoOrNull(this, userInfo, gameInfo); - if (gameInfoCache == null) - { - throw MessageBox.ErrorShow("未找到游戏信息"); - } - // 检查用户钻石是否足够 - if (userInfo.Diamond == 0 && gameInfo.ConsumeDiamondNumHour > 0) - { - PlayGameCommonSetting playGameCommonSetting = new PlayGameCommonSetting() - { - ScId = gameInfoCache.ScId, - Sn = gameInfoCache.Sn, - }; - var jyResponse = await JYApi.StopGame(playGameCommonSetting); - gameInfoCache.PlayGameClose(); - throw MessageBox.Show(ResponseCode.NotMoney, "钻石不足"); - } - PlayGameHeartbeatResponse playGameHeartbeatResponse = new PlayGameHeartbeatResponse() - { - Diamond = userInfo.Diamond, - UserPlayGameTime = 999 - }; - //LastChargingAt - if (gameInfo.ConsumeDiamondNumHour > 0) - { - //每分钟扣费 - var diamondNumHour = gameInfo.ConsumeDiamondNumHour / 60.0; - playGameHeartbeatResponse.GameConsumeDiamond = (int)diamondNumHour; - var chargingAt = DateTime.Now; - var minutes = (int)chargingAt.Subtract(gameInfoCache.LastChargingAt).TotalMinutes; - //判断扣费时间 - if (minutes > 1) - { - var gameDiamondNumHour = (int)diamondNumHour * minutes; - //当前游玩的扣费金额 - if (gameDiamondNumHour > 0) - { - //如果游玩余额大于用户可扣款的余额 - if (gameDiamondNumHour > userInfo.Diamond) - { - //去数据库中在验证一下 - //(int)userCurrency.GetUserCurrency(UserCurrencyType.钻石); - var currency = await Dao.DaoUser.Context.T_User_Currency.Where(it => it.UserId == userInfo.UserId && it.CurrencyType == (int)UserCurrencyType.钻石).FirstOrDefaultAsync(); - if (currency == null) - { - throw MessageBox.ErrorShow("用户数据错误"); - } - if ((int)(currency.CurrencyMoney) != userInfo.Diamond) - { - userInfo.Diamond = (int)currency.CurrencyMoney; - } - if (gameDiamondNumHour > userInfo.Diamond) - { - //用户余额不足 - gameDiamondNumHour = userInfo.Diamond; - playGameHeartbeatResponse.UserPlayGameTime = 0; - } - - } - var (issuccess, currlogId, diamId) = await this.UserPlayGameDiamondConsumeMoney(-gameDiamondNumHour, gameInfoCache.GameName, gameInfoCache.CurrencyLogId, gameInfoCache.DiamondListId, $"{diamondNumHour}/分钟"); - if (!issuccess) - { - throw MessageBox.ErrorShow("扣款出现错误"); - } - gameInfoCache.CurrencyLogId = currlogId; - gameInfoCache.DiamondListId = diamId; - //修改最后扣费时间 - gameInfoCache.LastChargingAt = gameInfoCache.LastChargingAt.AddMinutes(minutes); - await gameInfoCache.SaveChangesAsync(this); - await Dao.DaoUser.Context.SaveChangesAsync(); - //用户剩余游玩时间 - if (userInfo.Diamond > 0) - { - var userPlayGameTime = (int)(userInfo.Diamond / diamondNumHour); - playGameHeartbeatResponse.UserPlayGameTime = userPlayGameTime; - } - - //重置一下用户钻石 - playGameHeartbeatResponse.Diamond = userInfo.Diamond; - - } - - } - } - return playGameHeartbeatResponse; - } - /// - /// 添加日志 - /// - /// - /// - /// - /// - /// - private async Task AddPlayGmaeLog(PlayGameUserInfo gameInfoCache, string describeContent, string requestContent, string responseContent) + // 配置启动游戏设置 + var playGameSettings = new PlayGameSettings(playGameRequest.Sn, _UserId) { - var playGameLog = new T_User_PlayGmaeLog + GameKey = gameInfo.GameCloudId ?? playGameRequest.GameId, + QueueGrade = UserInfo.IsPay ? 5 : 1, + DisplayGrade = 1, + HangUpTimer = 300, // 挂机时间 5 分钟 + ModelName = playGameRequest.ModelName, + StartResolution = "1080P", + Cpu = playGameRequest.Cpu, + }; + //设置开始游戏数据 + gameInfoCache.InitStartPlayGame(playGameSettings); + // 调用鲸云游戏启动接口 + var jyResponseData = await JYApi.PlayGame(playGameSettings); + + var response = new BaseResponse(); + // 用户进入排队 + if (jyResponseData.IsLineUp) + { + var gameResponse = JsonConvert.DeserializeObject>(jyResponseData.ResponseContent); + + gameInfoCache?.PlayQueueStart(gameResponse?.Data?.PlayQueueId ?? 0, gameResponse?.Data?.QueuePos ?? 0, playGameSettings.QueueGrade, jyResponseData); + response = new BaseResponse(ResponseCode.StartQueue, "开始排队", jyResponseData.Data); + } + else if (jyResponseData.IsSuccess) + { + // 游戏启动成功 + var gameResponse = JsonConvert.DeserializeObject>(jyResponseData.ResponseContent); + // 创建游戏记录和日志 + var userGameList = new T_User_GameList { + Channel = AppRequestInfo.Channel, CreateTime = DateTime.Now, - DescribeContent = describeContent, - GameId = gameInfoCache.GameId, - UserId = gameInfoCache.UserId, - RequestContent = requestContent, - ResponseContent = responseContent, + GameId = playGameRequest.GameId, + Status = (int)PlayGameStatus.开始游戏, + UpdateTime = DateTime.Now, + UserId = _UserId, SessionId = gameInfoCache?.SessionId }; - // 创建游戏启动日志对象 + await Dao.DaoPhone.Context.T_User_GameList.AddAsync(userGameList); + await Dao.DaoPhone.Context.SaveChangesAsync(); + gameInfoCache?.PlayGameStart(gameResponse?.Data?.ScId ?? 0, userGameList.Id, playGameSettings.DisplayGrade, jyResponseData); + response = new BaseResponse(ResponseCode.Success, "", jyResponseData.Data); + } + else // 游戏启动失败 + { + gameInfoCache?.PlayGameError(jyResponseData); + response = new BaseResponse(ResponseCode.Error, jyResponseData.Msg, jyResponseData.Data); + } + await Dao.DaoPhone.Context.SaveChangesAsync(); - // 保存日志 - await Dao.DaoPhone.Context.T_User_PlayGmaeLog.AddAsync(playGameLog); - return playGameLog; + // 保存游戏缓存状态 + await gameInfoCache.SaveChangesAsync(this); + return response; + } + + /// + /// 游戏心跳 + /// + /// + /// + public async Task PlayGameHeartbeat(string gameId) + { + + // 检查用户是否已登录 + if (_UserId == 0) + { + throw MessageBox.ErrorShow("请先登录"); } - - /// - /// 游戏排队 - /// - /// - /// - public async Task> PlayGameQueueAsync(GameRequest gameRequest) + // 检查游戏是否存在 + var gameCache = Cache.GameEntityCache; + var gameInfo = gameCache[gameId]; + if (gameInfo == null) { - if (_UserId == 0) - { - throw MessageBox.ErrorShow("请先登录"); - } - var gameId = gameRequest.GameId; - // 检查游戏是否存在 - var gameCache = Cache.GameEntityCache; - var gameInfo = gameCache[gameId]; - if (gameInfo == null) - { - throw MessageBox.ErrorShow("游戏不存在"); - } - - // 获取用户和游戏信息 - var userInfo = UserInfo; - PlayGameUserInfo gameInfoCache = await PlayGameExtend.GetPlayGameUserInfoOrNull(this, userInfo, gameInfo); - if (gameInfoCache == null) - { - throw MessageBox.ErrorShow("未找到游戏信息"); - } - if (gameInfoCache.PlayQueueId == 0) - { - throw MessageBox.ErrorShow("排队出错"); - } - PlayGameQueue playGameQueue = new PlayGameQueue() - { - GameKey = gameInfoCache.JyGameId, - PlayQueueId = gameInfoCache.PlayQueueId, - QueueGrade = gameInfoCache.QueueGrade, - Sn = gameInfoCache.Sn, - }; - var paidui = await JYApi.PlayQueue(playGameQueue); - BaseResponse back = new BaseResponse(); - if (paidui.IsSuccess) - { - gameInfoCache.PlayQueueSuccess(); - - back = new BaseResponse(0, "排队成功"); - } - else if (paidui.IsLineUp) - { - gameInfoCache.PlayQueueStart(paidui?.Data?.PlayQueueId ?? 0, paidui?.Data?.QueuePos ?? 0); - back = new BaseResponse(ResponseCode.StartQueue, "", paidui.Data); - } - else - { - gameInfoCache.PlayGameError(); - back = new BaseResponse(ResponseCode.Error, "排队出现错误", paidui.Data); - } - - await gameInfoCache.SaveChangesAsync(this); - return back; + throw MessageBox.ErrorShow("游戏不存在"); } - - /// - /// 取消排队 - /// - /// - /// - public async Task> CancelQueueAsync(GameRequest gameRequest) + var userInfo = UserInfo; + PlayGameUserInfo gameInfoCache = await PlayGameExtend.GetPlayGameUserInfoOrNull(this, userInfo, gameInfo); + if (gameInfoCache == null) { - if (_UserId == 0) - { - throw MessageBox.ErrorShow("请先登录"); - } - var gameId = gameRequest.GameId; - // 检查游戏是否存在 - var gameCache = Cache.GameEntityCache; - var gameInfo = gameCache[gameId]; - if (gameInfo == null) - { - throw MessageBox.ErrorShow("游戏不存在"); - } - - // 获取用户和游戏信息 - var userInfo = UserInfo; - PlayGameUserInfo gameInfoCache = await PlayGameExtend.GetPlayGameUserInfoOrNull(this, userInfo, gameInfo); - if (gameInfoCache == null) - { - throw MessageBox.ErrorShow("未找到游戏信息"); - } - //CancelQueueAsync - //PlayGameCancelQueue playGameQueue - PlayGameQueue playGameQueue = new PlayGameQueue() - { - PlayQueueId = gameInfoCache.PlayQueueId, - Sn = gameInfoCache.Sn, - }; - var paidui = await JYApi.CancelQueue(playGameQueue); - if (paidui.IsSuccess) - { - gameInfoCache.PlayQueueCancel(); - } - await gameInfoCache.SaveChangesAsync(this); - return new BaseResponse(ResponseCode.Success, "取消排队成功"); + throw MessageBox.ErrorShow("未找到游戏信息"); } - - /// - /// 切换视频等级 - /// - /// - /// - /// - public async Task> DisplayGrade(int displayGrade, string gameId) + // 检查用户钻石是否足够 + if (userInfo.Diamond == 0 && gameInfo.ConsumeDiamondNumHour > 0) { - - if (_UserId == 0) + PlayGameCommonSetting playGameCommonSetting = new PlayGameCommonSetting() { - throw MessageBox.ErrorShow("请先登录"); - } - - // 检查游戏是否存在 - var gameCache = Cache.GameEntityCache; - var gameInfo = gameCache[gameId]; - if (gameInfo == null) - { - throw MessageBox.ErrorShow("游戏不存在"); - } - - // 获取用户和游戏信息 - var userInfo = UserInfo; - PlayGameUserInfo gameInfoCache = await PlayGameExtend.GetPlayGameUserInfoOrNull(this, userInfo, gameInfo); - if (gameInfoCache == null) - { - throw MessageBox.ErrorShow("未找到游戏信息"); - } - if (gameInfoCache.GameStatus != PlayGameStatus.开始游戏 && gameInfoCache.GameStatus != PlayGameStatus.游戏中) - { - throw MessageBox.ErrorShow("不在游戏中"); - } - DisplayGradeSettings displayGradeSettings = new DisplayGradeSettings() - { - DisplayGrade = displayGrade, ScId = gameInfoCache.ScId, Sn = gameInfoCache.Sn, }; - //切换视频等级 - var response = await JYApi.DisplayGrade(displayGradeSettings); - if (response.IsSuccess) + var jyResponse = await JYApi.StopGame(playGameCommonSetting); + gameInfoCache.PlayGameClose(); + throw MessageBox.Show(ResponseCode.NotMoney, "钻石不足"); + } + PlayGameHeartbeatResponse playGameHeartbeatResponse = new PlayGameHeartbeatResponse() + { + Diamond = userInfo.Diamond, + UserPlayGameTime = 999 + }; + //LastChargingAt + if (gameInfo.ConsumeDiamondNumHour > 0) + { + //每分钟扣费 + var diamondNumHour = gameInfo.ConsumeDiamondNumHour / 60.0; + playGameHeartbeatResponse.GameConsumeDiamond = (int)diamondNumHour; + var chargingAt = DateTime.Now; + var minutes = (int)chargingAt.Subtract(gameInfoCache.LastChargingAt ?? DateTime.Now).TotalMinutes; + //判断扣费时间 + if (minutes > 1) { - gameInfoCache.DisplayGrade = displayGrade; - await gameInfoCache.SaveChangesAsync(this); + var gameDiamondNumHour = (int)diamondNumHour * minutes; + //当前游玩的扣费金额 + if (gameDiamondNumHour > 0) + { + //如果游玩余额大于用户可扣款的余额 + if (gameDiamondNumHour > userInfo.Diamond) + { + //去数据库中在验证一下 + //(int)userCurrency.GetUserCurrency(UserCurrencyType.钻石); + var currency = await Dao.DaoUser.Context.T_User_Currency.Where(it => it.UserId == userInfo.UserId && it.CurrencyType == (int)UserCurrencyType.钻石).FirstOrDefaultAsync(); + if (currency == null) + { + throw MessageBox.ErrorShow("用户数据错误"); + } + if ((int)(currency.CurrencyMoney) != userInfo.Diamond) + { + userInfo.Diamond = (int)currency.CurrencyMoney; + } + if (gameDiamondNumHour > userInfo.Diamond) + { + //用户余额不足 + gameDiamondNumHour = userInfo.Diamond; + playGameHeartbeatResponse.UserPlayGameTime = 0; + } + + } + var (issuccess, currlogId, diamId) = await this.UserPlayGameDiamondConsumeMoney(-gameDiamondNumHour, gameInfoCache.GameName, gameInfoCache.CurrencyLogId, gameInfoCache.DiamondListId, $"{diamondNumHour}/分钟"); + if (!issuccess) + { + throw MessageBox.ErrorShow("扣款出现错误"); + } + gameInfoCache.CurrencyLogId = currlogId; + gameInfoCache.DiamondListId = diamId; + //修改最后扣费时间 + gameInfoCache.LastChargingAt = (gameInfoCache.LastChargingAt ?? gameInfoCache.CreateDateTime).AddMinutes(minutes); + gameInfoCache.PlayGameHeartbeat(); + await gameInfoCache.SaveChangesAsync(this); + await Dao.DaoUser.Context.SaveChangesAsync(); + //用户剩余游玩时间 + if (userInfo.Diamond > 0) + { + var userPlayGameTime = (int)(userInfo.Diamond / diamondNumHour); + playGameHeartbeatResponse.UserPlayGameTime = userPlayGameTime; + } + + //重置一下用户钻石 + playGameHeartbeatResponse.Diamond = userInfo.Diamond; + + } + } - else - { - throw MessageBox.ErrorShow("切换失败"); - } - return new BaseResponse(ResponseCode.Success, "", response.Data); + } + return playGameHeartbeatResponse; + + } + + + /// + /// 游戏结束 + /// + /// + /// + public async Task ExitPlayGame(string gameId) + { + // 检查用户是否已登录 + if (_UserId == 0) + { + throw MessageBox.ErrorShow("请先登录"); } - - /// - /// 获取可重连的会话列表 - /// - /// - /// - public async Task> GetMyScList(string sn) + // 检查游戏是否存在 + var gameCache = Cache.GameEntityCache; + var gameInfo = gameCache[gameId]; + if (gameInfo == null) { - var requestParmat = new RequestBaseModel() - { - Sn = sn, - }; - var response = await JYApi.MyScList(requestParmat); - if (response.IsSuccess) - { - return new BaseResponse(ResponseCode.Success, "", response.Data) { }; - } - throw response.ToMessageBox(); - + throw MessageBox.ErrorShow("游戏不存在"); } - - /// - /// 重连会话 - /// - /// - /// - /// - /// - /// - /// - public async Task> ReconPlayGame(int sc_id, int display_grade, string model_name, string sn, string cpu) + var userInfo = UserInfo; + PlayGameUserInfo gameInfoCache = await PlayGameExtend.GetPlayGameUserInfoOrNull(this, userInfo, gameInfo); + if (gameInfoCache == null) { - var setting = new ReconPlayGameSettings() - { - ScId = sc_id, - DisplayGrade = display_grade, - Cpu = cpu, - ModelName = model_name, - Sn = sn, - }; - var response = await JYApi.ReconPlayGame(setting); - if (response.IsSuccess) - { - return new BaseResponse(ResponseCode.Success, "", response.Data) { }; - } - throw response.ToMessageBox(); + throw MessageBox.ErrorShow("未找到游戏信息"); + } + if (gameInfoCache.GameStatus != PlayGameStatus.游戏结束) + { + gameInfoCache.ExitPlayGame(); } } + + + + /// + /// 游戏排队 + /// + /// + /// + public async Task> PlayGameQueueAsync(GameRequest gameRequest) + { + if (_UserId == 0) + { + throw MessageBox.ErrorShow("请先登录"); + } + var gameId = gameRequest.GameId; + // 检查游戏是否存在 + var gameCache = Cache.GameEntityCache; + var gameInfo = gameCache[gameId]; + if (gameInfo == null) + { + throw MessageBox.ErrorShow("游戏不存在"); + } + + // 获取用户和游戏信息 + var userInfo = UserInfo; + PlayGameUserInfo gameInfoCache = await PlayGameExtend.GetPlayGameUserInfoOrNull(this, userInfo, gameInfo); + if (gameInfoCache == null) + { + throw MessageBox.ErrorShow("未找到游戏信息"); + } + if (gameInfoCache.PlayQueueId == 0) + { + throw MessageBox.ErrorShow("排队出错"); + } + PlayGameQueue playGameQueue = new PlayGameQueue(gameInfoCache.Sn, _UserId) + { + GameKey = gameInfoCache.JyGameId, + PlayQueueId = gameInfoCache.PlayQueueId, + QueueGrade = gameInfoCache.QueueGrade, + }; + var paidui = await JYApi.PlayQueue(playGameQueue); + BaseResponse back = new BaseResponse(); + if (paidui.IsSuccess) + { + gameInfoCache.PlayQueueSuccess(paidui); + + back = new BaseResponse(0, "排队成功"); + } + else if (paidui.IsLineUp) + { + gameInfoCache.PlayQueueStart(paidui?.Data?.PlayQueueId ?? 0, paidui?.Data?.QueuePos ?? 0, jYApiRespnse: paidui); + back = new BaseResponse(ResponseCode.StartQueue, "", paidui.Data); + } + else + { + gameInfoCache.PlayGameError(paidui); + back = new BaseResponse(ResponseCode.Error, "排队出现错误", paidui.Data); + } + + await gameInfoCache.SaveChangesAsync(this); + return back; + } + + /// + /// 取消排队 + /// + /// + /// + public async Task> CancelQueueAsync(GameRequest gameRequest) + { + if (_UserId == 0) + { + throw MessageBox.ErrorShow("请先登录"); + } + var gameId = gameRequest.GameId; + // 检查游戏是否存在 + var gameCache = Cache.GameEntityCache; + var gameInfo = gameCache[gameId]; + if (gameInfo == null) + { + throw MessageBox.ErrorShow("游戏不存在"); + } + + // 获取用户和游戏信息 + var userInfo = UserInfo; + PlayGameUserInfo gameInfoCache = await PlayGameExtend.GetPlayGameUserInfoOrNull(this, userInfo, gameInfo); + if (gameInfoCache == null) + { + throw MessageBox.ErrorShow("未找到游戏信息"); + } + //CancelQueueAsync + //PlayGameCancelQueue playGameQueue + PlayGameQueue playGameQueue = new PlayGameQueue(gameInfoCache.Sn, _UserId) + { + PlayQueueId = gameInfoCache.PlayQueueId, + }; + var paidui = await JYApi.CancelQueue(playGameQueue); + if (paidui.IsSuccess) + { + gameInfoCache.PlayQueueCancel(paidui); + } + await gameInfoCache.SaveChangesAsync(this); + return new BaseResponse(ResponseCode.Success, "取消排队成功"); + } + + /// + /// 切换视频等级 + /// + /// + /// + /// + public async Task> DisplayGrade(int displayGrade, string gameId) + { + + if (_UserId == 0) + { + throw MessageBox.ErrorShow("请先登录"); + } + + // 检查游戏是否存在 + var gameCache = Cache.GameEntityCache; + var gameInfo = gameCache[gameId]; + if (gameInfo == null) + { + throw MessageBox.ErrorShow("游戏不存在"); + } + + // 获取用户和游戏信息 + var userInfo = UserInfo; + PlayGameUserInfo gameInfoCache = await PlayGameExtend.GetPlayGameUserInfoOrNull(this, userInfo, gameInfo); + if (gameInfoCache == null) + { + throw MessageBox.ErrorShow("未找到游戏信息"); + } + if (gameInfoCache.GameStatus != PlayGameStatus.开始游戏 && gameInfoCache.GameStatus != PlayGameStatus.游戏中) + { + throw MessageBox.ErrorShow("不在游戏中"); + } + DisplayGradeSettings displayGradeSettings = new DisplayGradeSettings() + { + DisplayGrade = displayGrade, + ScId = gameInfoCache.ScId, + Sn = gameInfoCache.Sn, + }; + //切换视频等级 + var response = await JYApi.DisplayGrade(displayGradeSettings); + if (response.IsSuccess) + { + gameInfoCache.DisplayGrade = displayGrade; + + await gameInfoCache.SaveChangesAsync(this); + } + else + { + throw MessageBox.ErrorShow("切换失败"); + } + return new BaseResponse(ResponseCode.Success, "", response.Data); + } + + + /// + /// 获取可重连的会话列表 + /// + /// + /// + public async Task> GetMyScList(string sn) + { + var requestParmat = new RequestBaseModel() + { + Sn = sn, + }; + var response = await JYApi.MyScList(requestParmat); + if (response.IsSuccess) + { + return new BaseResponse(ResponseCode.Success, "", response.Data) { }; + } + throw response.ToMessageBox(); + + } + + /// + /// 重连会话 + /// + /// + /// + /// + /// + /// + /// + public async Task> ReconPlayGame(ReconPlayGameSettings reconPlayGameSettings) + { + var setting = new ReconPlayGameSettings() + { + ScId = reconPlayGameSettings.ScId, + DisplayGrade = reconPlayGameSettings.DisplayGrade, + Cpu = reconPlayGameSettings.Cpu, + ModelName = reconPlayGameSettings.ModelName, + Sn = reconPlayGameSettings.Sn, + }; + var response = await JYApi.ReconPlayGame(setting); + if (response.IsSuccess) + { + return new BaseResponse(ResponseCode.Success, "", response.Data) { }; + } + throw response.ToMessageBox(); + } } diff --git a/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameExtend.cs b/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameExtend.cs index 8a9bede..9a45d93 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameExtend.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameExtend.cs @@ -1,3 +1,4 @@ +using CloudGaming.Code.DataAccess; using CloudGaming.DtoModel.Account.User; using CloudGaming.DtoModel.Game; using CloudGaming.DtoModel.JY; @@ -5,6 +6,8 @@ using CloudGaming.DtoModel.PlayGame; using HuanMeng.DotNetCore.Redis; +using Newtonsoft.Json; + using System.Runtime.CompilerServices; namespace CloudGaming.Code.Game @@ -54,6 +57,27 @@ namespace CloudGaming.Code.Game return gameInfoCache; } + /// + /// 初始化 + /// + /// + /// 开始游戏设置 + /// + public static bool InitStartPlayGame(this PlayGameUserInfo playGameUserInfo, PlayGameSettings playGameSettings) + { + playGameUserInfo.JyGameId = playGameSettings.GameKey; + playGameUserInfo.Sn = playGameSettings.Sn; + playGameUserInfo.ModelName = playGameSettings.ModelName; + playGameUserInfo.Cpu = playGameSettings.Cpu; + playGameUserInfo.QueueGrade = playGameSettings.QueueGrade; + playGameUserInfo.DisplayGrade = playGameSettings.DisplayGrade; + if (playGameUserInfo.GameStatus == PlayGameStatus.初始化) + { + playGameUserInfo.GameStatus = PlayGameStatus.初始化成功; + } + return true; + } + /// /// 初始化 /// @@ -62,14 +86,13 @@ namespace CloudGaming.Code.Game /// /// /// - public static bool InitStartPlayGame(this PlayGameUserInfo playGameUserInfo, string sn, string modenName, string cpu) + public static bool ExitPlayGame(this PlayGameUserInfo playGameUserInfo) { - playGameUserInfo.Sn = sn; - playGameUserInfo.Cpu = cpu; - playGameUserInfo.ModelName = modenName; - if (playGameUserInfo.GameStatus == PlayGameStatus.初始化) + + if (playGameUserInfo.GameStatus != PlayGameStatus.游戏结束) { - playGameUserInfo.GameStatus = PlayGameStatus.初始化成功; + playGameUserInfo.GameStatus = PlayGameStatus.游戏结束; + playGameUserInfo.LastDateTime = DateTime.Now; } return true; } @@ -81,14 +104,15 @@ namespace CloudGaming.Code.Game /// 本次游戏连接会话 id /// 游戏记录id /// 游戏显示等级 + /// 请求信息 /// - public static bool PlayGameStart(this PlayGameUserInfo playGameUserInfo, int scId, int gameListId, int display_grade) + public static bool PlayGameStart(this PlayGameUserInfo playGameUserInfo, int scId, int gameListId, int display_grade, IJYApiRespnse jYApiRespnse) { playGameUserInfo.GameStatus = PlayGameStatus.开始游戏; playGameUserInfo.GameListId = gameListId; playGameUserInfo.ScId = scId; playGameUserInfo.DisplayGrade = display_grade; - playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation() + playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation(jYApiRespnse) { Content = "开始游戏", OperationDateTime = DateTime.Now, @@ -104,9 +128,14 @@ namespace CloudGaming.Code.Game /// /// /// - public static bool PlayGameError(this PlayGameUserInfo playGameUserInfo) + public static bool PlayGameError(this PlayGameUserInfo playGameUserInfo, IJYApiRespnse jYApiRespnse) { playGameUserInfo.GameStatus = PlayGameStatus.游戏启动失败; + playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation(jYApiRespnse) + { + OperationDateTime = DateTime.Now, + Content = "启动游戏失败", + }); return true; } @@ -128,9 +157,12 @@ namespace CloudGaming.Code.Game /// public static bool PlayGameHeartbeat(this PlayGameUserInfo playGameUserInfo) { - - playGameUserInfo.GameStatus = PlayGameStatus.游戏中; + if (playGameUserInfo.GameStatus != PlayGameStatus.游戏中) + { + playGameUserInfo.GameStatus = PlayGameStatus.游戏中; + } playGameUserInfo.PlayGameHeartbeatAt = DateTime.Now; + playGameUserInfo.PlayGameTotalSeconds = (int)(playGameUserInfo.PlayGameHeartbeatAt ?? DateTime.Now).Subtract(playGameUserInfo.PlayGameStartAt ?? playGameUserInfo.CreateDateTime).TotalSeconds; return true; } @@ -141,29 +173,49 @@ namespace CloudGaming.Code.Game /// 队列id /// 前面还有多少位 /// 队列等级 + /// /// - public static bool PlayQueueStart(this PlayGameUserInfo playGameUserInfo, int play_queue_id, int queue_pos, int? queue_grade = null) + public static bool PlayQueueStart(this PlayGameUserInfo playGameUserInfo, int play_queue_id, int queue_pos, int? queue_grade = null, IJYApiRespnse jYApiRespnse = null) { + PlayGameUserOperation? playGameUserOperation = null; if (playGameUserInfo.GameStatus == PlayGameStatus.排队中) { - playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation() + if (playGameUserInfo.LastWriteQueueAt == null || (playGameUserInfo.LastWriteQueueAt != null && DateTime.Now.Subtract(playGameUserInfo.LastWriteQueueAt ?? DateTime.Now).TotalMinutes > 1)) { - Content = $"排队中,前面还有{queue_pos}人", - OperationDateTime = DateTime.Now, - }); + playGameUserOperation = new PlayGameUserOperation(jYApiRespnse) + { + Content = $"排队中,排队Id{play_queue_id},前面还有{queue_pos}人", + OperationDateTime = DateTime.Now, + }; + playGameUserInfo.LastWriteQueueAt = DateTime.Now; + } + else + { + playGameUserOperation = new PlayGameUserOperation() + { + Content = $"排队中,排队Id{play_queue_id},前面还有{queue_pos}人", + OperationDateTime = DateTime.Now, + }; + } + + playGameUserInfo.GameUserOperation.Add(playGameUserOperation); + } else { - playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation() + playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation(jYApiRespnse) { - Content = $"开始排队,前面还有{queue_pos}人", + Content = $"开始排队,排队Id:{play_queue_id},前面还有{queue_pos}人", OperationDateTime = DateTime.Now, }); + } playGameUserInfo.GameStatus = PlayGameStatus.排队中; playGameUserInfo.PlayQueueId = play_queue_id; - - playGameUserInfo.PlayQueueStartAt = DateTime.Now; + if (playGameUserInfo.PlayQueueStartAt == null) + { + playGameUserInfo.PlayQueueStartAt = DateTime.Now; + } if (queue_grade != null) { playGameUserInfo.QueueGrade = queue_grade ?? 1; @@ -175,7 +227,7 @@ namespace CloudGaming.Code.Game /// /// /// - public static bool PlayQueueSuccess(this PlayGameUserInfo playGameUserInfo) + public static bool PlayQueueSuccess(this PlayGameUserInfo playGameUserInfo, IJYApiRespnse jYApiRespnse) { if (playGameUserInfo.GameStatus == PlayGameStatus.排队中) { @@ -186,7 +238,7 @@ namespace CloudGaming.Code.Game { totalSeconds = (int)DateTime.Now.Subtract(playGameUserInfo.PlayQueueStartAt ?? DateTime.Now).TotalSeconds; } - playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation() + playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation(jYApiRespnse) { Content = $"排队成功,本次排队耗时{totalSeconds}秒", OperationDateTime = DateTime.Now, @@ -199,10 +251,10 @@ namespace CloudGaming.Code.Game /// /// /// - public static bool PlayQueueCancel(this PlayGameUserInfo playGameUserInfo) + public static bool PlayQueueCancel(this PlayGameUserInfo playGameUserInfo, IJYApiRespnse jYApiRespnse) { playGameUserInfo.GameStatus = PlayGameStatus.取消排队; - playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation() + playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation(jYApiRespnse) { Content = $"用户取消排队", OperationDateTime = DateTime.Now, @@ -218,11 +270,57 @@ namespace CloudGaming.Code.Game /// public static async Task SaveChangesAsync(this PlayGameUserInfo playGameUserInfo, CloudGamingBase cloudGamingBase) { + playGameUserInfo.LastDateTime = DateTime.Now; var redisGameKey = GetPlayGameKey(playGameUserInfo.GameId, playGameUserInfo.UserId); - if (playGameUserInfo.GameStatus == PlayGameStatus.取消排队 || playGameUserInfo.GameStatus == PlayGameStatus.游戏启动失败) + if (playGameUserInfo.GameStatus == PlayGameStatus.取消排队 || playGameUserInfo.GameStatus == PlayGameStatus.游戏启动失败 || playGameUserInfo.GameStatus == PlayGameStatus.游戏结束) { - return await cloudGamingBase.RedisCache.KeyDeleteAsync(redisGameKey); + if (playGameUserInfo.DiamondListId > 0) + { + //设置游玩记录 + var userGameListLog = await cloudGamingBase.Dao.DaoPhone.Context.T_User_GameList.FirstOrDefaultAsync(it => it.Id == playGameUserInfo.DiamondListId); + if (userGameListLog != null) + { + userGameListLog.Status = (int)PlayGameStatus.游戏结束; + var t = DateTime.Now.Subtract(playGameUserInfo.PlayGameStartAt ?? playGameUserInfo.CreateDateTime); + var playTime = (int)t.TotalSeconds / 60; + userGameListLog.PlaySeconds = (int)t.TotalSeconds; + userGameListLog.PlayTime = playTime; + userGameListLog.UpdateTime = DateTime.Now; + await cloudGamingBase.Dao.DaoPhone.Context.SaveChangesAsync(); + //设置游玩历史 + var userId = playGameUserInfo.UserId; + var gameId = playGameUserInfo.GameId; + //设置用户游玩历史 + var playGameTime = await cloudGamingBase.Dao.DaoPhone.Context.T_User_PlayGameTime.Where(it => it.UserId == userId && it.GameId == gameId).FirstOrDefaultAsync(); + if (playGameTime == null) + { + playGameTime = new T_User_PlayGameTime() + { + Createtime = DateTime.Now, + NightCardPlayTime = 0, + DiamondPlayTime = 0, + FreePlayTime = 0, + GameId = gameId, + PlayTime = 0, + UpdateTime = DateTime.Now, + UserId = userId, + }; + await cloudGamingBase.Dao.DaoPhone.Context.T_User_PlayGameTime.AddAsync(playGameTime); + } + playGameTime.PlayTime += playTime; + playGameTime.UpdateTime = DateTime.Now; + playGameTime.DiamondPlayTime += playTime; + await cloudGamingBase.Dao.DaoPhone.Context.SaveChangesAsync(); + } + } + var playGameLog = playGameUserInfo.ToGamePlayGameLog(); + if (playGameLog != null) + { + await cloudGamingBase.Dao.DaoPhone.Context.T_Game_PlayGameLog.AddAsync(playGameLog); + await cloudGamingBase.Dao.DaoPhone.Context.SaveChangesAsync(); + } + return await cloudGamingBase.RedisCache.KeyDeleteAsync(redisGameKey); } return await cloudGamingBase.RedisCache.StringSetAsync(redisGameKey, playGameUserInfo, TimeSpan.FromMinutes(10)); diff --git a/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameUserInfoCache.cs b/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameUserInfoCache.cs deleted file mode 100644 index e529e0f..0000000 --- a/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameUserInfoCache.cs +++ /dev/null @@ -1,19 +0,0 @@ -using CloudGaming.DtoModel.PlayGame; - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CloudGaming.Code.Game -{ - public class PlayGameUserInfoCache - { - private string redisGameKey; - public PlayGameUserInfoCache(CloudGamingBase cloudGamingBase, string gameId, string userId) - { - redisGameKey = $"PlayGame:{gameId}:{userId}"; - } - } -} diff --git a/src/CloudGaming/Model/CloudGaming.DtoModel/JY/JYApiResponse.cs b/src/CloudGaming/Model/CloudGaming.DtoModel/JY/JYApiResponse.cs index 89ee319..71fe3ba 100644 --- a/src/CloudGaming/Model/CloudGaming.DtoModel/JY/JYApiResponse.cs +++ b/src/CloudGaming/Model/CloudGaming.DtoModel/JY/JYApiResponse.cs @@ -12,7 +12,7 @@ namespace CloudGaming.DtoModel.JY /// /// /// - public class JYApiResponse : JYResponseCode where T : class, new() + public class JYApiResponse : JYResponseCode, IJYApiRespnse where T : class, new() { /// /// 请求信息 @@ -33,4 +33,27 @@ namespace CloudGaming.DtoModel.JY /// public string TotalMilliseconds { get; set; } } + + public interface IJYApiRespnse + { + /// + /// 请求信息 + /// + string RequestStr { get; set; } + /// + /// 响应信息 + /// + string ResponseStr { get; set; } + + /// + /// 返回内容 + /// + string ResponseContent { get; set; } + + /// + /// 请求耗时 + /// + string TotalMilliseconds { get; set; } + + } } diff --git a/src/CloudGaming/Model/CloudGaming.DtoModel/JY/PlayQueueInfoModel.cs b/src/CloudGaming/Model/CloudGaming.DtoModel/JY/PlayQueueInfoModel.cs index 5952645..262dca8 100644 --- a/src/CloudGaming/Model/CloudGaming.DtoModel/JY/PlayQueueInfoModel.cs +++ b/src/CloudGaming/Model/CloudGaming.DtoModel/JY/PlayQueueInfoModel.cs @@ -1,10 +1,6 @@ using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Text.Json.Serialization; namespace CloudGaming.DtoModel.JY; @@ -17,13 +13,19 @@ public class PlayQueueInfoModel /// 排队id /// [JsonProperty("play_queue_id")] + [JsonPropertyName("play_queue_id")] public int PlayQueueId { get; set; } + /// /// 前面还有多少人 /// [JsonProperty("queue_pos")] + [JsonPropertyName("queue_pos")] public int QueuePos { get; set; } -} - + [JsonProperty("level")] + [JsonPropertyName("level")] + public int Level { get; set; } + +} \ No newline at end of file diff --git a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/DisplayGradeRequest.cs b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/DisplayGradeRequest.cs new file mode 100644 index 0000000..5e53d94 --- /dev/null +++ b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/DisplayGradeRequest.cs @@ -0,0 +1,22 @@ +using CloudGaming.DtoModel.Game; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CloudGaming.DtoModel.PlayGame +{ + /// + /// + /// + public class DisplayGradeRequest : GameRequest + { + /// + /// 视频等级 + /// + public int DisplayGrade { get; set; } + + } +} diff --git a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameCommonSetting.cs b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameCommonSetting.cs index 89cc336..22d8c7c 100644 --- a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameCommonSetting.cs +++ b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameCommonSetting.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Text.Json.Serialization; -using System.Threading.Tasks; namespace CloudGaming.DtoModel.PlayGame { diff --git a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameQueue.cs b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameQueue.cs index 976a00f..ff032cd 100644 --- a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameQueue.cs +++ b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameQueue.cs @@ -1,3 +1,5 @@ +using CloudGaming.DtoModel.JY; + using System; using System.Collections.Generic; using System.Linq; @@ -10,8 +12,13 @@ namespace CloudGaming.DtoModel.PlayGame; /// /// 游戏排队 /// -public class PlayGameQueue : RequestBaseModel +public class PlayGameQueue : JYRequestParameter { + + public PlayGameQueue(string sn, int userId) : base(sn, userId) + { + } + /// /// 排队 id /// diff --git a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameStatus.cs b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameStatus.cs index a14a40b..6df1b31 100644 --- a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameStatus.cs +++ b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameStatus.cs @@ -51,6 +51,8 @@ namespace CloudGaming.DtoModel.PlayGame /// /// 游戏启动失败 /// - 游戏启动失败 = 9 + 游戏启动失败 = 9, + + } } diff --git a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameUserInfo.cs b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameUserInfo.cs index 736830f..467194a 100644 --- a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameUserInfo.cs +++ b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameUserInfo.cs @@ -1,138 +1,181 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Newtonsoft.Json; -namespace CloudGaming.DtoModel.PlayGame +namespace CloudGaming.DtoModel.PlayGame; + +/// +/// 游戏 +/// +public class PlayGameUserInfo { /// - /// 游戏 + /// 游戏Id /// - public class PlayGameUserInfo + public string GameId { get; set; } + /// + /// 游戏名称 + /// + public string GameName { get; set; } + + /// + /// 用户剩余钻石 + /// + public int UserPlayGameDiamonds { get; set; } + + /// + /// 用户本次玩游戏共花销多少钻石 + /// + public int SpendingDiamonds { get; set; } + + /// + /// 用户Id + /// + public int UserId { get; set; } + /// + /// 创建时间 + /// + public DateTime CreateDateTime { get; set; } + + /// + /// 最后一次修改时间 + /// + public DateTime LastDateTime { get; set; } + /// + /// 开始游戏时间 + /// + public DateTime? PlayGameStartAt { get; set; } + + /// + /// 本次游玩时间 + /// + public int PlayGameTotalSeconds { get; set; } + + /// + /// 游戏心跳时间 + /// + public DateTime? PlayGameHeartbeatAt { get; set; } + + /// + /// 最后一次扣费时间 + /// + public DateTime? LastChargingAt { get; set; } + + /// + /// 游戏记录id + /// + public int GameListId { get; set; } + + + /// + /// 用户设备号 + /// + public string Sn { get; set; } + /// + /// 设备号 + /// + public string SessionId { get; set; } + /// + /// 设备型号 + /// + public string ModelName { get; set; } + /// + /// 用户cpu + /// + public string Cpu { get; set; } + /// + /// 鲸云scid + /// + public int ScId { get; set; } + + /// + /// 第三方游戏id + /// + public string JyGameId { get; set; } + + /// + /// 显示等级 + /// + public int DisplayGrade { get; set; } + /// + /// 队列等级 + /// + public int QueueGrade { get; set; } + + /// + /// 用户游戏状态 + /// + public PlayGameStatus GameStatus { get; set; } + + /// + /// 用户排队Id + /// + public int PlayQueueId { get; set; } + + /// + /// 用户开始排队时间 + /// + public DateTime? PlayQueueStartAt { get; set; } + + /// + /// 最后写入排队时间 + /// + public DateTime? LastWriteQueueAt { get; set; } + + /// + /// 结束排队时间 + /// + public DateTime? PlayQueueSuccessAt { get; set; } + + /// + /// 用户操作内容 + /// + public List GameUserOperation { get; set; } + + /// + /// 金额日志表id + /// + public int CurrencyLogId { get; set; } + + + /// + /// 资产记录表id + /// + public int DiamondListId { get; set; } + + /// + /// 转化成数据库实体类 + /// + /// + public T_Game_PlayGameLog ToGamePlayGameLog() { - /// - /// 游戏Id - /// - public string GameId { get; set; } - /// - /// 游戏名称 - /// - public string GameName { get; set; } - - /// - /// 用户剩余钻石 - /// - public int UserPlayGameDiamonds { get; set; } - - /// - /// 用户本次玩游戏共花销多少钻石 - /// - public int SpendingDiamonds { get; set; } - - /// - /// 用户Id - /// - public int UserId { get; set; } - /// - /// 创建时间 - /// - public DateTime CreateDateTime { get; set; } - - /// - /// 最后一次修改时间 - /// - public DateTime LastDateTime { get; set; } - /// - /// 开始游戏时间 - /// - public DateTime PlayGameStartAt { get; set; } - - /// - /// 游戏心跳时间 - /// - public DateTime PlayGameHeartbeatAt { get; set; } - - /// - /// 最后一次扣费时间 - /// - public DateTime LastChargingAt { get; set; } - - /// - /// 游戏记录id - /// - public int GameListId { get; set; } - - - /// - /// 用户设备号 - /// - public string Sn { get; set; } - /// - /// 设备号 - /// - public string SessionId { get; set; } - /// - /// 设备型号 - /// - public string ModelName { get; set; } - /// - /// 用户cpu - /// - public string Cpu { get; set; } - /// - /// 鲸云scid - /// - public int ScId { get; set; } - - /// - /// 第三方游戏id - /// - public string JyGameId { get; set; } - - /// - /// 显示等级 - /// - public int DisplayGrade { get; set; } - /// - /// 队列等级 - /// - public int QueueGrade { get; set; } - - /// - /// 用户游戏状态 - /// - public PlayGameStatus GameStatus { get; set; } - - /// - /// 用户排队Id - /// - public int PlayQueueId { get; set; } - - /// - /// 用户开始排队时间 - /// - public DateTime? PlayQueueStartAt { get; set; } - - /// - /// 结束排队时间 - /// - public DateTime? PlayQueueSuccessAt { get; set; } - - /// - /// 用户操作内容 - /// - public List GameUserOperation { get; set; } - - /// - /// 金额日志表id - /// - public int CurrencyLogId { get; set; } - - - /// - /// 资产记录表id - /// - public int DiamondListId { get; set; } + var log = new T_Game_PlayGameLog + { + GameId = GameId, + GameName = GameName, + UserPlayGameDiamonds = UserPlayGameDiamonds, + SpendingDiamonds = SpendingDiamonds, + UserId = UserId, + CreateDateTime = CreateDateTime, + LastDateTime = LastDateTime, + PlayGameStartAt = PlayGameStartAt, + PlayGameTotalSeconds = PlayGameTotalSeconds, + PlayGameHeartbeatAt = PlayGameHeartbeatAt, + LastChargingAt = LastChargingAt, + Sn = Sn, + SessionId = SessionId, + ModelName = ModelName, + Cpu = Cpu, + ScId = ScId, + JyGameId = JyGameId, + DisplayGrade = DisplayGrade, + QueueGrade = QueueGrade, + PlayQueueId = PlayQueueId, + PlayQueueStartAt = PlayQueueStartAt, + PlayQueueSuccessAt = PlayQueueSuccessAt, + CurrencyLogId = CurrencyLogId, + DiamondListId = DiamondListId, + GameStatus = (int)GameStatus, + GameUserOperationJson = GameUserOperation == null ? "" : JsonConvert.SerializeObject(GameUserOperation), + }; + return log; } } diff --git a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameUserOperation.cs b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameUserOperation.cs index 4021507..9ca1aa1 100644 --- a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameUserOperation.cs +++ b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameUserOperation.cs @@ -1,3 +1,5 @@ +using CloudGaming.DtoModel.JY; + using System; using System.Collections.Generic; using System.Linq; @@ -11,6 +13,18 @@ namespace CloudGaming.DtoModel.PlayGame /// public class PlayGameUserOperation { + public PlayGameUserOperation() + { + } + public PlayGameUserOperation(IJYApiRespnse? jYApiRespnse) + { + RequestContent = jYApiRespnse?.ResponseStr; + ResponseContent = jYApiRespnse?.ResponseContent; + TotalMilliseconds = jYApiRespnse?.TotalMilliseconds; + } + + + /// /// 操作时间 /// @@ -20,5 +34,20 @@ namespace CloudGaming.DtoModel.PlayGame /// 操作内容 /// public string Content { get; set; } + + /// + /// 请求内容 + /// + public string RequestContent { get; set; } + + /// + /// 返回内容 + /// + public string ResponseContent { get; set; } + + /// + /// 请求耗时 + /// + public string TotalMilliseconds { get; set; } } } diff --git a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/RequestBaseModel.cs b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/RequestBaseModel.cs index c817a61..97b576c 100644 --- a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/RequestBaseModel.cs +++ b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/RequestBaseModel.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.Json.Serialization; using System.Threading.Tasks; namespace CloudGaming.DtoModel.PlayGame @@ -14,6 +15,7 @@ namespace CloudGaming.DtoModel.PlayGame /// /// 设备号 /// + [JsonPropertyName("sn")] public string Sn { get; set; } } } diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/T_App_Config.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/T_App_Config.cs index e30fcd0..2c9d1b4 100644 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/T_App_Config.cs +++ b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/T_App_Config.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace CloudGaming.GameModel.Db.Db_Ext; diff --git a/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/CloudGamingPhoneContext.cs b/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/CloudGamingPhoneContext.cs index ee269c0..1f03c24 100644 --- a/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/CloudGamingPhoneContext.cs +++ b/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/CloudGamingPhoneContext.cs @@ -93,6 +93,11 @@ public partial class CloudGamingPhoneContext : MultiTenantDbContext//DbContext /// public virtual DbSet T_Game_DiscountCfg { get; set; } + /// + /// 用户玩游戏日志表 + /// + public virtual DbSet T_Game_PlayGameLog { get; set; } + /// /// 虚拟键盘配置表 /// @@ -173,11 +178,6 @@ public partial class CloudGamingPhoneContext : MultiTenantDbContext//DbContext /// public virtual DbSet T_User_GameList { get; set; } - /// - /// 游戏日志表 - /// - public virtual DbSet T_User_GameLog { get; set; } - /// /// 用户消息表 /// @@ -188,11 +188,6 @@ public partial class CloudGamingPhoneContext : MultiTenantDbContext//DbContext /// public virtual DbSet T_User_PlayGameTime { get; set; } - /// - /// 用户游玩游戏动作日志表 - /// - public virtual DbSet T_User_PlayGmaeLog { get; set; } - /// /// 兑换码使用表 /// @@ -681,6 +676,75 @@ public partial class CloudGamingPhoneContext : MultiTenantDbContext//DbContext } }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("PK__T_Game_P__3214EC073566E4D6"); + + entity.ToTable(tb => tb.HasComment("用户玩游戏日志表")); + + entity.Property(e => e.Id).HasComment("主键"); + entity.Property(e => e.Cpu) + .HasMaxLength(50) + .HasComment("用户cpu"); + entity.Property(e => e.CreateDateTime) + .HasComment("创建时间") + .HasColumnType("datetime"); + entity.Property(e => e.CurrencyLogId).HasComment("金额日志表id"); + entity.Property(e => e.DiamondListId).HasComment("资产记录日志表id"); + entity.Property(e => e.DisplayGrade).HasComment("显示等级"); + entity.Property(e => e.GameId) + .HasMaxLength(50) + .HasComment("游戏Id"); + entity.Property(e => e.GameName) + .HasMaxLength(100) + .HasComment("游戏名称"); + entity.Property(e => e.GameStatus).HasComment("用户游戏状态"); + entity.Property(e => e.GameUserOperationJson).HasComment("用户操作内容"); + entity.Property(e => e.JyGameId) + .HasMaxLength(50) + .HasComment("第三方游戏id"); + entity.Property(e => e.LastChargingAt) + .HasComment("最后一次扣费时间") + .HasColumnType("datetime"); + entity.Property(e => e.LastDateTime) + .HasComment("最后一次修改时间") + .HasColumnType("datetime"); + entity.Property(e => e.ModelName) + .HasMaxLength(100) + .HasComment("设备型号"); + entity.Property(e => e.PlayGameHeartbeatAt) + .HasComment("游戏心跳时间") + .HasColumnType("datetime"); + entity.Property(e => e.PlayGameStartAt) + .HasComment("开始游戏时间") + .HasColumnType("datetime"); + entity.Property(e => e.PlayGameTotalSeconds).HasComment("本次游玩时间(秒)"); + entity.Property(e => e.PlayQueueId).HasComment("用户排队Id"); + entity.Property(e => e.PlayQueueStartAt) + .HasComment("用户开始排队时间") + .HasColumnType("datetime"); + entity.Property(e => e.PlayQueueSuccessAt) + .HasComment("结束排队时间") + .HasColumnType("datetime"); + entity.Property(e => e.QueueGrade).HasComment("队列等级"); + entity.Property(e => e.ScId).HasComment("鲸云scid"); + entity.Property(e => e.SessionId) + .HasMaxLength(64) + .HasComment("设备号"); + entity.Property(e => e.Sn) + .HasMaxLength(100) + .HasComment("用户设备号"); + entity.Property(e => e.SpendingDiamonds).HasComment("用户本次玩游戏共花销多少钻石"); + entity.Property(e => e.TenantId).HasComment("租户id"); + entity.Property(e => e.UserId).HasComment("用户Id"); + entity.Property(e => e.UserPlayGameDiamonds).HasComment("用户剩余钻石"); + //添加全局筛选器 + if (this.TenantInfo != null) + { + entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId); + } + }); + modelBuilder.Entity(entity => { entity.HasKey(e => e.Id).HasName("PK_T_KEYBOARDSETTING"); @@ -1122,6 +1186,9 @@ public partial class CloudGamingPhoneContext : MultiTenantDbContext//DbContext .HasComment("游戏Id"); entity.Property(e => e.PlaySeconds).HasComment("游玩时间,秒"); entity.Property(e => e.PlayTime).HasComment("游玩时间,分组数"); + entity.Property(e => e.SessionId) + .HasMaxLength(64) + .HasComment("游戏会话id"); entity.Property(e => e.Status).HasComment("状态"); entity.Property(e => e.TenantId).HasComment("租户"); entity.Property(e => e.UpdateTime) @@ -1135,56 +1202,6 @@ public partial class CloudGamingPhoneContext : MultiTenantDbContext//DbContext } }); - modelBuilder.Entity(entity => - { - entity.HasKey(e => e.Id).HasName("PK__T_User_G__3214EC07CA3EB798"); - - entity.ToTable(tb => tb.HasComment("游戏日志表")); - - entity.Property(e => e.Cpu) - .HasMaxLength(50) - .HasComment("设备cpu"); - entity.Property(e => e.CreateTime) - .HasComment("开始时间") - .HasColumnType("datetime"); - entity.Property(e => e.DisplayGrade).HasComment("显示等级"); - entity.Property(e => e.GameId) - .HasMaxLength(50) - .HasComment("游戏Id"); - entity.Property(e => e.Gamekey) - .HasMaxLength(50) - .HasComment("游戏标识,鲸云游戏id"); - entity.Property(e => e.IP) - .HasMaxLength(64) - .HasComment("ip"); - entity.Property(e => e.ModelName) - .HasMaxLength(50) - .HasComment("设备型号"); - entity.Property(e => e.PlayQueueId).HasComment("游戏排队id"); - entity.Property(e => e.PlayQueueStatus).HasComment("排队状态"); - entity.Property(e => e.QueueGrade).HasComment("排队等级"); - entity.Property(e => e.ScId) - .HasMaxLength(64) - .HasComment("会话Id"); - entity.Property(e => e.SessionId) - .HasMaxLength(64) - .HasComment("会话id"); - entity.Property(e => e.Status).HasComment("状态,排队,游戏中,启动失败"); - entity.Property(e => e.TenantId).HasComment("租户"); - entity.Property(e => e.UpdateTime) - .HasComment("结束时间") - .HasColumnType("datetime"); - entity.Property(e => e.UserId).HasComment("用户Id"); - entity.Property(e => e.UserKey) - .HasMaxLength(100) - .HasComment("用户标识"); - //添加全局筛选器 - if (this.TenantInfo != null) - { - entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId); - } - }); - modelBuilder.Entity(entity => { entity.HasKey(e => e.Id).HasName("PK__T_User_M__3214EC07ECFD5286"); @@ -1237,9 +1254,6 @@ public partial class CloudGamingPhoneContext : MultiTenantDbContext//DbContext .HasComment("游戏Id"); entity.Property(e => e.NightCardPlayTime).HasComment("包夜卡游玩时间"); entity.Property(e => e.PlayTime).HasComment("游玩总时间"); - entity.Property(e => e.SessionId) - .HasMaxLength(64) - .HasComment("会话id"); entity.Property(e => e.TenantId).HasComment("租户"); entity.Property(e => e.UpdateTime) .HasComment("创建时间") @@ -1252,37 +1266,6 @@ public partial class CloudGamingPhoneContext : MultiTenantDbContext//DbContext } }); - modelBuilder.Entity(entity => - { - entity.HasKey(e => e.Id).HasName("PK__T_User_P__3214EC07BC145801"); - - entity.ToTable(tb => tb.HasComment("用户游玩游戏动作日志表")); - - entity.Property(e => e.Id).HasComment("主键"); - entity.Property(e => e.CreateTime) - .HasComment("开始时间") - .HasColumnType("datetime"); - entity.Property(e => e.DescribeContent).HasComment("动作描述"); - entity.Property(e => e.GameId) - .HasMaxLength(50) - .HasComment("游戏Id"); - entity.Property(e => e.RequestContent).HasComment("请求接口内容"); - entity.Property(e => e.ResponseContent).HasComment("返回内容"); - entity.Property(e => e.SessionId) - .HasMaxLength(64) - .HasComment("会话id"); - entity.Property(e => e.TenantId).HasComment("租户"); - entity.Property(e => e.UpdateTime) - .HasComment("修改时间") - .HasColumnType("datetime"); - entity.Property(e => e.UserId).HasComment("用户id"); - //添加全局筛选器 - if (this.TenantInfo != null) - { - entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId); - } - }); - modelBuilder.Entity(entity => { entity.HasKey(e => e.Id).HasName("PK__T_User_R__3214EC07BEE9D60C"); diff --git a/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_Game_PlayGameLog.cs b/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_Game_PlayGameLog.cs new file mode 100644 index 0000000..4411ddb --- /dev/null +++ b/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_Game_PlayGameLog.cs @@ -0,0 +1,151 @@ +using System; + +namespace CloudGaming.Model.DbSqlServer.Db_Phone; + +/// +/// 用户玩游戏日志表 +/// +public partial class T_Game_PlayGameLog: MultiTenantEntity +{ + public T_Game_PlayGameLog() { } + + /// + /// 主键 + /// + public virtual int Id { get; set; } + + /// + /// 所属租户 + /// + public override Guid TenantId { get; set; } + + /// + /// 游戏Id + /// + public virtual string GameId { get; set; } = null!; + + /// + /// 用户Id + /// + public virtual int UserId { get; set; } + + /// + /// 游戏名称 + /// + public virtual string GameName { get; set; } = null!; + + /// + /// 用户剩余钻石 + /// + public virtual int UserPlayGameDiamonds { get; set; } + + /// + /// 用户本次玩游戏共花销多少钻石 + /// + public virtual int SpendingDiamonds { get; set; } + + /// + /// 创建时间 + /// + public virtual DateTime CreateDateTime { get; set; } + + /// + /// 最后一次修改时间 + /// + public virtual DateTime LastDateTime { get; set; } + + /// + /// 开始游戏时间 + /// + public virtual DateTime? PlayGameStartAt { get; set; } + + /// + /// 本次游玩时间(秒) + /// + public virtual int PlayGameTotalSeconds { get; set; } + + /// + /// 游戏心跳时间 + /// + public virtual DateTime? PlayGameHeartbeatAt { get; set; } + + /// + /// 最后一次扣费时间 + /// + public virtual DateTime? LastChargingAt { get; set; } + + /// + /// 用户设备号 + /// + public virtual string Sn { get; set; } = null!; + + /// + /// 设备号 + /// + public virtual string SessionId { get; set; } = null!; + + /// + /// 设备型号 + /// + public virtual string ModelName { get; set; } = null!; + + /// + /// 用户cpu + /// + public virtual string Cpu { get; set; } = null!; + + /// + /// 鲸云scid + /// + public virtual int ScId { get; set; } + + /// + /// 第三方游戏id + /// + public virtual string JyGameId { get; set; } = null!; + + /// + /// 显示等级 + /// + public virtual int DisplayGrade { get; set; } + + /// + /// 队列等级 + /// + public virtual int QueueGrade { get; set; } + + /// + /// 用户游戏状态 + /// + public virtual int GameStatus { get; set; } + + /// + /// 用户排队Id + /// + public virtual int PlayQueueId { get; set; } + + /// + /// 用户开始排队时间 + /// + public virtual DateTime? PlayQueueStartAt { get; set; } + + /// + /// 结束排队时间 + /// + public virtual DateTime? PlayQueueSuccessAt { get; set; } + + /// + /// 金额日志表id + /// + public virtual int CurrencyLogId { get; set; } + + /// + /// 资产记录日志表id + /// + public virtual int DiamondListId { get; set; } + + /// + /// 用户操作内容 + /// + public virtual string? GameUserOperationJson { get; set; } +} diff --git a/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_User_GameList.cs b/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_User_GameList.cs index b86315d..36c8fde 100644 --- a/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_User_GameList.cs +++ b/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_User_GameList.cs @@ -55,4 +55,9 @@ public partial class T_User_GameList: MultiTenantEntity /// 所属租户 /// public override Guid TenantId { get; set; } - } + + /// + /// 游戏会话id + /// + public virtual string? SessionId { get; set; } +} diff --git a/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_User_GameLog.cs b/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_User_GameLog.cs deleted file mode 100644 index c678933..0000000 --- a/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_User_GameLog.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System; - -namespace CloudGaming.Model.DbSqlServer.Db_Phone; - -/// -/// 游戏日志表 -/// -public partial class T_User_GameLog: MultiTenantEntity -{ - public T_User_GameLog() { } - - public virtual int Id { get; set; } - - /// - /// 所属租户 - /// - public override Guid TenantId { get; set; } - - /// - /// 游戏Id - /// - public virtual string GameId { get; set; } = null!; - - /// - /// ip - /// - public virtual string? IP { get; set; } - - /// - /// 会话Id - /// - public virtual string? ScId { get; set; } - - /// - /// 用户Id - /// - public virtual int UserId { get; set; } - - /// - /// 游戏标识,鲸云游戏id - /// - public virtual string? Gamekey { get; set; } - - /// - /// 游戏排队id - /// - public virtual int PlayQueueId { get; set; } - - /// - /// 排队等级 - /// - public virtual int QueueGrade { get; set; } - - /// - /// 排队状态 - /// - public virtual int PlayQueueStatus { get; set; } - - /// - /// 用户标识 - /// - public virtual string? UserKey { get; set; } - - /// - /// 显示等级 - /// - public virtual int DisplayGrade { get; set; } - - /// - /// 设备型号 - /// - public virtual string? ModelName { get; set; } - - /// - /// 设备cpu - /// - public virtual string? Cpu { get; set; } - - /// - /// 开始时间 - /// - public virtual DateTime CreateTime { get; set; } - - /// - /// 结束时间 - /// - public virtual DateTime UpdateTime { get; set; } - - /// - /// 状态,排队,游戏中,启动失败 - /// - public virtual int Status { get; set; } - - /// - /// 会话id - /// - public virtual string? SessionId { get; set; } -} diff --git a/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_User_PlayGameTime.cs b/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_User_PlayGameTime.cs index 049913f..22e937c 100644 --- a/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_User_PlayGameTime.cs +++ b/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_User_PlayGameTime.cs @@ -55,9 +55,4 @@ public partial class T_User_PlayGameTime: MultiTenantEntity /// 所属租户 /// public override Guid TenantId { get; set; } - - /// - /// 会话id - /// - public virtual string? SessionId { get; set; } -} + } diff --git a/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_User_PlayGmaeLog.cs b/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_User_PlayGmaeLog.cs deleted file mode 100644 index 2d71be3..0000000 --- a/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/T_User_PlayGmaeLog.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; - -namespace CloudGaming.Model.DbSqlServer.Db_Phone; - -/// -/// 用户游玩游戏动作日志表 -/// -public partial class T_User_PlayGmaeLog: MultiTenantEntity -{ - public T_User_PlayGmaeLog() { } - - /// - /// 主键 - /// - public virtual int Id { get; set; } - - /// - /// 所属租户 - /// - public override Guid TenantId { get; set; } - - /// - /// 游戏Id - /// - public virtual string GameId { get; set; } = null!; - - /// - /// 动作描述 - /// - public virtual string DescribeContent { get; set; } = null!; - - /// - /// 开始时间 - /// - public virtual DateTime CreateTime { get; set; } - - /// - /// 修改时间 - /// - public virtual DateTime UpdateTime { get; set; } - - /// - /// 用户id - /// - public virtual int UserId { get; set; } - - /// - /// 请求接口内容 - /// - public virtual string? RequestContent { get; set; } - - /// - /// 返回内容 - /// - public virtual string? ResponseContent { get; set; } - - /// - /// 会话id - /// - public virtual string? SessionId { get; set; } -}