From abc9cea3c1dbb77e1bb2be9417ffce6fb37e7008 Mon Sep 17 00:00:00 2001 From: zpc Date: Sat, 16 Nov 2024 04:41:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E9=87=91?= =?UTF-8?q?=E9=A2=9D=E6=B6=88=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CloudGaming.Code/Account/AccountBLL.cs | 2 +- .../CloudGaming.Code/Account/AccountExtend.cs | 16 ++++ .../Account/Contract/IUserConsumeMoney.cs | 20 ++++ .../UserCurrency/DiamondConsumeMoney.cs | 21 ++++ .../Account/UserCurrencyExtend.cs | 96 +++++++++++++++++++ 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 src/CloudGaming/Code/CloudGaming.Code/Account/Contract/IUserConsumeMoney.cs create mode 100644 src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrency/DiamondConsumeMoney.cs create mode 100644 src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrencyExtend.cs diff --git a/src/CloudGaming/Code/CloudGaming.Code/Account/AccountBLL.cs b/src/CloudGaming/Code/CloudGaming.Code/Account/AccountBLL.cs index 1724ace..47f1212 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Account/AccountBLL.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Account/AccountBLL.cs @@ -529,7 +529,7 @@ namespace CloudGaming.Code.Account UserId = _UserId, Ip = HttpContextAccessor.HttpContext.GetClientIpAddress() }; - + await this.GetConsumeMoney(UserCurrencyType.钻石).ConsumeMoneyAsync(10); await Dao.DaoUser.Context.T_User_LimitActionLog.AddAsync(limitActionLog); await Dao.DaoUser.Context.SaveChangesAsync(); return "奖励已经发送,钻石*10"; diff --git a/src/CloudGaming/Code/CloudGaming.Code/Account/AccountExtend.cs b/src/CloudGaming/Code/CloudGaming.Code/Account/AccountExtend.cs index 3745fa1..5d3e4b2 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Account/AccountExtend.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Account/AccountExtend.cs @@ -1,5 +1,6 @@ using CloudGaming.Code.Account.Contract; using CloudGaming.Code.Account.Login; +using CloudGaming.Code.Account.UserCurrency; using CloudGaming.Code.DataAccess; using CloudGaming.DtoModel.Account.Login; using CloudGaming.DtoModel.Account.User; @@ -219,5 +220,20 @@ namespace CloudGaming.Code.Account await cloudGamingBase.RedisCache.StringSetAsync(key, userInfo, TimeSpan.FromHours(1)); return userInfo; } + + /// + /// + /// + /// + /// + /// + public static IUserConsumeMoney GetConsumeMoney(this CloudGamingBase cloudGamingBase, UserCurrencyType userCurrencyType) + { + if (UserCurrencyType.钻石 == userCurrencyType) + { + return new DiamondConsumeMoney(cloudGamingBase); + } + return new DiamondConsumeMoney(cloudGamingBase); + } } } diff --git a/src/CloudGaming/Code/CloudGaming.Code/Account/Contract/IUserConsumeMoney.cs b/src/CloudGaming/Code/CloudGaming.Code/Account/Contract/IUserConsumeMoney.cs new file mode 100644 index 0000000..297fe8a --- /dev/null +++ b/src/CloudGaming/Code/CloudGaming.Code/Account/Contract/IUserConsumeMoney.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CloudGaming.Code.Account.Contract; + +/// +/// 用户货币变更 +/// +public interface IUserConsumeMoney +{ + /// + /// 扣除或者添加货币 + /// + /// + /// + public Task ConsumeMoneyAsync(decimal money); +} diff --git a/src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrency/DiamondConsumeMoney.cs b/src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrency/DiamondConsumeMoney.cs new file mode 100644 index 0000000..4c2a385 --- /dev/null +++ b/src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrency/DiamondConsumeMoney.cs @@ -0,0 +1,21 @@ +using CloudGaming.Code.Account.Contract; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CloudGaming.Code.Account.UserCurrency +{ + /// + /// + /// + public class DiamondConsumeMoney(CloudGamingBase cloudGamingBase) : IUserConsumeMoney + { + public Task ConsumeMoneyAsync(decimal money) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrencyExtend.cs b/src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrencyExtend.cs new file mode 100644 index 0000000..89416f6 --- /dev/null +++ b/src/CloudGaming/Code/CloudGaming.Code/Account/UserCurrencyExtend.cs @@ -0,0 +1,96 @@ +using CloudGaming.Code.DataAccess; +using CloudGaming.DtoModel.Account.User; + +using Microsoft.EntityFrameworkCore.Storage; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CloudGaming.Code.Account +{ + public static class UserCurrencyExtend + { + /// + /// 获取用户货币余额,没有货币的时候添加 + /// + /// + /// + /// + /// + 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) + { + 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; + } + + /// + /// 获取用户货币余额 + /// + /// + /// + /// + /// + 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 bool 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) + { + throw new ArgumentNullException("用户不能为空"); + } + int userId = user.Id; + return ConsumeMoneyNoWork(userId, userCurrencyType, money, dao, orderId: orderId, title: title); + } + public static bool ConsumeMoneyNoWork(int userId, UserCurrencyType userCurrencyType, decimal money, DAO dao, T_User_Currency? _currency = null, string remarks = "", string title = "", string orderId = "") + { + + return true; + } + } +}