diff --git a/src/CloudGaming/Api/CloudGaming.Api/appsettings.Development.json b/src/CloudGaming/Api/CloudGaming.Api/appsettings.Development.json
index c7ca56c..1f3aad1 100644
--- a/src/CloudGaming/Api/CloudGaming.Api/appsettings.Development.json
+++ b/src/CloudGaming/Api/CloudGaming.Api/appsettings.Development.json
@@ -10,7 +10,7 @@
"secret": "95BB717C61D1ECB0E9FB82C932CC77FF",
"nodes": "http://124.220.55.158:94", //多个节点使用逗号分隔
"url": "http://124.220.55.158:94",
- "env": "PROD",
+ "env": "DEV",
"UserName": "admin",
"Password": "dbt@com@1234"
},
diff --git a/src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrencyExtend.cs b/src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrencyExtend.cs
index e642954..8c4dcd1 100644
--- a/src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrencyExtend.cs
+++ b/src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrencyExtend.cs
@@ -14,416 +14,414 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace CloudGaming.Code.Account
+namespace CloudGaming.Code.Account;
+
+public static class UserCurrencyExtend
{
- public static class UserCurrencyExtend
+ ///
+ /// 获取用户货币余额,没有货币的时候添加
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static async Task GetUserCurrencyMoney(this T_User user, UserCurrencyType userCurrencyType, DAO dao)
{
- ///
- /// 获取用户货币余额,没有货币的时候添加
- ///
- ///
- ///
- ///
- ///
- public static async Task GetUserCurrencyMoney(this T_User user, UserCurrencyType userCurrencyType, DAO dao)
+ var userCurrency = await dao.DaoUser.Context.T_User_Currency.FirstOrDefaultAsync(it => it.UserId == user.Id && it.CurrencyType == (int)userCurrencyType);
+ if (userCurrency == null)
{
- var userCurrency = await dao.DaoUser.Context.T_User_Currency.FirstOrDefaultAsync(it => it.UserId == user.Id && it.CurrencyType == (int)userCurrencyType);
- if (userCurrency == null)
+ userCurrency = new T_User_Currency()
{
- userCurrency = new T_User_Currency()
- {
- CurrencyMoney = 0,
- CreateAt = DateTime.Now,
- CurrencyName = userCurrencyType.ToString(),
- CurrencyType = (int)userCurrencyType,
- UpdateAt = DateTime.Now,
- UserId = user.Id,
- };
- await dao.DaoUser.Context.AddAsync(userCurrency);
- await dao.DaoUser.Context.SaveChangesAsync();
- }
- return userCurrency?.CurrencyMoney ?? 0;
+ CurrencyMoney = 0,
+ CreateAt = DateTime.Now,
+ CurrencyName = userCurrencyType.ToString(),
+ CurrencyType = (int)userCurrencyType,
+ UpdateAt = DateTime.Now,
+ UserId = user.Id,
+ };
+ await dao.DaoUser.Context.AddAsync(userCurrency);
+ await dao.DaoUser.Context.SaveChangesAsync();
}
+ return userCurrency?.CurrencyMoney ?? 0;
+ }
- ///
- /// 获取用户货币余额
- ///
- ///
- ///
- ///
- ///
- public static async Task GetUserCurrency(this T_User user, UserCurrencyType userCurrencyType, DAO dao)
- {
- var userCurrency = await dao.DaoUser.Context.T_User_Currency.FirstOrDefaultAsync(it => it.UserId == user.Id && it.CurrencyType == (int)userCurrencyType);
- return userCurrency;
- }
+ ///
+ /// 获取用户货币余额
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static async Task GetUserCurrency(this T_User user, UserCurrencyType userCurrencyType, DAO dao)
+ {
+ var userCurrency = await dao.DaoUser.Context.T_User_Currency.FirstOrDefaultAsync(it => it.UserId == user.Id && it.CurrencyType == (int)userCurrencyType);
+ return userCurrency;
+ }
- ///
- /// 获取用户所有货币信息
- ///
- ///
- ///
- ///
- ///
- public static async Task> GetUserCurrencys(this T_User user, DAO dao)
- {
- var userCurrency = await dao.DaoUser.Context.T_User_Currency.Where(it => it.UserId == user.Id).ToListAsync();
- return userCurrency;
- }
+ ///
+ /// 获取用户所有货币信息
+ ///
+ ///
+ ///
+ ///
+ public static async Task> GetUserCurrencys(this T_User user, DAO dao)
+ {
+ var userCurrency = await dao.DaoUser.Context.T_User_Currency.Where(it => it.UserId == user.Id).ToListAsync();
+ return userCurrency;
+ }
- ///
- /// 扣除或者充值货币
- ///
- ///
- /// 货币类型
- /// 扣除金额(负数扣除,正数添加)
- /// 数据库
- ///
- /// 订单号
- ///
- ///
- ///
- public static async Task ConsumeMoneyNoWork(this T_User user, UserCurrencyType userCurrencyType, decimal money, DAO dao, T_User_Currency? _currency = null, string orderId = "", string title = "")
+ ///
+ /// 扣除或者充值货币
+ ///
+ ///
+ /// 货币类型
+ /// 扣除金额(负数扣除,正数添加)
+ /// 数据库
+ ///
+ /// 订单号
+ ///
+ ///
+ ///
+ public static async Task ConsumeMoneyNoWork(this T_User user, UserCurrencyType userCurrencyType, decimal money, DAO dao, T_User_Currency? _currency = null, string orderId = "", string title = "")
+ {
+ if (user == null || user.Id == 0)
{
- if (user == null || user.Id == 0)
- {
- throw new ArgumentNullException("用户不能为空");
- }
- int userId = user.Id;
- return await UserConsumeDiamondMoneyAsync(dao, userId, userCurrencyType, money, title, orderId, _currency);
+ throw new ArgumentNullException("用户不能为空");
}
+ int userId = user.Id;
+ return await UserConsumeDiamondMoneyAsync(dao, userId, userCurrencyType, money, title, orderId, _currency);
+ }
- ///
- /// 扣除当前用户钻石
- ///
- ///
- ///
- ///
- public static IUserConsumeMoney GetCurrentUserConsumeMoney(this CloudGamingBase cloudGamingBase, UserCurrencyType userCurrencyType, T_User_Currency currency = null)
+ ///
+ /// 扣除当前用户钻石
+ ///
+ ///
+ ///
+ ///
+ public static IUserConsumeMoney GetCurrentUserConsumeMoney(this CloudGamingBase cloudGamingBase, UserCurrencyType userCurrencyType, T_User_Currency currency = null)
+ {
+ return GetCurrentUserConsumeMoney(cloudGamingBase.Dao, cloudGamingBase._UserId, userCurrencyType, currency);
+ }
+ ///
+ /// 扣除当前用户钻石
+ ///
+ ///
+ ///
+ ///
+ public static IUserConsumeMoney GetCurrentUserConsumeMoney(DAO dao, int userId, UserCurrencyType userCurrencyType, T_User_Currency currency = null)
+ {
+ if (UserCurrencyType.钻石 == userCurrencyType)
{
- return GetCurrentUserConsumeMoney(cloudGamingBase.Dao, cloudGamingBase._UserId, userCurrencyType, currency);
- }
- ///
- /// 扣除当前用户钻石
- ///
- ///
- ///
- ///
- public static IUserConsumeMoney GetCurrentUserConsumeMoney(DAO dao, int userId, UserCurrencyType userCurrencyType, T_User_Currency currency = null)
- {
- if (UserCurrencyType.钻石 == userCurrencyType)
- {
- return new DiamondConsumeMoney(dao, userId, userCurrencyType, currency);
- }
- else if (userCurrencyType == UserCurrencyType.会员卡 || userCurrencyType == UserCurrencyType.会员季卡 || userCurrencyType == UserCurrencyType.会员月卡 || userCurrencyType == UserCurrencyType.会员年卡)
- {
- return new PlayCardConsumeMoney(dao, userId, userCurrencyType, currency);
- }
return new DiamondConsumeMoney(dao, userId, userCurrencyType, currency);
}
-
- ///
- /// 扣除当前用户钻石
- ///
- ///
- ///
- ///
- public static IUserConsumeMoney CurrentUserConsumeMoney(this UserInfoCache userInfo, CloudGamingBase cloudGamingBase, UserCurrencyType userCurrencyType, T_User_Currency currency = null)
+ else if (userCurrencyType == UserCurrencyType.会员卡 || userCurrencyType == UserCurrencyType.会员季卡 || userCurrencyType == UserCurrencyType.会员月卡 || userCurrencyType == UserCurrencyType.会员年卡)
{
- return GetCurrentUserConsumeMoney(cloudGamingBase.Dao, userInfo.UserId, userCurrencyType, currency);
-
+ return new PlayCardConsumeMoney(dao, userId, userCurrencyType, currency);
}
+ return new DiamondConsumeMoney(dao, userId, userCurrencyType, currency);
+ }
- ///
- /// 扣除当前用户钻石
- ///
- ///
- ///
- ///
- ///
- public static async Task UserConsumeDiamondMoneyAsync(this CloudGamingBase cloudGamingBase, decimal money, Action? userDoamondAction = null)
+ ///
+ /// 扣除当前用户钻石
+ ///
+ ///
+ ///
+ ///
+ public static IUserConsumeMoney CurrentUserConsumeMoney(this UserInfoCache userInfo, CloudGamingBase cloudGamingBase, UserCurrencyType userCurrencyType, T_User_Currency currency = null)
+ {
+ return GetCurrentUserConsumeMoney(cloudGamingBase.Dao, userInfo.UserId, userCurrencyType, currency);
+
+ }
+
+ ///
+ /// 扣除当前用户钻石
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static async Task UserConsumeDiamondMoneyAsync(this CloudGamingBase cloudGamingBase, decimal money, Action? userDoamondAction = null)
+ {
+ T_User_Currency currency = new T_User_Currency();
+ try
{
- T_User_Currency currency = new T_User_Currency();
- try
+ var isSuccess = await UserConsumeDiamondMoneyAsync(cloudGamingBase.Dao, cloudGamingBase.UserInfo.UserId, money, userDoamondAction, currency);//
+ if (!isSuccess)
{
- var isSuccess = await UserConsumeDiamondMoneyAsync(cloudGamingBase.Dao, cloudGamingBase.UserInfo.UserId, money, userDoamondAction, currency);//
- if (!isSuccess)
- {
- return false;
- }
- cloudGamingBase.UserInfo.Diamond = (int)currency.CurrencyMoney;
- await cloudGamingBase.SaveUserInfoCacheChangesAsync();
- }
- catch (Exception ex)
- {
-
return false;
}
- return true;
+ cloudGamingBase.UserInfo.Diamond = (int)currency.CurrencyMoney;
+ await cloudGamingBase.SaveUserInfoCacheChangesAsync();
}
-
-
-
-
-
- ///
- /// 扣除或者添加当前用户钻石
- ///
- ///
- ///
- /// 负数扣除,正数添加
- ///
- ///
- public static async Task UserConsumeDiamondMoneyAsync(DAO dao, int userId, decimal money, Action? userDoamondAction = null, T_User_Currency userCurrency = null)
+ catch (Exception ex)
{
- var userConsumeMoney = new DiamondConsumeMoney(dao, userId, UserCurrencyType.钻石, userCurrency);
- try
- {
- var isSuccess = await userConsumeMoney.ConsumeMoneyAsync(money);
- if (!isSuccess)
- {
- return false;
- }
- UserCurrencyConsumeType consumeType = money >= 0 ? UserCurrencyConsumeType.收入 : UserCurrencyConsumeType.消耗;
- T_User_DiamondList userDiamondList = new T_User_DiamondList()
- {
- CreateAt = DateTime.Now,
- Consume = money,
- ConsumeType = (int)consumeType,
- CurrencyType = (int)UserCurrencyType.钻石,
- OrderCode = "",
- Title = "",
- UpdateAt = DateTime.Now,
- UserId = userId,
- };
- if (userDoamondAction != null)
- {
- userDoamondAction(userDiamondList);
- }
- await dao.DaoUser.Context.AddAsync(userDiamondList);
- await dao.DaoUser.Context.SaveChangesAsync();
- }
- catch (Exception ex)
- {
+ return false;
+ }
+ return true;
+ }
+
+
+
+
+ ///
+ /// 扣除或者添加当前用户钻石
+ ///
+ ///
+ ///
+ /// 负数扣除,正数添加
+ ///
+ ///
+ public static async Task UserConsumeDiamondMoneyAsync(DAO dao, int userId, decimal money, Action? userDoamondAction = null, T_User_Currency userCurrency = null)
+ {
+
+ var userConsumeMoney = new DiamondConsumeMoney(dao, userId, UserCurrencyType.钻石, userCurrency);
+ try
+ {
+ var isSuccess = await userConsumeMoney.ConsumeMoneyAsync(money);
+ if (!isSuccess)
+ {
return false;
}
- return true;
+ UserCurrencyConsumeType consumeType = money >= 0 ? UserCurrencyConsumeType.收入 : UserCurrencyConsumeType.消耗;
+ T_User_DiamondList userDiamondList = new T_User_DiamondList()
+ {
+ CreateAt = DateTime.Now,
+ Consume = money,
+ ConsumeType = (int)consumeType,
+ CurrencyType = (int)UserCurrencyType.钻石,
+ OrderCode = "",
+ Title = "",
+ UpdateAt = DateTime.Now,
+ UserId = userId,
+ };
+ if (userDoamondAction != null)
+ {
+ userDoamondAction(userDiamondList);
+ }
+ await dao.DaoUser.Context.AddAsync(userDiamondList);
+ await dao.DaoUser.Context.SaveChangesAsync();
}
- ///
- /// 畅玩卡
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static async Task UserConsumePlayGameMoneyAsync(DAO dao, int userId, decimal money, UserCurrencyType userCurrencyType, Action? userDoamondAction = null, T_User_Currency userCurrency = null)
+ catch (Exception ex)
{
- var userConsumeMoney = GetCurrentUserConsumeMoney(dao, userId, userCurrencyType, userCurrency);
- try
- {
- var isSuccess = await userConsumeMoney.ConsumeMoneyAsync(money);
- if (!isSuccess)
- {
- return false;
- }
- UserCurrencyConsumeType consumeType = money >= 0 ? UserCurrencyConsumeType.收入 : UserCurrencyConsumeType.消耗;
- T_User_DiamondList userDiamondList = new T_User_DiamondList()
- {
- CreateAt = DateTime.Now,
- Consume = money,
- ConsumeType = (int)consumeType,
- CurrencyType = (int)userCurrencyType,
- OrderCode = "",
- Title = "",
- UpdateAt = DateTime.Now,
- UserId = userId,
- };
- if (userDoamondAction != null)
- {
- userDoamondAction(userDiamondList);
- }
- await dao.DaoUser.Context.AddAsync(userDiamondList);
- await dao.DaoUser.Context.SaveChangesAsync();
- }
- catch (Exception ex)
- {
+ return false;
+ }
+ return true;
+ }
+ ///
+ /// 畅玩卡
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static async Task UserConsumePlayGameMoneyAsync(DAO dao, int userId, decimal money, UserCurrencyType userCurrencyType, Action? userDoamondAction = null, T_User_Currency userCurrency = null)
+ {
+ var userConsumeMoney = GetCurrentUserConsumeMoney(dao, userId, userCurrencyType, userCurrency);
+ try
+ {
+ var isSuccess = await userConsumeMoney.ConsumeMoneyAsync(money);
+ if (!isSuccess)
+ {
return false;
}
- return true;
+ UserCurrencyConsumeType consumeType = money >= 0 ? UserCurrencyConsumeType.收入 : UserCurrencyConsumeType.消耗;
+ T_User_DiamondList userDiamondList = new T_User_DiamondList()
+ {
+ CreateAt = DateTime.Now,
+ Consume = money,
+ ConsumeType = (int)consumeType,
+ CurrencyType = (int)userCurrencyType,
+ OrderCode = "",
+ Title = "",
+ UpdateAt = DateTime.Now,
+ UserId = userId,
+ };
+ if (userDoamondAction != null)
+ {
+ userDoamondAction(userDiamondList);
+ }
+ await dao.DaoUser.Context.AddAsync(userDiamondList);
+ await dao.DaoUser.Context.SaveChangesAsync();
}
-
- ///
- ///
- ///
- ///
- /// 金额
- /// 资产支出标题
- /// 订单号
- ///
-
- public static async Task UserConsumeDiamondMoneyAsync(this CloudGamingBase cloudGamingBase, UserCurrencyType userCurrencyType, decimal money, string title = "", string orderId = "")
+ catch (Exception ex)
{
- if (userCurrencyType == UserCurrencyType.钻石)
- {
- return await UserConsumeDiamondMoneyAsync(cloudGamingBase, money, it => { it.Title = title; it.OrderCode = orderId; });
- }
- else if (userCurrencyType == UserCurrencyType.会员卡 || userCurrencyType == UserCurrencyType.会员季卡 || userCurrencyType == UserCurrencyType.会员月卡 || userCurrencyType == UserCurrencyType.会员年卡)
- {
- var cu = new T_User_Currency();
- var isSuccess = await UserConsumePlayGameMoneyAsync(cloudGamingBase.Dao, cloudGamingBase._UserId, money, userCurrencyType, it => { it.Title = title; it.OrderCode = orderId; }, cu);
- if (isSuccess)
- {
- cloudGamingBase.UserInfo.UserVipInfo = new UserInfoPlayGameCard(cu);
- }
- return isSuccess;
- }
+ return false;
+ }
+ return true;
+ }
+ ///
+ ///
+ ///
+ ///
+ /// 金额
+ /// 资产支出标题
+ /// 订单号
+ ///
+
+ public static async Task UserConsumeDiamondMoneyAsync(this CloudGamingBase cloudGamingBase, UserCurrencyType userCurrencyType, decimal money, string title = "", string orderId = "")
+ {
+ if (userCurrencyType == UserCurrencyType.钻石)
+ {
return await UserConsumeDiamondMoneyAsync(cloudGamingBase, money, it => { it.Title = title; it.OrderCode = orderId; });
}
- ///
- /// 充值或者消耗用户货币
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
-
- public static async Task UserConsumeDiamondMoneyAsync(DAO dao, int userId, UserCurrencyType userCurrencyType, decimal money, string title = "", string orderId = "", T_User_Currency currency = null)
+ else if (userCurrencyType == UserCurrencyType.会员卡 || userCurrencyType == UserCurrencyType.会员季卡 || userCurrencyType == UserCurrencyType.会员月卡 || userCurrencyType == UserCurrencyType.会员年卡)
{
- if (userCurrencyType == UserCurrencyType.钻石)
- {
- return await UserConsumeDiamondMoneyAsync(dao, userId, money, it => { it.Title = title; it.OrderCode = orderId; }, currency);
- }
- else if (userCurrencyType == UserCurrencyType.会员卡 || userCurrencyType == UserCurrencyType.会员季卡 || userCurrencyType == UserCurrencyType.会员月卡 || userCurrencyType == UserCurrencyType.会员年卡)
- {
- return await UserConsumePlayGameMoneyAsync(dao, userId, money, userCurrencyType, it => { it.Title = title; it.OrderCode = orderId; }, currency);
- }
- return await UserConsumeDiamondMoneyAsync(dao, userId, money, it => { it.Title = title; it.OrderCode = orderId; }, currency);
- }
-
- ///
- /// 用户玩游戏消耗钻石
- ///
- ///
- /// 金额
- /// 资产记录日志id
- /// 游戏名称
- /// 资产收入支出记录id
- /// 游戏每分钟消耗多少钻石
- ///
- public static async Task<(bool, int, int)> UserPlayGameDiamondConsumeMoney(this CloudGamingBase cloudGamingBase, decimal money, string gameName, int currencyLogId, int diamondListId, string gameXiaoHao)
- {
- bool issuccess = false;
- int _currencyLogId = currencyLogId;
- try
- {
- var currency = new T_User_Currency();
- GameDiamondConsumeMoney gameDiamondConsumeMoney = new GameDiamondConsumeMoney(cloudGamingBase.Dao, cloudGamingBase._UserId, UserCurrencyType.钻石, currency);
- (issuccess, _currencyLogId) = await gameDiamondConsumeMoney.ConsumeMoneyAsync(money, currencyLogId);
- if (issuccess)
- {
- cloudGamingBase.UserInfo.Diamond = (int)currency.CurrencyMoney;
- //await cloudGamingBase.SaveUserInfoCacheChangesAsync();
- UserCurrencyConsumeType consumeType = money >= 0 ? UserCurrencyConsumeType.收入 : UserCurrencyConsumeType.消耗;
- T_User_DiamondList userDiamondList = null;
- if (diamondListId > 0)
- {
- userDiamondList = await cloudGamingBase.Dao.DaoUser.Context.T_User_DiamondList.FirstOrDefaultAsync(it => it.Id == diamondListId);
- }
- if (userDiamondList == null)
- {
- userDiamondList = new T_User_DiamondList()
- {
- CreateAt = DateTime.Now,
- Consume = 0,
- ConsumeType = (int)consumeType,
- CurrencyType = (int)UserCurrencyType.钻石,
- OrderCode = "",
- Title = $"游玩《{gameName}》",
- UpdateAt = DateTime.Now,
- UserId = cloudGamingBase.UserInfo.UserId,
- Extend = gameXiaoHao,
- };
- await cloudGamingBase.Dao.DaoUser.Context.AddAsync(userDiamondList);
-
- }
- userDiamondList.Consume += Math.Abs(money);
- userDiamondList.UpdateAt = DateTime.Now;
- await cloudGamingBase.Dao.DaoUser.Context.SaveChangesAsync();
- diamondListId = userDiamondList.Id;
- }
- }
- catch (Exception ex)
- {
-
- return (false, _currencyLogId, diamondListId); ;
- }
- return (issuccess, _currencyLogId, diamondListId);
-
- }
- ///
- /// 扣除当前用户钻石
- ///
- ///
- ///
- ///
- public static async Task UserConsumeMoneyAsync(this CloudGamingBase cloudGamingBase, int userId, decimal money)
- {
- bool isSuccess = await UserConsumeDiamondMoneyAsync(userId, money, cloudGamingBase);
+ var cu = new T_User_Currency();
+ var isSuccess = await UserConsumePlayGameMoneyAsync(cloudGamingBase.Dao, cloudGamingBase._UserId, money, userCurrencyType, it => { it.Title = title; it.OrderCode = orderId; }, cu);
if (isSuccess)
{
+
+ cloudGamingBase.UserInfo.UserVipInfo = new UserInfoPlayGameCard(cu);
await cloudGamingBase.SaveUserInfoCacheChangesAsync();
}
return isSuccess;
}
+ return await UserConsumeDiamondMoneyAsync(cloudGamingBase, money, it => { it.Title = title; it.OrderCode = orderId; });
+ }
+ ///
+ /// 充值或者消耗用户货币
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
- ///
- /// 扣除当前用户钻石
- ///
- ///
- ///
- ///
- public static async Task UserConsumeDiamondMoneyAsync(int userId, decimal money, CloudGamingBase cloudGamingBase)
+ public static async Task UserConsumeDiamondMoneyAsync(DAO dao, int userId, UserCurrencyType userCurrencyType, decimal money, string title = "", string orderId = "", T_User_Currency currency = null)
+ {
+ if (userCurrencyType == UserCurrencyType.钻石)
{
- T_User_Currency currency = new T_User_Currency();
- var userConsumeMoney = new DiamondConsumeMoney(cloudGamingBase.Dao, userId, UserCurrencyType.钻石, currency);
- try
- {
- var isSuccess = await userConsumeMoney.ConsumeMoneyAsync(money);
-
- if (!isSuccess)
- {
- return false;
- }
- //清除缓存
- string key = AccountExtend.GetUserInfoRedisKey(userId);
- var userInfo = await cloudGamingBase.RedisCache.StringGetAsync(key);
- if (userInfo != null)
- {
- userInfo.Diamond = (int)currency.CurrencyMoney;
- await cloudGamingBase.RedisCache.StringSetAsync(key, userInfo, TimeSpan.FromMinutes(30));
- }
- }
- catch (Exception ex)
- {
-
- return false;
- }
- return true;
+ return await UserConsumeDiamondMoneyAsync(dao, userId, money, it => { it.Title = title; it.OrderCode = orderId; }, currency);
}
+ else if (userCurrencyType == UserCurrencyType.会员卡 || userCurrencyType == UserCurrencyType.会员季卡 || userCurrencyType == UserCurrencyType.会员月卡 || userCurrencyType == UserCurrencyType.会员年卡)
+ {
+ return await UserConsumePlayGameMoneyAsync(dao, userId, money, userCurrencyType, it => { it.Title = title; it.OrderCode = orderId; }, currency);
+ }
+ return await UserConsumeDiamondMoneyAsync(dao, userId, money, it => { it.Title = title; it.OrderCode = orderId; }, currency);
+ }
+
+ ///
+ /// 用户玩游戏消耗钻石
+ ///
+ ///
+ /// 金额
+ /// 资产记录日志id
+ /// 游戏名称
+ /// 资产收入支出记录id
+ /// 游戏每分钟消耗多少钻石
+ ///
+ public static async Task<(bool, int, int)> UserPlayGameDiamondConsumeMoney(this CloudGamingBase cloudGamingBase, decimal money, string gameName, int currencyLogId, int diamondListId, string gameXiaoHao)
+ {
+ bool issuccess = false;
+ int _currencyLogId = currencyLogId;
+ try
+ {
+ var currency = new T_User_Currency();
+ GameDiamondConsumeMoney gameDiamondConsumeMoney = new GameDiamondConsumeMoney(cloudGamingBase.Dao, cloudGamingBase._UserId, UserCurrencyType.钻石, currency);
+ (issuccess, _currencyLogId) = await gameDiamondConsumeMoney.ConsumeMoneyAsync(money, currencyLogId);
+ if (issuccess)
+ {
+ cloudGamingBase.UserInfo.Diamond = (int)currency.CurrencyMoney;
+ //await cloudGamingBase.SaveUserInfoCacheChangesAsync();
+ UserCurrencyConsumeType consumeType = money > 0 ? UserCurrencyConsumeType.收入 : UserCurrencyConsumeType.消耗;
+ T_User_DiamondList userDiamondList = null;
+ if (diamondListId > 0)
+ {
+ userDiamondList = await cloudGamingBase.Dao.DaoUser.Context.T_User_DiamondList.FirstOrDefaultAsync(it => it.Id == diamondListId);
+ }
+ if (userDiamondList == null)
+ {
+ userDiamondList = new T_User_DiamondList()
+ {
+ CreateAt = DateTime.Now,
+ Consume = 0,
+ ConsumeType = (int)consumeType,
+ CurrencyType = (int)UserCurrencyType.钻石,
+ OrderCode = "",
+ Title = $"游玩《{gameName}》",
+ UpdateAt = DateTime.Now,
+ UserId = cloudGamingBase.UserInfo.UserId,
+ Extend = gameXiaoHao,
+ };
+ await cloudGamingBase.Dao.DaoUser.Context.AddAsync(userDiamondList);
+ }
+ userDiamondList.Consume += Math.Abs(money);
+ userDiamondList.UpdateAt = DateTime.Now;
+ await cloudGamingBase.Dao.DaoUser.Context.SaveChangesAsync();
+ diamondListId = userDiamondList.Id;
+ }
+ }
+ catch (Exception ex)
+ {
+
+ return (false, _currencyLogId, diamondListId); ;
+ }
+ return (issuccess, _currencyLogId, diamondListId);
}
+ ///
+ /// 扣除当前用户钻石
+ ///
+ ///
+ ///
+ ///
+ public static async Task UserConsumeMoneyAsync(this CloudGamingBase cloudGamingBase, int userId, decimal money)
+ {
+ bool isSuccess = await UserConsumeDiamondMoneyAsync(userId, money, cloudGamingBase);
+ if (isSuccess)
+ {
+ await cloudGamingBase.SaveUserInfoCacheChangesAsync();
+ }
+ return isSuccess;
+ }
+
+
+ ///
+ /// 扣除当前用户钻石
+ ///
+ ///
+ ///
+ ///
+ public static async Task UserConsumeDiamondMoneyAsync(int userId, decimal money, CloudGamingBase cloudGamingBase)
+ {
+ T_User_Currency currency = new T_User_Currency();
+ var userConsumeMoney = new DiamondConsumeMoney(cloudGamingBase.Dao, userId, UserCurrencyType.钻石, currency);
+ try
+ {
+ var isSuccess = await userConsumeMoney.ConsumeMoneyAsync(money);
+
+ if (!isSuccess)
+ {
+ return false;
+ }
+ //清除缓存
+ string key = AccountExtend.GetUserInfoRedisKey(userId);
+ var userInfo = await cloudGamingBase.RedisCache.StringGetAsync(key);
+ if (userInfo != null)
+ {
+ userInfo.Diamond = (int)currency.CurrencyMoney;
+ await cloudGamingBase.RedisCache.StringSetAsync(key, userInfo, TimeSpan.FromMinutes(30));
+ }
+ }
+ catch (Exception ex)
+ {
+
+ return false;
+ }
+ return true;
+ }
+
}
diff --git a/src/CloudGaming/Code/CloudGaming.Code/AppExtend/AppRequestConfig.cs b/src/CloudGaming/Code/CloudGaming.Code/AppExtend/AppRequestConfig.cs
index 9dded17..70c000e 100644
--- a/src/CloudGaming/Code/CloudGaming.Code/AppExtend/AppRequestConfig.cs
+++ b/src/CloudGaming/Code/CloudGaming.Code/AppExtend/AppRequestConfig.cs
@@ -26,7 +26,7 @@ namespace CloudGaming.Code.AppExtend
{
if (!(httpRequest?.Headers?.TryGetValue("Channel", out var _channel) ?? false))
{
- _channel = "ps_001";
+ _channel = "cs_001";
}
channel = _channel;
if (string.IsNullOrEmpty(channel))
diff --git a/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameBLL.cs b/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameBLL.cs
index 7449016..9274e6d 100644
--- a/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameBLL.cs
+++ b/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameBLL.cs
@@ -165,15 +165,23 @@ public class PlayGameBLL : CloudGamingBase
gameInfoCache?.PlayGameStart(gameResponse?.Data?.ScId ?? 0, userGameList.Id, playGameSettings.DisplayGrade, jyResponseData);
gameInfoCache.Ip = HttpContextAccessor.HttpContext.GetClientIpAddress();
gameInfoCache.Channel = AppRequestInfo.Channel;
- var diamondNumHour = gameInfo.ConsumeDiamondNumHour / 60.0;
- if (diamondNumHour > 0)
+ //var diamondNumHour = gameInfo.ConsumeDiamondNumHour / 60.0;
+ var (diamondNumHour, playGamePayStatus) = GetUserGameNum(UserInfo, gameInfo);
+
+ if (diamondNumHour >= 0)
{
var startDiamond = (int)diamondNumHour < 1 ? 1 : (int)diamondNumHour;
- await BalanceDeductionFee(userInfo, gameInfoCache, diamondNumHour, 0, startDiamond);
+ string c = $"启动游戏扣除钻石*{startDiamond},游戏每分钟消耗*{diamondNumHour}";
+ if (playGamePayStatus != PlayGamePayStatus.钻石)
+ {
+ c = $"启动游戏,{playGamePayStatus}-不扣除费用。";
+ }
+
+ await BalanceDeductionFee(userInfo, gameInfoCache, diamondNumHour, 0, startDiamond, playGamePayStatus);
gameInfoCache.GameUserOperation.Add(new PlayGameUserOperation()
{
ActionId = (int)PlayGameStatus.开始游戏扣费,
- Content = $"启动游戏扣除钻石*{startDiamond},游戏每分钟消耗*{diamondNumHour}",
+ Content = c,
OperationDateTime = DateTime.Now,
});
}
@@ -200,6 +208,38 @@ public class PlayGameBLL : CloudGamingBase
return response;
}
+
+ ///
+ /// 获取用户游戏扣款金额
+ ///
+ ///
+ ///
+ ///
+ ///
+ public (double, PlayGamePayStatus) GetUserGameNum(UserInfo userInfo, GameInfo gameInfo)
+ {
+ if (gameInfo == null)
+ {
+ throw new ArgumentNullException("游戏不能为空");
+ }
+ if (userInfo == null)
+ {
+ throw new ArgumentNullException("用户不能为空");
+ }
+ var diamondNumHour = gameInfo.ConsumeDiamondNumHour / 60.0;
+ PlayGamePayStatus msg = PlayGamePayStatus.免费游戏;
+ if (diamondNumHour > 0)
+ {
+ msg = PlayGamePayStatus.钻石;
+ if (userInfo.UserVipInfo != null && userInfo.UserVipInfo != null && userInfo.UserVipInfo.ExpireDateTime > DateTime.Now)
+ {
+ diamondNumHour = 0;
+ msg = PlayGamePayStatus.会员免费;
+ }
+ }
+ return (diamondNumHour, msg);
+ }
+
///
/// 游戏心跳
///
@@ -236,8 +276,9 @@ public class PlayGameBLL : CloudGamingBase
//LastChargingAt
if (gameInfo.ConsumeDiamondNumHour > 0)
{
+ var (diamondNumHour, playGamePayStatus) = GetUserGameNum(UserInfo, gameInfo);
//每分钟扣费
- var diamondNumHour = gameInfo.ConsumeDiamondNumHour / 60.0;
+ //var diamondNumHour = gameInfo.ConsumeDiamondNumHour / 60.0;
playGameHeartbeatResponse.GameConsumeDiamond = diamondNumHour.ToString("0.##");
var chargingAt = DateTime.Now;
var minutes = (int)chargingAt.Subtract(gameInfoCache.LastChargingAt ?? DateTime.Now).TotalMinutes;
@@ -260,35 +301,43 @@ public class PlayGameBLL : CloudGamingBase
//判断扣费时间
if (minutes >= 1)
{
- var gameDiamondNumHour = (int)(diamondNumHour * minutes);
- //当前游玩的扣费金额,如果扣费金额不足1钻石,则等待下一次扣费
- if (gameDiamondNumHour >= 1)
+ if (playGamePayStatus == PlayGamePayStatus.钻石)
{
- //如果游玩余额大于用户可扣款的余额
- if (gameDiamondNumHour >= userInfo.Diamond)
+ var gameDiamondNumHour = (int)(diamondNumHour * minutes);
+ //当前游玩的扣费金额,如果扣费金额不足1钻石,则等待下一次扣费
+ if (gameDiamondNumHour >= 1)
{
- //去数据库中在验证一下
- //(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)
+ //如果游玩余额大于用户可扣款的余额
+ if (gameDiamondNumHour >= userInfo.Diamond)
{
- throw MessageBox.ErrorShow("用户数据错误");
- }
- if ((int)(currency.CurrencyMoney) != userInfo.Diamond)
- {
- userInfo.Diamond = (int)currency.CurrencyMoney;
- }
- if (gameDiamondNumHour > userInfo.Diamond)
- {
- //用户余额不足
- gameDiamondNumHour = userInfo.Diamond;
- playGameHeartbeatResponse.UserPlayGameTime = 0;
- }
+ //去数据库中在验证一下
+ //(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;
+ }
+ }
+ await BalanceDeductionFee(userInfo, gameInfoCache, diamondNumHour, minutes, gameDiamondNumHour, playGamePayStatus);
}
- await BalanceDeductionFee(userInfo, gameInfoCache, diamondNumHour, minutes, gameDiamondNumHour);
+ }
+ else
+ {
+ await BalanceDeductionFee(userInfo, gameInfoCache, diamondNumHour, minutes, 60, playGamePayStatus);
}
}
+
//用户剩余游玩时间
if (userInfo.Diamond > 0)
{
@@ -302,7 +351,7 @@ public class PlayGameBLL : CloudGamingBase
//重置一下用户钻石
playGameHeartbeatResponse.Diamond = userInfo.Diamond;
- gameInfoCache.PlayGameHeartbeat($";累计扣除钻石*{gameInfoCache.SpendingDiamonds};用户剩余钻石*{userInfo.Diamond};当前游戏每分钟消耗钻石*{diamondNumHour.ToString("0.##")};上一次扣费时间:{gameInfoCache.LastChargingAt?.ToString("yyyy-MM-dd HH:mm:ss")}");
+ gameInfoCache.PlayGameHeartbeat($";游戏消耗-{playGamePayStatus},累计扣除钻石*{gameInfoCache.SpendingDiamonds};用户剩余钻石*{userInfo.Diamond};当前游戏每分钟消耗钻石*{diamondNumHour.ToString("0.##")};上一次扣费时间:{gameInfoCache.LastChargingAt?.ToString("yyyy-MM-dd HH:mm:ss")}");
await gameInfoCache.SaveChangesAsync(this);
}
else
@@ -316,26 +365,88 @@ public class PlayGameBLL : CloudGamingBase
}
- private async Task BalanceDeductionFee(UserInfoCache userInfo, PlayGameUserInfo gameInfoCache, double diamondNumHour, int minutes, decimal gameDiamondNumHour)
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ private async Task BalanceDeductionFee(UserInfoCache userInfo, PlayGameUserInfo gameInfoCache, double diamondNumHour, int minutes, decimal gameDiamondNumHour, PlayGamePayStatus playGamePayStatus)
{
- var (issuccess, currlogId, diamId) = await this.UserPlayGameDiamondConsumeMoney(-gameDiamondNumHour, gameInfoCache.GameName, gameInfoCache.CurrencyLogId, gameInfoCache.DiamondListId, $"{diamondNumHour}/分钟");
- if (!issuccess)
+ int currlogId = 0;
+ int diamId = 0;
+ //扣费状态被改变,说明和上一次的扣费不一样,需要重置一下资产记录
+ if (gameInfoCache.PlayGamePayStatus == null || gameInfoCache.PlayGamePayStatus != playGamePayStatus)
{
- var Content = $"扣除费用{gameDiamondNumHour},用户剩余金额{userInfo.Diamond};";
- if (minutes == 0)
- {
- Content = $"启动扣除费用{gameDiamondNumHour},用户剩余金额{userInfo.Diamond};";
- }
- gameInfoCache.GameUserOperation.Add(new PlayGameUserOperation()
- {
- ActionId = (int)PlayGameStatus.用户扣款错误,
- Content = Content
- });
- await gameInfoCache.SaveChangesAsync(this);
- throw MessageBox.ErrorShow("扣款出现错误");
+ gameInfoCache.DiamondListId = 0;
+ gameInfoCache.CurrencyLogId = 0;
+ }
+ gameInfoCache.PlayGamePayStatus = playGamePayStatus;
+ if (playGamePayStatus == PlayGamePayStatus.钻石)
+ {
+ var (issuccess, currlogId1, diamId1) = await this.UserPlayGameDiamondConsumeMoney(-gameDiamondNumHour, gameInfoCache.GameName, gameInfoCache.CurrencyLogId, gameInfoCache.DiamondListId, $"{diamondNumHour}/分钟");
+ if (!issuccess)
+ {
+ var Content = $"扣除费用{gameDiamondNumHour},用户剩余金额{userInfo.Diamond};";
+ if (minutes == 0)
+ {
+ Content = $"启动扣除费用{gameDiamondNumHour},用户剩余金额{userInfo.Diamond};";
+ }
+ gameInfoCache.GameUserOperation.Add(new PlayGameUserOperation()
+ {
+ ActionId = (int)PlayGameStatus.用户扣款错误,
+ Content = Content
+ });
+ await gameInfoCache.SaveChangesAsync(this);
+ throw MessageBox.ErrorShow("扣款出现错误");
+ }
+ currlogId = currlogId1;
+ diamId = diamId1;
+ gameInfoCache.SpendingDiamonds += gameDiamondNumHour;
+ userInfo.UserPlayGameTime += minutes;
+
+ }
+ else
+ {
+ T_User_DiamondList userDiamondList = null;
+ int diamondListId = gameInfoCache.DiamondListId;
+ if (diamondListId > 0)
+ {
+ userDiamondList = await Dao.DaoUser.Context.T_User_DiamondList.FirstOrDefaultAsync(it => it.Id == diamondListId);
+ }
+ if (userDiamondList == null)
+ {
+ userDiamondList = new T_User_DiamondList()
+ {
+ CreateAt = DateTime.Now,
+ Consume = 0,
+ ConsumeType = (int)UserCurrencyConsumeType.消耗,
+ CurrencyType = (int)UserCurrencyType.钻石,
+ OrderCode = "",
+ Title = $"游玩《{gameInfoCache.GameName}》 * {playGamePayStatus}",
+ UpdateAt = DateTime.Now,
+ UserId = UserInfo.UserId,
+ Extend = $"{playGamePayStatus}",
+ };
+ await Dao.DaoUser.Context.AddAsync(userDiamondList);
+ }
+ userDiamondList.Consume += 0;
+ userDiamondList.UpdateAt = DateTime.Now;
+ await Dao.DaoUser.Context.SaveChangesAsync();
+ gameInfoCache.SpendingDiamonds += 0;
+ userInfo.UserPlayGameTime += minutes;
+ if (gameInfoCache.PlayGamePayStatus == PlayGamePayStatus.会员免费)
+ {
+ gameInfoCache.VipCardPlayTime += minutes;
+ }
+ else if (gameInfoCache.PlayGamePayStatus == PlayGamePayStatus.免费游戏)
+ {
+ gameInfoCache.FreePlayTime += minutes;
+ }
}
- gameInfoCache.SpendingDiamonds += gameDiamondNumHour;
- userInfo.UserPlayGameTime += minutes;
await this.SaveUserInfoCacheChangesAsync();
gameInfoCache.CurrencyLogId = currlogId;
gameInfoCache.DiamondListId = diamId;
@@ -585,7 +696,7 @@ public class PlayGameBLL : CloudGamingBase
///
/// 重连会话
///
- ///
+ ///
///
public async Task> ReconPlayGame(GameRequest gameRequest)
{
@@ -643,7 +754,7 @@ public class PlayGameBLL : CloudGamingBase
{
throw MessageBox.ErrorShow("未找到游戏信息");
}
- JYRequestCommonParameter playGameCommonSetting = new JYRequestCommonParameter(sn,userId)
+ JYRequestCommonParameter playGameCommonSetting = new JYRequestCommonParameter(sn, userId)
{
ScId = gameInfoCache.ScId,
Ip = this.HttpContextAccessor.HttpContext.GetClientIpAddress()
@@ -652,7 +763,7 @@ public class PlayGameBLL : CloudGamingBase
return new BaseResponse(ResponseCode.Success, "", dic.Data);
}
-
+
public async Task GameSetting(string gameId)
{
if (_UserId == 0)
diff --git a/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameExtend.cs b/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameExtend.cs
index 24d1deb..a4c2afe 100644
--- a/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameExtend.cs
+++ b/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameExtend.cs
@@ -667,6 +667,14 @@ namespace CloudGaming.Code.Game
await dao.DaoPhone.Context.T_User_PlayGameTime.AddAsync(playGameTime);
}
playGameTime.PlayTime += playTime;
+ if (playGameUserInfo.FreePlayTime > 0)
+ {
+ playGameTime.FreePlayTime = playGameUserInfo.FreePlayTime / 60;
+ }
+ if (playGameUserInfo.VipCardPlayTime > 0)
+ {
+ playGameTime.NightCardPlayTime = playGameUserInfo.VipCardPlayTime / 60;
+ }
playGameTime.UpdateTime = DateTime.Now;
playGameTime.DiamondPlayTime += playTime;
await dao.DaoPhone.Context.SaveChangesAsync();
diff --git a/src/CloudGaming/Console/CloudGaming.ImportGame/Program.cs b/src/CloudGaming/Console/CloudGaming.ImportGame/Program.cs
index fb386f9..199e823 100644
--- a/src/CloudGaming/Console/CloudGaming.ImportGame/Program.cs
+++ b/src/CloudGaming/Console/CloudGaming.ImportGame/Program.cs
@@ -99,69 +99,69 @@ using (var package = new ExcelPackage(new FileInfo(filePath)))
}
Console.WriteLine("验证成功,开始导入数据...");
//Console.ReadKey();
-List tags = new List();
-Console.WriteLine("开始验证标签...");
-tempGames.ForEach(it => tags.AddRange(it.GameTag));
-tags = tags.Distinct().ToList();
-var gameTags = gameDao.T_Game_Tags.ToList();
-var notTags = tags.Where(it => !gameTags.Any(item => item.TagName == it)).ToList();
-if (notTags != null && notTags.Count > 0)
-{
- var orderId = (gameTags.Max(it => (int?)it.OrderId) ?? 0) + 1;
- var tagId = (gameTags.Max(it => (int?)it.TagId) ?? 0) + 1;
- notTags.ForEach(t =>
- {
- //不在数据库中
- T_Game_Tags t_Game_Tags = new T_Game_Tags()
- {
- CreatTime = DateTime.Now,
- Desc = "",
- IsOnline = true,
- OrderId = orderId,
- TagId = tagId,
- TagName = t,
- UpdateTime = DateTime.Now,
- };
- gameDao.Add(t_Game_Tags);
- tagId++;
- orderId++;
- Console.WriteLine($"添加标签{t}==>tagId:{tagId}==>orderId:{orderId}");
- });
- gameDao.SaveChanges();
- gameTags = gameDao.T_Game_Tags.ToList();
-}
-Console.WriteLine("开始验证类型...");
-var gameTypes = gameDao.T_Game_Types.ToList();
-List types = new List();
-tempGames.ForEach(it => types.AddRange(it.GameType));
-types = types.Distinct().ToList();
+//List tags = new List();
+//Console.WriteLine("开始验证标签...");
+//tempGames.ForEach(it => tags.AddRange(it.GameTag));
+//tags = tags.Distinct().ToList();
+//var gameTags = gameDao.T_Game_Tags.ToList();
+//var notTags = tags.Where(it => !gameTags.Any(item => item.TagName == it)).ToList();
+//if (notTags != null && notTags.Count > 0)
+//{
+// var orderId = (gameTags.Max(it => (int?)it.OrderId) ?? 0) + 1;
+// var tagId = (gameTags.Max(it => (int?)it.TagId) ?? 0) + 1;
+// notTags.ForEach(t =>
+// {
+// //不在数据库中
+// T_Game_Tags t_Game_Tags = new T_Game_Tags()
+// {
+// CreatTime = DateTime.Now,
+// Desc = "",
+// IsOnline = true,
+// OrderId = orderId,
+// TagId = tagId,
+// TagName = t,
+// UpdateTime = DateTime.Now,
+// };
+// gameDao.Add(t_Game_Tags);
+// tagId++;
+// orderId++;
+// Console.WriteLine($"添加标签{t}==>tagId:{tagId}==>orderId:{orderId}");
+// });
+// gameDao.SaveChanges();
+// gameTags = gameDao.T_Game_Tags.ToList();
+//}
+//Console.WriteLine("开始验证类型...");
+//var gameTypes = gameDao.T_Game_Types.ToList();
+//List types = new List();
+//tempGames.ForEach(it => types.AddRange(it.GameType));
+//types = types.Distinct().ToList();
-var notTypes = types.Where(it => !gameTypes.Any(item => item.TypeName == it)).ToList();
-if (notTypes != null && notTypes.Count > 0)
-{
- var orderId = (gameTypes.Max(it => (int?)it.OrderId) ?? 0) + 1;
- var TypeId = (gameTypes.Max(it => (int?)it.TypeId) ?? 0) + 1;
- notTypes.ForEach(t =>
- {
- //不在数据库中
- T_Game_Types t_Game_Tags = new T_Game_Types()
- {
- CreatTime = DateTime.Now,
- IsOnline = true,
- OrderId = orderId,
- TypeId = TypeId,
- TypeName = t,
- UpdateTime = DateTime.Now,
- TypeDetails = ""
- };
- gameDao.Add(t_Game_Tags);
- TypeId++;
- orderId++;
- Console.WriteLine($"添加类型{t}==>tagId:{TypeId}==>orderId:{orderId}");
- });
- gameDao.SaveChanges();
- gameTypes = gameDao.T_Game_Types.ToList();
-}
+//var notTypes = types.Where(it => !gameTypes.Any(item => item.TypeName == it)).ToList();
+//if (notTypes != null && notTypes.Count > 0)
+//{
+// var orderId = (gameTypes.Max(it => (int?)it.OrderId) ?? 0) + 1;
+// var TypeId = (gameTypes.Max(it => (int?)it.TypeId) ?? 0) + 1;
+// notTypes.ForEach(t =>
+// {
+// //不在数据库中
+// T_Game_Types t_Game_Tags = new T_Game_Types()
+// {
+// CreatTime = DateTime.Now,
+// IsOnline = true,
+// OrderId = orderId,
+// TypeId = TypeId,
+// TypeName = t,
+// UpdateTime = DateTime.Now,
+// TypeDetails = ""
+// };
+// gameDao.Add(t_Game_Tags);
+// TypeId++;
+// orderId++;
+// Console.WriteLine($"添加类型{t}==>tagId:{TypeId}==>orderId:{orderId}");
+// });
+// gameDao.SaveChanges();
+// gameTypes = gameDao.T_Game_Types.ToList();
+//}
var gameChildList = gameDao.T_Game_ChildList.ToList();
@@ -202,66 +202,68 @@ tempGames.ForEach((Action)(game =>
gameDao.Add(gamel);
gameList.Add(gamel);
}
- gamel.GameIntroduce = game.GameIntroduce;
- gamel.GameCloudId = game.GameCloudId;
- gamel.GameName = game.GameName;
- //添加游戏标签
- //if(gameTypes)
- var tempTypes = gameChildList.Where(it => it.GameId == game.GameId && it.ChildType == 1).ToList();
- //先删除当前游戏所有的类型
- if (tempTypes != null && tempTypes.Count > 0)
- {
- gameDao.RemoveRange(tempTypes);
- }
- if (game.GameType != null && game.GameType.Length > 0)
- {
- int index = 0;
- foreach (var gameTypeName in game.GameType)
- {
- var g = gameTypes.FirstOrDefault(it => it.TypeName == gameTypeName);
- if (g != null)
- {
- T_Game_ChildList cg = new T_Game_ChildList()
- {
- ChildId = g.TypeId,
- ChildType = 1,
- GameId = game.GameId,
- OrderId = index,
- Desc = ""
- };
- gameDao.Add(cg);
- index++;
- }
- }
- }
- //游戏标签管理
- var tempTags = gameChildList.Where(it => it.GameId == game.GameId && it.ChildType == 2).ToList();
- //先删除当前游戏所有的标签
- if (tempTags != null && tempTags.Count > 0)
- {
- gameDao.RemoveRange(tempTags);
- }
- if (game.GameTag != null && game.GameTag.Length > 0)
- {
- int index = 0;
- foreach (var gameTagName in game.GameTag)
- {
- var g = gameTags.FirstOrDefault(it => it.TagName == gameTagName);
- if (g != null)
- {
- T_Game_ChildList cg = new T_Game_ChildList()
- {
- ChildId = g.TagId,
- ChildType = 2,
- GameId = game.GameId,
- OrderId = index,
- Desc = ""
- };
- gameDao.Add(cg);
- index++;
- }
- }
- }
+ //gamel.GameIntroduce = game.GameIntroduce;
+ //gamel.GameCloudId = game.GameCloudId;
+ //gamel.GameName = game.GameName;
+ ////添加游戏标签
+ ////if(gameTypes)
+ //var tempTypes = gameChildList.Where(it => it.GameId == game.GameId && it.ChildType == 1).ToList();
+ ////先删除当前游戏所有的类型
+ //if (tempTypes != null && tempTypes.Count > 0)
+ //{
+ // gameDao.RemoveRange(tempTypes);
+ //}
+ //if (game.GameType != null && game.GameType.Length > 0)
+ //{
+ // int index = 0;
+ // foreach (var gameTypeName in game.GameType)
+ // {
+ // var g = gameTypes.FirstOrDefault(it => it.TypeName == gameTypeName);
+ // if (g != null)
+ // {
+ // T_Game_ChildList cg = new T_Game_ChildList()
+ // {
+ // ChildId = g.TypeId,
+ // ChildType = 1,
+ // GameId = game.GameId,
+ // OrderId = index,
+ // Desc = ""
+ // };
+ // gameDao.Add(cg);
+ // index++;
+ // }
+ // }
+ //}
+ ////游戏标签管理
+ //var tempTags = gameChildList.Where(it => it.GameId == game.GameId && it.ChildType == 2).ToList();
+ ////先删除当前游戏所有的标签
+ //if (tempTags != null && tempTags.Count > 0)
+ //{
+ // gameDao.RemoveRange(tempTags);
+ //}
+ //if (game.GameTag != null && game.GameTag.Length > 0)
+ //{
+ // int index = 0;
+ // foreach (var gameTagName in game.GameTag)
+ // {
+ // var g = gameTags.FirstOrDefault(it => it.TagName == gameTagName);
+ // if (g != null)
+ // {
+ // T_Game_ChildList cg = new T_Game_ChildList()
+ // {
+ // ChildId = g.TagId,
+ // ChildType = 2,
+ // GameId = game.GameId,
+ // OrderId = index,
+ // Desc = ""
+ // };
+ // gameDao.Add(cg);
+ // index++;
+ // }
+ // }
+ //}
+
+
//添加游戏类型
//gameDao.SaveChanges();
//添加配置表
@@ -271,7 +273,7 @@ tempGames.ForEach((Action)(game =>
{
gameCbt1 = new T_GameCBT()
{
- GameId = game.GameId,
+ GameId = gamel.GameId,
IsOnline = true,
Score = game.Score,
OrderId = gameCbtOrderId,
@@ -282,9 +284,9 @@ tempGames.ForEach((Action)(game =>
IsLimitToVip = false,
GameLoadTime = game.GameLoadTime,
Title2 = game.Title2,
- GameName = game.GameName,
+ GameName = gamel.GameName,
ImageId_Banner = 0,
- ConsumeDiamondNumHour = game.ConsumeDiamondNumHour,
+ ConsumeDiamondNumHour = 60,
ConsumeDiamondNumHourVip = 0,
GameGroup = 0,
VipTypeLimit = 0,
diff --git a/src/CloudGaming/Console/CloudGaming.Test/ToDictionaryOrListTest.cs b/src/CloudGaming/Console/CloudGaming.Test/ToDictionaryOrListTest.cs
index 1d44763..222eadd 100644
--- a/src/CloudGaming/Console/CloudGaming.Test/ToDictionaryOrListTest.cs
+++ b/src/CloudGaming/Console/CloudGaming.Test/ToDictionaryOrListTest.cs
@@ -46,7 +46,7 @@ namespace CloudGaming.Test
},
};
- var dic = epgCategoryDto.ToDictionaryOrList();
+ var dic = epgCategoryDto.ToDictionaryOrList(true);
return dic;
}
@@ -85,7 +85,7 @@ namespace CloudGaming.Test
});
}
- var dic = epgCategoryDtos.ToDictionaryOrList();
+ var dic = epgCategoryDtos.ToDictionaryOrList(true);
return dic;
}
@@ -111,368 +111,10 @@ namespace CloudGaming.Test
}
},
};
- var dic = ObjectExtensions1.ToDictionaryOrList(epgCategoryDto);
- return dic;
+ //var dic = ObjectExtensions.ToDictionaryOrList(epgCategoryDto);
+ return null ;
}
-
- //[Benchmark]
- public object ListToDictionaryOrListExtend1()
- {
- List epgCategoryDtos = new List();
- for (int i = 0; i < 20; i++)
- {
- epgCategoryDtos.Add(new EpgCategoryDto()
- {
- CategoryName = "Banner" + i,
- CategoryType = "Banner" + i,
- IsQuickStartPopUp = true,
- ShowNum_Index = 10 + i,
- EpgList = new List()
- {
- new EpgInfo(){
- CornerIcon=i,
- EpgId=i,
- IdName="IO"+i,
- ResType=4,
- Title="title"+i
- },
- new EpgInfo(){
- CornerIcon=i+2,
- EpgId=i+2,
- IdName="IO"+i+2,
- ResType=4+2,
- Title="title"+i+2
- }
- },
- });
- }
-
-
- var dic = ObjectExtensions1.ToDictionaryOrList(epgCategoryDtos);
- return dic;
-
- }
-
-
-
- //[Benchmark]
- public object ObjectToDictionaryOrListExtend3()
- {
- EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
- {
- CategoryName = "Banner",
- CategoryType = "Banner",
- IsQuickStartPopUp = true,
- ShowNum_Index = 10,
- EpgList = new List()
- {
- new EpgInfo(){
- CornerIcon=10,
- EpgId=10,
- IdName="IO",
- ResType=4,
- Title="title"
- }
- },
- };
- var dic = ObjectExtensions3.ToDictionaryOrList(epgCategoryDto);
- return dic;
-
- }
-
-
- //[Benchmark]
- public object ListToDictionaryOrListExtend3()
- {
- List epgCategoryDtos = new List();
- for (int i = 0; i < 20; i++)
- {
- epgCategoryDtos.Add(new EpgCategoryDto()
- {
- CategoryName = "Banner" + i,
- CategoryType = "Banner" + i,
- IsQuickStartPopUp = true,
- ShowNum_Index = 10 + i,
- EpgList = new List()
- {
- new EpgInfo(){
- CornerIcon=i,
- EpgId=i,
- IdName="IO"+i,
- ResType=4,
- Title="title"+i
- },
- new EpgInfo(){
- CornerIcon=i+2,
- EpgId=i+2,
- IdName="IO"+i+2,
- ResType=4+2,
- Title="title"+i+2
- }
- },
- });
- }
-
-
- var dic = ObjectExtensions3.ToDictionaryOrList(epgCategoryDtos);
- return dic;
-
- }
-
- // [Benchmark]
- public object ObjectToDictionaryOrListExtend4()
- {
- EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
- {
- CategoryName = "Banner",
- CategoryType = "Banner",
- IsQuickStartPopUp = true,
- ShowNum_Index = 10,
- EpgList = new List()
- {
- new EpgInfo(){
- CornerIcon=10,
- EpgId=10,
- IdName="IO",
- ResType=4,
- Title="title"
- }
- },
- };
- var dic = ObjectExtensions5.ToDictionaryOrList(epgCategoryDto);
- return dic;
-
- }
-
-
- //[Benchmark]
- public object ListToDictionaryOrListExtend4()
- {
- List epgCategoryDtos = new List();
- for (int i = 0; i < 20; i++)
- {
- epgCategoryDtos.Add(new EpgCategoryDto()
- {
- CategoryName = "Banner" + i,
- CategoryType = "Banner" + i,
- IsQuickStartPopUp = true,
- ShowNum_Index = 10 + i,
- EpgList = new List()
- {
- new EpgInfo(){
- CornerIcon=i,
- EpgId=i,
- IdName="IO"+i,
- ResType=4,
- Title="title"+i
- },
- new EpgInfo(){
- CornerIcon=i+2,
- EpgId=i+2,
- IdName="IO"+i+2,
- ResType=4+2,
- Title="title"+i+2
- }
- },
- });
- }
-
-
- var dic = ObjectExtensions5.ToDictionaryOrList(epgCategoryDtos);
- return dic;
-
- }
-
- //[Benchmark]
- public object ObjectToDictionaryOrListExtend6()
- {
- EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
- {
- CategoryName = "Banner",
- CategoryType = "Banner",
- IsQuickStartPopUp = true,
- ShowNum_Index = 10,
- EpgList = new List()
- {
- new EpgInfo(){
- CornerIcon=10,
- EpgId=10,
- IdName="IO",
- ResType=4,
- Title="title"
- }
- },
- };
- var dic = ObjectExtensions6.ToDictionaryOrList(epgCategoryDto);
- return dic;
-
- }
-
- //
- //[Benchmark]
- public object ListToDictionaryOrListExtend6()
- {
- List epgCategoryDtos = new List();
- for (int i = 0; i < 20; i++)
- {
- epgCategoryDtos.Add(new EpgCategoryDto()
- {
- CategoryName = "Banner" + i,
- CategoryType = "Banner" + i,
- IsQuickStartPopUp = true,
- ShowNum_Index = 10 + i,
- EpgList = new List()
- {
- new EpgInfo(){
- CornerIcon=i,
- EpgId=i,
- IdName="IO"+i,
- ResType=4,
- Title="title"+i
- },
- new EpgInfo(){
- CornerIcon=i+2,
- EpgId=i+2,
- IdName="IO"+i+2,
- ResType=4+2,
- Title="title"+i+2
- }
- },
- });
- }
-
-
- var dic = ObjectExtensions6.ToDictionaryOrList(epgCategoryDtos);
- return dic;
- }
-
-
- //[Benchmark]
- public object ObjectToDictionaryOrListExtend7()
- {
- EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
- {
- CategoryName = "Banner",
- CategoryType = "Banner",
- IsQuickStartPopUp = true,
- ShowNum_Index = 10,
- EpgList = new List()
- {
- new EpgInfo(){
- CornerIcon=10,
- EpgId=10,
- IdName="IO",
- ResType=4,
- Title="title"
- }
- },
- };
- var dic = ObjectExtensions6.ToDictionaryOrList(epgCategoryDto);
- return dic;
-
- }
-
-
- //[Benchmark]
- public object ListToDictionaryOrListExtend7()
- {
- List epgCategoryDtos = new List();
- for (int i = 0; i < 20; i++)
- {
- epgCategoryDtos.Add(new EpgCategoryDto()
- {
- CategoryName = "Banner" + i,
- CategoryType = "Banner" + i,
- IsQuickStartPopUp = true,
- ShowNum_Index = 10 + i,
- EpgList = new List()
- {
- new EpgInfo(){
- CornerIcon=i,
- EpgId=i,
- IdName="IO"+i,
- ResType=4,
- Title="title"+i
- },
- new EpgInfo(){
- CornerIcon=i+2,
- EpgId=i+2,
- IdName="IO"+i+2,
- ResType=4+2,
- Title="title"+i+2
- }
- },
- });
- }
-
-
- var dic = ObjectExtensions7.ToDictionaryOrList(epgCategoryDtos);
- return dic;
- }
-
- //[Benchmark]
- public object ObjectToDictionaryOrListExtend8()
- {
- EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
- {
- CategoryName = "Banner",
- CategoryType = "Banner",
- IsQuickStartPopUp = true,
- ShowNum_Index = 10,
- EpgList = new List()
- {
- new EpgInfo(){
- CornerIcon=10,
- EpgId=10,
- IdName="IO",
- ResType=4,
- Title="title"
- }
- },
- };
- var dic = ObjectExtensions.ToDictionaryOrList(epgCategoryDto);
- return dic;
-
- }
-
-
- // [Benchmark]
- public object ListToDictionaryOrListExtend8()
- {
- List epgCategoryDtos = new List();
- for (int i = 0; i < 20; i++)
- {
- epgCategoryDtos.Add(new EpgCategoryDto()
- {
- CategoryName = "Banner" + i,
- CategoryType = "Banner" + i,
- IsQuickStartPopUp = true,
- ShowNum_Index = 10 + i,
- EpgList = new List()
- {
- new EpgInfo(){
- CornerIcon=i,
- EpgId=i,
- IdName="IO"+i,
- ResType=4,
- Title="title"+i
- },
- new EpgInfo(){
- CornerIcon=i+2,
- EpgId=i+2,
- IdName="IO"+i+2,
- ResType=4+2,
- Title="title"+i+2
- }
- },
- });
- }
-
-
- var dic = ObjectExtensions.ToDictionaryOrList(epgCategoryDtos);
- return dic;
- }
}
}
diff --git a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGamePayStatus.cs b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGamePayStatus.cs
new file mode 100644
index 0000000..1ffa6ec
--- /dev/null
+++ b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGamePayStatus.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CloudGaming.DtoModel.PlayGame;
+
+///
+/// 玩游戏状态
+///
+public enum PlayGamePayStatus
+{
+ ///
+ ///
+ ///
+ 免费游戏 = 0,
+ ///
+ ///
+ ///
+ 钻石 = 1,
+ ///
+ ///
+ ///
+ 会员免费 = 2
+}
diff --git a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameUserInfo.cs b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameUserInfo.cs
index 591250f..e038f86 100644
--- a/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameUserInfo.cs
+++ b/src/CloudGaming/Model/CloudGaming.DtoModel/PlayGame/PlayGameUserInfo.cs
@@ -157,6 +157,19 @@ public class PlayGameUserInfo
///
public string Channel { get; set; }
+ ///
+ /// 当前游戏付费状态
+ ///
+ public PlayGamePayStatus? PlayGamePayStatus { get; set; }
+ ///
+ /// 会员游玩时间
+ ///
+ public int VipCardPlayTime { get; set; }
+ ///
+ /// 免费游玩时间
+ ///
+ public int FreePlayTime { get; set; }
+
///
/// 转化成数据库实体类
///
@@ -196,7 +209,7 @@ public class PlayGameUserInfo
GameStatus = (int)GameStatus,
GameUserOperationJson = GameUserOperation == null ? "" : JsonConvert.SerializeObject(GameUserOperation, settings),
Channel = Channel,
- CreateDay = int.Parse(CreateDateTime.ToString("yyyyMMdd"))
+ CreateDay = int.Parse(CreateDateTime.ToString("yyyyMMdd")),
};
return log;
}