添加用户金额消费
This commit is contained in:
parent
248ac1fe07
commit
abc9cea3c1
|
|
@ -529,7 +529,7 @@ namespace CloudGaming.Code.Account
|
||||||
UserId = _UserId,
|
UserId = _UserId,
|
||||||
Ip = HttpContextAccessor.HttpContext.GetClientIpAddress()
|
Ip = HttpContextAccessor.HttpContext.GetClientIpAddress()
|
||||||
};
|
};
|
||||||
|
await this.GetConsumeMoney(UserCurrencyType.钻石).ConsumeMoneyAsync(10);
|
||||||
await Dao.DaoUser.Context.T_User_LimitActionLog.AddAsync(limitActionLog);
|
await Dao.DaoUser.Context.T_User_LimitActionLog.AddAsync(limitActionLog);
|
||||||
await Dao.DaoUser.Context.SaveChangesAsync();
|
await Dao.DaoUser.Context.SaveChangesAsync();
|
||||||
return "奖励已经发送,钻石*10";
|
return "奖励已经发送,钻石*10";
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using CloudGaming.Code.Account.Contract;
|
using CloudGaming.Code.Account.Contract;
|
||||||
using CloudGaming.Code.Account.Login;
|
using CloudGaming.Code.Account.Login;
|
||||||
|
using CloudGaming.Code.Account.UserCurrency;
|
||||||
using CloudGaming.Code.DataAccess;
|
using CloudGaming.Code.DataAccess;
|
||||||
using CloudGaming.DtoModel.Account.Login;
|
using CloudGaming.DtoModel.Account.Login;
|
||||||
using CloudGaming.DtoModel.Account.User;
|
using CloudGaming.DtoModel.Account.User;
|
||||||
|
|
@ -219,5 +220,20 @@ namespace CloudGaming.Code.Account
|
||||||
await cloudGamingBase.RedisCache.StringSetAsync(key, userInfo, TimeSpan.FromHours(1));
|
await cloudGamingBase.RedisCache.StringSetAsync(key, userInfo, TimeSpan.FromHours(1));
|
||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cloudGamingBase"></param>
|
||||||
|
/// <param name="userCurrencyType"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IUserConsumeMoney GetConsumeMoney(this CloudGamingBase cloudGamingBase, UserCurrencyType userCurrencyType)
|
||||||
|
{
|
||||||
|
if (UserCurrencyType.钻石 == userCurrencyType)
|
||||||
|
{
|
||||||
|
return new DiamondConsumeMoney(cloudGamingBase);
|
||||||
|
}
|
||||||
|
return new DiamondConsumeMoney(cloudGamingBase);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用户货币变更
|
||||||
|
/// </summary>
|
||||||
|
public interface IUserConsumeMoney
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 扣除或者添加货币
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="money"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Task<bool> ConsumeMoneyAsync(decimal money);
|
||||||
|
}
|
||||||
|
|
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class DiamondConsumeMoney(CloudGamingBase cloudGamingBase) : IUserConsumeMoney
|
||||||
|
{
|
||||||
|
public Task<bool> ConsumeMoneyAsync(decimal money)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取用户货币余额,没有货币的时候添加
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
|
/// <param name="userCurrencyType"></param>
|
||||||
|
/// <param name="dao"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<decimal> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取用户货币余额
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
|
/// <param name="userCurrencyType"></param>
|
||||||
|
/// <param name="dao"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<T_User_Currency> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取用户所有货币信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
|
/// <param name="userCurrencyType"></param>
|
||||||
|
/// <param name="dao"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<List<T_User_Currency>> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 扣除或者充值货币
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
|
/// <param name="userCurrencyType">货币类型</param>
|
||||||
|
/// <param name="money">扣除金额(负数扣除,正数添加)</param>
|
||||||
|
/// <param name="dao">数据库</param>
|
||||||
|
/// <param name="_currency"></param>
|
||||||
|
/// <param name="orderId">订单号</param>
|
||||||
|
/// <param name="title"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="ArgumentNullException"></exception>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user