修复游戏接口问题
This commit is contained in:
parent
8841099e26
commit
f2ad570efe
|
|
@ -1,4 +1,7 @@
|
|||
### 20241119
|
||||
### 20241126
|
||||
1. 增加玩游戏等接口
|
||||
|
||||
### 20241119
|
||||
1. 增加兑换码接口(测试兑换码:test)
|
||||
2. 增加首页排行榜接口
|
||||
3. 增加游玩历史接口
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 玩游戏接口
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取token接口
|
||||
/// </summary>
|
||||
/// <param name="requestBaseModel"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<string> GetTokenAsync([FromBody] RequestBaseModel requestBaseModel)
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取token接口
|
||||
/// </summary>
|
||||
/// <param name="requestBaseModel"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<BaseResponse<GetTokenModel>> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始游戏
|
||||
/// </summary>
|
||||
/// <param name="playGameRequest"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<BaseResponse<object>> PlayGameAsync([FromBody] PlayGameRequest playGameRequest)
|
||||
{
|
||||
PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi);
|
||||
return await playGameBLL.PlayGameAsync(playGameRequest);
|
||||
/// <summary>
|
||||
/// 开始游戏
|
||||
/// </summary>
|
||||
/// <param name="playGameRequest"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<BaseResponse<object>> PlayGameAsync([FromBody] PlayGameRequest playGameRequest)
|
||||
{
|
||||
PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi);
|
||||
return await playGameBLL.PlayGameAsync(playGameRequest);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏心跳
|
||||
/// </summary>
|
||||
/// <param name="gameRequest"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<PlayGameHeartbeatResponse> PlayGameHeartbeat([FromBody] GameRequest gameRequest)
|
||||
{
|
||||
PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi);
|
||||
return await playGameBLL.PlayGameHeartbeat(gameRequest.GameId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 游戏排队
|
||||
/// </summary>
|
||||
/// <param name="gameRequest"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<BaseResponse<PlayQueueInfoModel>> PlayGameQueueAsync(GameRequest gameRequest)
|
||||
{
|
||||
PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi);
|
||||
return await playGameBLL.PlayGameQueueAsync(gameRequest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消排队
|
||||
/// </summary>
|
||||
/// <param name="gameRequest"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<BaseResponse<bool>> CancelQueueAsync(GameRequest gameRequest)
|
||||
{
|
||||
PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi);
|
||||
return await playGameBLL.CancelQueueAsync(gameRequest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换视频等级
|
||||
/// </summary>
|
||||
/// <param name="displayGradeRequest"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<BaseResponse<object>> DisplayGrade([FromBody] DisplayGradeRequest displayGradeRequest)
|
||||
{
|
||||
|
||||
PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi);
|
||||
return await playGameBLL.DisplayGrade(displayGradeRequest.DisplayGrade, displayGradeRequest.GameId);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取可重连的会话列表
|
||||
/// </summary>
|
||||
/// <param name="requestBaseModel"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<BaseResponse<object>> GetMyScList([FromBody] RequestBaseModel requestBaseModel)
|
||||
{
|
||||
PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi);
|
||||
return await playGameBLL.GetMyScList(requestBaseModel.Sn);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重连会话
|
||||
/// </summary>
|
||||
/// <param name="reconPlayGameSettings"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<BaseResponse<object>> ReconPlayGame([FromBody] ReconPlayGameSettings reconPlayGameSettings)
|
||||
{
|
||||
PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi);
|
||||
return await playGameBLL.ReconPlayGame(reconPlayGameSettings);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,16 +60,12 @@ public class DiamondConsumeMoney(DAO dao, int userId, UserCurrencyType userCurre
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="dao"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="userCurrencyType"></param>
|
||||
/// <param name="money"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception">余额不足</exception>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public async Task<T_User_Currency?> AddUserCurrencyAsync(decimal money)
|
||||
{
|
||||
var currency = await dao.DaoUser.Context.T_User_Currency.Where(it => it.CurrencyType == (int)userCurrencyType && it.UserId == userId).FirstOrDefaultAsync();
|
||||
|
|
|
|||
|
|
@ -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<object>(ResponseCode.JwtError, "", null);
|
||||
return context.Response.WriteAsync(result.ToString());
|
||||
|
||||
//context.Response.Clear(); // 清空现有响应内容
|
||||
//context.Response.StatusCode = StatusCodes.Status200OK; // 设置状态码为403 Forbidden
|
||||
|
||||
//// 返回自定义的错误消息
|
||||
//var result = new BaseResponse<object>(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<object>(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()); // 写入响应
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ namespace CloudGaming.Code.Game
|
|||
return new List<GameHistoryListDto>();
|
||||
}
|
||||
List<GameHistoryListDto> gameHistoryListDtos = new List<GameHistoryListDto>();
|
||||
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<GamePlayTimeDto> gamePlayTimeDtos = new List<GamePlayTimeDto>();
|
||||
//游玩记录
|
||||
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名
|
||||
|
|
|
|||
|
|
@ -29,515 +29,494 @@ using System.Text.Json;
|
|||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace CloudGaming.Code.Game
|
||||
namespace CloudGaming.Code.Game;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class PlayGameBLL : CloudGamingBase
|
||||
{
|
||||
private IJYApi JYApi { get; set; }
|
||||
public PlayGameBLL(IServiceProvider serviceProvider, IJYApi jYApi) : base(serviceProvider)
|
||||
{
|
||||
JYApi = jYApi;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class PlayGameBLL : CloudGamingBase
|
||||
/// <param name="requestBaseModel"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BaseResponse<GetTokenModel>> 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<GetTokenModel>(ResponseCode.Success, "", data?.Data ?? new GetTokenModel());
|
||||
}
|
||||
throw data.ToMessageBox();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启动游戏方法
|
||||
/// </summary>
|
||||
/// <param name="playGameRequest">启动游戏的请求参数</param>
|
||||
/// <returns>包含操作结果的响应对象</returns>
|
||||
public async Task<BaseResponse<object>> PlayGameAsync(PlayGameRequest playGameRequest)
|
||||
{
|
||||
// 检查用户是否已登录
|
||||
if (_UserId == 0)
|
||||
{
|
||||
throw MessageBox.ErrorShow("请先登录");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="requestBaseModel"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> 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("游戏不存在");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启动游戏方法
|
||||
/// </summary>
|
||||
/// <param name="playGameRequest">启动游戏的请求参数</param>
|
||||
/// <returns>包含操作结果的响应对象</returns>
|
||||
public async Task<BaseResponse<object>> 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<object>();
|
||||
// 用户进入排队
|
||||
if (data.IsLineUp)
|
||||
{
|
||||
var gameResponse = JsonConvert.DeserializeObject<JYResponseCode<PlayQueueInfoModel>>(data.ResponseContent);
|
||||
|
||||
gameInfoCache?.PlayQueueStart(gameResponse?.Data?.PlayQueueId ?? 0, gameResponse?.Data?.QueuePos ?? 0, playGameSettings.QueueGrade);
|
||||
//playGameLog.DescribeContent += "用户进入排队状态;";
|
||||
response = new BaseResponse<object>(ResponseCode.StartQueue, "开始排队", data.Data);
|
||||
}
|
||||
else if (data.IsSuccess)
|
||||
{
|
||||
// 游戏启动成功
|
||||
var gameResponse = JsonConvert.DeserializeObject<JYResponseCode<JYPlayGameModel>>(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<object>(ResponseCode.Success, "", data.Data);
|
||||
}
|
||||
else // 游戏启动失败
|
||||
{
|
||||
gameInfoCache?.PlayGameError();
|
||||
//playGameLog.DescribeContent += "游戏启动失败;";
|
||||
await Dao.DaoPhone.Context.SaveChangesAsync();
|
||||
response = new BaseResponse<object>(ResponseCode.Error, data.Msg, data.Data);
|
||||
}
|
||||
|
||||
|
||||
await Dao.DaoPhone.Context.SaveChangesAsync();
|
||||
|
||||
// 保存游戏缓存状态
|
||||
await gameInfoCache.SaveChangesAsync(this);
|
||||
return response;
|
||||
throw MessageBox.Show(ResponseCode.NotMoney, "钻石不足");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏心跳
|
||||
/// </summary>
|
||||
/// <param name="gameId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<PlayGameHeartbeatResponse> 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;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加日志
|
||||
/// </summary>
|
||||
/// <param name="gameInfoCache"></param>
|
||||
/// <param name="describeContent"></param>
|
||||
/// <param name="requestContent"></param>
|
||||
/// <param name="responseContent"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<T_User_PlayGmaeLog> 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<object>();
|
||||
// 用户进入排队
|
||||
if (jyResponseData.IsLineUp)
|
||||
{
|
||||
var gameResponse = JsonConvert.DeserializeObject<JYResponseCode<PlayQueueInfoModel>>(jyResponseData.ResponseContent);
|
||||
|
||||
gameInfoCache?.PlayQueueStart(gameResponse?.Data?.PlayQueueId ?? 0, gameResponse?.Data?.QueuePos ?? 0, playGameSettings.QueueGrade, jyResponseData);
|
||||
response = new BaseResponse<object>(ResponseCode.StartQueue, "开始排队", jyResponseData.Data);
|
||||
}
|
||||
else if (jyResponseData.IsSuccess)
|
||||
{
|
||||
// 游戏启动成功
|
||||
var gameResponse = JsonConvert.DeserializeObject<JYResponseCode<JYPlayGameModel>>(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<object>(ResponseCode.Success, "", jyResponseData.Data);
|
||||
}
|
||||
else // 游戏启动失败
|
||||
{
|
||||
gameInfoCache?.PlayGameError(jyResponseData);
|
||||
response = new BaseResponse<object>(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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏心跳
|
||||
/// </summary>
|
||||
/// <param name="gameId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<PlayGameHeartbeatResponse> PlayGameHeartbeat(string gameId)
|
||||
{
|
||||
|
||||
// 检查用户是否已登录
|
||||
if (_UserId == 0)
|
||||
{
|
||||
throw MessageBox.ErrorShow("请先登录");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 游戏排队
|
||||
/// </summary>
|
||||
/// <param name="gameRequest"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BaseResponse<PlayQueueInfoModel>> 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<PlayQueueInfoModel> back = new BaseResponse<PlayQueueInfoModel>();
|
||||
if (paidui.IsSuccess)
|
||||
{
|
||||
gameInfoCache.PlayQueueSuccess();
|
||||
|
||||
back = new BaseResponse<PlayQueueInfoModel>(0, "排队成功");
|
||||
}
|
||||
else if (paidui.IsLineUp)
|
||||
{
|
||||
gameInfoCache.PlayQueueStart(paidui?.Data?.PlayQueueId ?? 0, paidui?.Data?.QueuePos ?? 0);
|
||||
back = new BaseResponse<PlayQueueInfoModel>(ResponseCode.StartQueue, "", paidui.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameInfoCache.PlayGameError();
|
||||
back = new BaseResponse<PlayQueueInfoModel>(ResponseCode.Error, "排队出现错误", paidui.Data);
|
||||
}
|
||||
|
||||
await gameInfoCache.SaveChangesAsync(this);
|
||||
return back;
|
||||
throw MessageBox.ErrorShow("游戏不存在");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消排队
|
||||
/// </summary>
|
||||
/// <param name="gameRequest"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BaseResponse<bool>> 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<bool>(ResponseCode.Success, "取消排队成功");
|
||||
throw MessageBox.ErrorShow("未找到游戏信息");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换视频等级
|
||||
/// </summary>
|
||||
/// <param name="displayGrade"></param>
|
||||
/// <param name="gameId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BaseResponse<object>> 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<object>(ResponseCode.Success, "", response.Data);
|
||||
}
|
||||
return playGameHeartbeatResponse;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 游戏结束
|
||||
/// </summary>
|
||||
/// <param name="gameId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task ExitPlayGame(string gameId)
|
||||
{
|
||||
// 检查用户是否已登录
|
||||
if (_UserId == 0)
|
||||
{
|
||||
throw MessageBox.ErrorShow("请先登录");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取可重连的会话列表
|
||||
/// </summary>
|
||||
/// <param name="sn"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BaseResponse<object>> 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<object>(ResponseCode.Success, "", response.Data) { };
|
||||
}
|
||||
throw response.ToMessageBox();
|
||||
|
||||
throw MessageBox.ErrorShow("游戏不存在");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重连会话
|
||||
/// </summary>
|
||||
/// <param name="sc_id"></param>
|
||||
/// <param name="display_grade"></param>
|
||||
/// <param name="model_name"></param>
|
||||
/// <param name="sn"></param>
|
||||
/// <param name="cpu"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BaseResponse<object>> 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<object>(ResponseCode.Success, "", response.Data) { };
|
||||
}
|
||||
throw response.ToMessageBox();
|
||||
throw MessageBox.ErrorShow("未找到游戏信息");
|
||||
}
|
||||
if (gameInfoCache.GameStatus != PlayGameStatus.游戏结束)
|
||||
{
|
||||
gameInfoCache.ExitPlayGame();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 游戏排队
|
||||
/// </summary>
|
||||
/// <param name="gameRequest"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BaseResponse<PlayQueueInfoModel>> 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<PlayQueueInfoModel> back = new BaseResponse<PlayQueueInfoModel>();
|
||||
if (paidui.IsSuccess)
|
||||
{
|
||||
gameInfoCache.PlayQueueSuccess(paidui);
|
||||
|
||||
back = new BaseResponse<PlayQueueInfoModel>(0, "排队成功");
|
||||
}
|
||||
else if (paidui.IsLineUp)
|
||||
{
|
||||
gameInfoCache.PlayQueueStart(paidui?.Data?.PlayQueueId ?? 0, paidui?.Data?.QueuePos ?? 0, jYApiRespnse: paidui);
|
||||
back = new BaseResponse<PlayQueueInfoModel>(ResponseCode.StartQueue, "", paidui.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameInfoCache.PlayGameError(paidui);
|
||||
back = new BaseResponse<PlayQueueInfoModel>(ResponseCode.Error, "排队出现错误", paidui.Data);
|
||||
}
|
||||
|
||||
await gameInfoCache.SaveChangesAsync(this);
|
||||
return back;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消排队
|
||||
/// </summary>
|
||||
/// <param name="gameRequest"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BaseResponse<bool>> 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<bool>(ResponseCode.Success, "取消排队成功");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换视频等级
|
||||
/// </summary>
|
||||
/// <param name="displayGrade"></param>
|
||||
/// <param name="gameId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BaseResponse<object>> 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<object>(ResponseCode.Success, "", response.Data);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取可重连的会话列表
|
||||
/// </summary>
|
||||
/// <param name="sn"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BaseResponse<object>> GetMyScList(string sn)
|
||||
{
|
||||
var requestParmat = new RequestBaseModel()
|
||||
{
|
||||
Sn = sn,
|
||||
};
|
||||
var response = await JYApi.MyScList(requestParmat);
|
||||
if (response.IsSuccess)
|
||||
{
|
||||
return new BaseResponse<object>(ResponseCode.Success, "", response.Data) { };
|
||||
}
|
||||
throw response.ToMessageBox();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重连会话
|
||||
/// </summary>
|
||||
/// <param name="sc_id"></param>
|
||||
/// <param name="display_grade"></param>
|
||||
/// <param name="model_name"></param>
|
||||
/// <param name="sn"></param>
|
||||
/// <param name="cpu"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BaseResponse<object>> 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<object>(ResponseCode.Success, "", response.Data) { };
|
||||
}
|
||||
throw response.ToMessageBox();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
/// <param name="playGameUserInfo"></param>
|
||||
/// <param name="playGameSettings">开始游戏设置</param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
|
|
@ -62,14 +86,13 @@ namespace CloudGaming.Code.Game
|
|||
/// <param name="modenName"></param>
|
||||
/// <param name="cpu"></param>
|
||||
/// <returns></returns>
|
||||
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
|
|||
/// <param name="scId">本次游戏连接会话 id</param>
|
||||
/// <param name="gameListId">游戏记录id</param>
|
||||
/// <param name="display_grade">游戏显示等级</param>
|
||||
/// <param name="jYApiRespnse">请求信息</param>
|
||||
/// <returns></returns>
|
||||
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
|
|||
/// </summary>
|
||||
/// <param name="playGameUserInfo"></param>
|
||||
/// <returns></returns>
|
||||
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
|
|||
/// <returns></returns>
|
||||
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
|
|||
/// <param name="play_queue_id">队列id</param>
|
||||
/// <param name="queue_pos">前面还有多少位</param>
|
||||
/// <param name="queue_grade">队列等级</param>
|
||||
/// <param name="jYApiRespnse"></param>
|
||||
/// <returns></returns>
|
||||
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
|
|||
/// </summary>
|
||||
/// <param name="playGameUserInfo"></param>
|
||||
/// <returns></returns>
|
||||
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
|
|||
/// </summary>
|
||||
/// <param name="playGameUserInfo"></param>
|
||||
/// <returns></returns>
|
||||
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
|
|||
/// <returns></returns>
|
||||
public static async Task<bool> 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));
|
||||
|
||||
|
|
|
|||
|
|
@ -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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ namespace CloudGaming.DtoModel.JY
|
|||
///
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class JYApiResponse<T> : JYResponseCode<T> where T : class, new()
|
||||
public class JYApiResponse<T> : JYResponseCode<T>, IJYApiRespnse where T : class, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// 请求信息
|
||||
|
|
@ -33,4 +33,27 @@ namespace CloudGaming.DtoModel.JY
|
|||
/// </summary>
|
||||
public string TotalMilliseconds { get; set; }
|
||||
}
|
||||
|
||||
public interface IJYApiRespnse
|
||||
{
|
||||
/// <summary>
|
||||
/// 请求信息
|
||||
/// </summary>
|
||||
string RequestStr { get; set; }
|
||||
/// <summary>
|
||||
/// 响应信息
|
||||
/// </summary>
|
||||
string ResponseStr { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回内容
|
||||
/// </summary>
|
||||
string ResponseContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 请求耗时
|
||||
/// </summary>
|
||||
string TotalMilliseconds { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
/// </summary>
|
||||
[JsonProperty("play_queue_id")]
|
||||
[JsonPropertyName("play_queue_id")]
|
||||
public int PlayQueueId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 前面还有多少人
|
||||
/// </summary>
|
||||
[JsonProperty("queue_pos")]
|
||||
[JsonPropertyName("queue_pos")]
|
||||
public int QueuePos { get; set; }
|
||||
}
|
||||
|
||||
|
||||
[JsonProperty("level")]
|
||||
[JsonPropertyName("level")]
|
||||
public int Level { get; set; }
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class DisplayGradeRequest : GameRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 视频等级
|
||||
/// </summary>
|
||||
public int DisplayGrade { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
|||
/// <summary>
|
||||
/// 游戏排队
|
||||
/// </summary>
|
||||
public class PlayGameQueue : RequestBaseModel
|
||||
public class PlayGameQueue : JYRequestParameter
|
||||
{
|
||||
|
||||
public PlayGameQueue(string sn, int userId) : base(sn, userId)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 排队 id
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ namespace CloudGaming.DtoModel.PlayGame
|
|||
/// <summary>
|
||||
/// 游戏启动失败
|
||||
/// </summary>
|
||||
游戏启动失败 = 9
|
||||
游戏启动失败 = 9,
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 游戏
|
||||
/// </summary>
|
||||
public class PlayGameUserInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏
|
||||
/// 游戏Id
|
||||
/// </summary>
|
||||
public class PlayGameUserInfo
|
||||
public string GameId { get; set; }
|
||||
/// <summary>
|
||||
/// 游戏名称
|
||||
/// </summary>
|
||||
public string GameName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户剩余钻石
|
||||
/// </summary>
|
||||
public int UserPlayGameDiamonds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户本次玩游戏共花销多少钻石
|
||||
/// </summary>
|
||||
public int SpendingDiamonds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户Id
|
||||
/// </summary>
|
||||
public int UserId { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime CreateDateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后一次修改时间
|
||||
/// </summary>
|
||||
public DateTime LastDateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 开始游戏时间
|
||||
/// </summary>
|
||||
public DateTime? PlayGameStartAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 本次游玩时间
|
||||
/// </summary>
|
||||
public int PlayGameTotalSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏心跳时间
|
||||
/// </summary>
|
||||
public DateTime? PlayGameHeartbeatAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后一次扣费时间
|
||||
/// </summary>
|
||||
public DateTime? LastChargingAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏记录id
|
||||
/// </summary>
|
||||
public int GameListId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 用户设备号
|
||||
/// </summary>
|
||||
public string Sn { get; set; }
|
||||
/// <summary>
|
||||
/// 设备号
|
||||
/// </summary>
|
||||
public string SessionId { get; set; }
|
||||
/// <summary>
|
||||
/// 设备型号
|
||||
/// </summary>
|
||||
public string ModelName { get; set; }
|
||||
/// <summary>
|
||||
/// 用户cpu
|
||||
/// </summary>
|
||||
public string Cpu { get; set; }
|
||||
/// <summary>
|
||||
/// 鲸云scid
|
||||
/// </summary>
|
||||
public int ScId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 第三方游戏id
|
||||
/// </summary>
|
||||
public string JyGameId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 显示等级
|
||||
/// </summary>
|
||||
public int DisplayGrade { get; set; }
|
||||
/// <summary>
|
||||
/// 队列等级
|
||||
/// </summary>
|
||||
public int QueueGrade { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户游戏状态
|
||||
/// </summary>
|
||||
public PlayGameStatus GameStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户排队Id
|
||||
/// </summary>
|
||||
public int PlayQueueId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户开始排队时间
|
||||
/// </summary>
|
||||
public DateTime? PlayQueueStartAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后写入排队时间
|
||||
/// </summary>
|
||||
public DateTime? LastWriteQueueAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束排队时间
|
||||
/// </summary>
|
||||
public DateTime? PlayQueueSuccessAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户操作内容
|
||||
/// </summary>
|
||||
public List<PlayGameUserOperation> GameUserOperation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 金额日志表id
|
||||
/// </summary>
|
||||
public int CurrencyLogId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 资产记录表id
|
||||
/// </summary>
|
||||
public int DiamondListId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 转化成数据库实体类
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public T_Game_PlayGameLog ToGamePlayGameLog()
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏Id
|
||||
/// </summary>
|
||||
public string GameId { get; set; }
|
||||
/// <summary>
|
||||
/// 游戏名称
|
||||
/// </summary>
|
||||
public string GameName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户剩余钻石
|
||||
/// </summary>
|
||||
public int UserPlayGameDiamonds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户本次玩游戏共花销多少钻石
|
||||
/// </summary>
|
||||
public int SpendingDiamonds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户Id
|
||||
/// </summary>
|
||||
public int UserId { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime CreateDateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后一次修改时间
|
||||
/// </summary>
|
||||
public DateTime LastDateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 开始游戏时间
|
||||
/// </summary>
|
||||
public DateTime PlayGameStartAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏心跳时间
|
||||
/// </summary>
|
||||
public DateTime PlayGameHeartbeatAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后一次扣费时间
|
||||
/// </summary>
|
||||
public DateTime LastChargingAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏记录id
|
||||
/// </summary>
|
||||
public int GameListId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 用户设备号
|
||||
/// </summary>
|
||||
public string Sn { get; set; }
|
||||
/// <summary>
|
||||
/// 设备号
|
||||
/// </summary>
|
||||
public string SessionId { get; set; }
|
||||
/// <summary>
|
||||
/// 设备型号
|
||||
/// </summary>
|
||||
public string ModelName { get; set; }
|
||||
/// <summary>
|
||||
/// 用户cpu
|
||||
/// </summary>
|
||||
public string Cpu { get; set; }
|
||||
/// <summary>
|
||||
/// 鲸云scid
|
||||
/// </summary>
|
||||
public int ScId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 第三方游戏id
|
||||
/// </summary>
|
||||
public string JyGameId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 显示等级
|
||||
/// </summary>
|
||||
public int DisplayGrade { get; set; }
|
||||
/// <summary>
|
||||
/// 队列等级
|
||||
/// </summary>
|
||||
public int QueueGrade { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户游戏状态
|
||||
/// </summary>
|
||||
public PlayGameStatus GameStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户排队Id
|
||||
/// </summary>
|
||||
public int PlayQueueId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户开始排队时间
|
||||
/// </summary>
|
||||
public DateTime? PlayQueueStartAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束排队时间
|
||||
/// </summary>
|
||||
public DateTime? PlayQueueSuccessAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户操作内容
|
||||
/// </summary>
|
||||
public List<PlayGameUserOperation> GameUserOperation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 金额日志表id
|
||||
/// </summary>
|
||||
public int CurrencyLogId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 资产记录表id
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
|||
/// </summary>
|
||||
public class PlayGameUserOperation
|
||||
{
|
||||
public PlayGameUserOperation()
|
||||
{
|
||||
}
|
||||
public PlayGameUserOperation(IJYApiRespnse? jYApiRespnse)
|
||||
{
|
||||
RequestContent = jYApiRespnse?.ResponseStr;
|
||||
ResponseContent = jYApiRespnse?.ResponseContent;
|
||||
TotalMilliseconds = jYApiRespnse?.TotalMilliseconds;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 操作时间
|
||||
/// </summary>
|
||||
|
|
@ -20,5 +34,20 @@ namespace CloudGaming.DtoModel.PlayGame
|
|||
/// 操作内容
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 请求内容
|
||||
/// </summary>
|
||||
public string RequestContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回内容
|
||||
/// </summary>
|
||||
public string ResponseContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 请求耗时
|
||||
/// </summary>
|
||||
public string TotalMilliseconds { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
|||
/// <summary>
|
||||
/// 设备号
|
||||
/// </summary>
|
||||
[JsonPropertyName("sn")]
|
||||
public string Sn { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
|
||||
namespace CloudGaming.GameModel.Db.Db_Ext;
|
||||
|
||||
|
|
|
|||
|
|
@ -93,6 +93,11 @@ public partial class CloudGamingPhoneContext : MultiTenantDbContext//DbContext
|
|||
/// </summary>
|
||||
public virtual DbSet<T_Game_DiscountCfg> T_Game_DiscountCfg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户玩游戏日志表
|
||||
/// </summary>
|
||||
public virtual DbSet<T_Game_PlayGameLog> T_Game_PlayGameLog { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 虚拟键盘配置表
|
||||
/// </summary>
|
||||
|
|
@ -173,11 +178,6 @@ public partial class CloudGamingPhoneContext : MultiTenantDbContext//DbContext
|
|||
/// </summary>
|
||||
public virtual DbSet<T_User_GameList> T_User_GameList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏日志表
|
||||
/// </summary>
|
||||
public virtual DbSet<T_User_GameLog> T_User_GameLog { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户消息表
|
||||
/// </summary>
|
||||
|
|
@ -188,11 +188,6 @@ public partial class CloudGamingPhoneContext : MultiTenantDbContext//DbContext
|
|||
/// </summary>
|
||||
public virtual DbSet<T_User_PlayGameTime> T_User_PlayGameTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户游玩游戏动作日志表
|
||||
/// </summary>
|
||||
public virtual DbSet<T_User_PlayGmaeLog> T_User_PlayGmaeLog { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 兑换码使用表
|
||||
/// </summary>
|
||||
|
|
@ -681,6 +676,75 @@ public partial class CloudGamingPhoneContext : MultiTenantDbContext//DbContext
|
|||
}
|
||||
});
|
||||
|
||||
modelBuilder.Entity<T_Game_PlayGameLog>(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<T_KeyboardSetting>(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<T_User_GameLog>(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<T_User_Messages>(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<T_User_PlayGmaeLog>(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<T_User_RedemptionUsage>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PK__T_User_R__3214EC07BEE9D60C");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,151 @@
|
|||
using System;
|
||||
|
||||
namespace CloudGaming.Model.DbSqlServer.Db_Phone;
|
||||
|
||||
/// <summary>
|
||||
/// 用户玩游戏日志表
|
||||
/// </summary>
|
||||
public partial class T_Game_PlayGameLog: MultiTenantEntity
|
||||
{
|
||||
public T_Game_PlayGameLog() { }
|
||||
|
||||
/// <summary>
|
||||
/// 主键
|
||||
/// </summary>
|
||||
public virtual int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属租户
|
||||
/// </summary>
|
||||
public override Guid TenantId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏Id
|
||||
/// </summary>
|
||||
public virtual string GameId { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 用户Id
|
||||
/// </summary>
|
||||
public virtual int UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏名称
|
||||
/// </summary>
|
||||
public virtual string GameName { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 用户剩余钻石
|
||||
/// </summary>
|
||||
public virtual int UserPlayGameDiamonds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户本次玩游戏共花销多少钻石
|
||||
/// </summary>
|
||||
public virtual int SpendingDiamonds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public virtual DateTime CreateDateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后一次修改时间
|
||||
/// </summary>
|
||||
public virtual DateTime LastDateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始游戏时间
|
||||
/// </summary>
|
||||
public virtual DateTime? PlayGameStartAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 本次游玩时间(秒)
|
||||
/// </summary>
|
||||
public virtual int PlayGameTotalSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏心跳时间
|
||||
/// </summary>
|
||||
public virtual DateTime? PlayGameHeartbeatAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后一次扣费时间
|
||||
/// </summary>
|
||||
public virtual DateTime? LastChargingAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户设备号
|
||||
/// </summary>
|
||||
public virtual string Sn { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 设备号
|
||||
/// </summary>
|
||||
public virtual string SessionId { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 设备型号
|
||||
/// </summary>
|
||||
public virtual string ModelName { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 用户cpu
|
||||
/// </summary>
|
||||
public virtual string Cpu { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 鲸云scid
|
||||
/// </summary>
|
||||
public virtual int ScId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 第三方游戏id
|
||||
/// </summary>
|
||||
public virtual string JyGameId { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 显示等级
|
||||
/// </summary>
|
||||
public virtual int DisplayGrade { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 队列等级
|
||||
/// </summary>
|
||||
public virtual int QueueGrade { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户游戏状态
|
||||
/// </summary>
|
||||
public virtual int GameStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户排队Id
|
||||
/// </summary>
|
||||
public virtual int PlayQueueId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户开始排队时间
|
||||
/// </summary>
|
||||
public virtual DateTime? PlayQueueStartAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束排队时间
|
||||
/// </summary>
|
||||
public virtual DateTime? PlayQueueSuccessAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 金额日志表id
|
||||
/// </summary>
|
||||
public virtual int CurrencyLogId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资产记录日志表id
|
||||
/// </summary>
|
||||
public virtual int DiamondListId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户操作内容
|
||||
/// </summary>
|
||||
public virtual string? GameUserOperationJson { get; set; }
|
||||
}
|
||||
|
|
@ -55,4 +55,9 @@ public partial class T_User_GameList: MultiTenantEntity
|
|||
/// 所属租户
|
||||
/// </summary>
|
||||
public override Guid TenantId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏会话id
|
||||
/// </summary>
|
||||
public virtual string? SessionId { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,98 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace CloudGaming.Model.DbSqlServer.Db_Phone;
|
||||
|
||||
/// <summary>
|
||||
/// 游戏日志表
|
||||
/// </summary>
|
||||
public partial class T_User_GameLog: MultiTenantEntity
|
||||
{
|
||||
public T_User_GameLog() { }
|
||||
|
||||
public virtual int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属租户
|
||||
/// </summary>
|
||||
public override Guid TenantId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏Id
|
||||
/// </summary>
|
||||
public virtual string GameId { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// ip
|
||||
/// </summary>
|
||||
public virtual string? IP { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 会话Id
|
||||
/// </summary>
|
||||
public virtual string? ScId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户Id
|
||||
/// </summary>
|
||||
public virtual int UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏标识,鲸云游戏id
|
||||
/// </summary>
|
||||
public virtual string? Gamekey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏排队id
|
||||
/// </summary>
|
||||
public virtual int PlayQueueId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排队等级
|
||||
/// </summary>
|
||||
public virtual int QueueGrade { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排队状态
|
||||
/// </summary>
|
||||
public virtual int PlayQueueStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户标识
|
||||
/// </summary>
|
||||
public virtual string? UserKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 显示等级
|
||||
/// </summary>
|
||||
public virtual int DisplayGrade { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备型号
|
||||
/// </summary>
|
||||
public virtual string? ModelName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备cpu
|
||||
/// </summary>
|
||||
public virtual string? Cpu { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始时间
|
||||
/// </summary>
|
||||
public virtual DateTime CreateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束时间
|
||||
/// </summary>
|
||||
public virtual DateTime UpdateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态,排队,游戏中,启动失败
|
||||
/// </summary>
|
||||
public virtual int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 会话id
|
||||
/// </summary>
|
||||
public virtual string? SessionId { get; set; }
|
||||
}
|
||||
|
|
@ -55,9 +55,4 @@ public partial class T_User_PlayGameTime: MultiTenantEntity
|
|||
/// 所属租户
|
||||
/// </summary>
|
||||
public override Guid TenantId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 会话id
|
||||
/// </summary>
|
||||
public virtual string? SessionId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,61 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace CloudGaming.Model.DbSqlServer.Db_Phone;
|
||||
|
||||
/// <summary>
|
||||
/// 用户游玩游戏动作日志表
|
||||
/// </summary>
|
||||
public partial class T_User_PlayGmaeLog: MultiTenantEntity
|
||||
{
|
||||
public T_User_PlayGmaeLog() { }
|
||||
|
||||
/// <summary>
|
||||
/// 主键
|
||||
/// </summary>
|
||||
public virtual int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属租户
|
||||
/// </summary>
|
||||
public override Guid TenantId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏Id
|
||||
/// </summary>
|
||||
public virtual string GameId { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 动作描述
|
||||
/// </summary>
|
||||
public virtual string DescribeContent { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 开始时间
|
||||
/// </summary>
|
||||
public virtual DateTime CreateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
public virtual DateTime UpdateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户id
|
||||
/// </summary>
|
||||
public virtual int UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 请求接口内容
|
||||
/// </summary>
|
||||
public virtual string? RequestContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回内容
|
||||
/// </summary>
|
||||
public virtual string? ResponseContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 会话id
|
||||
/// </summary>
|
||||
public virtual string? SessionId { get; set; }
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user