添加货币信息

This commit is contained in:
zpc 2024-07-19 03:20:25 +08:00
parent eb7699b435
commit da4a977034
9 changed files with 138 additions and 3 deletions

View File

@ -11,7 +11,7 @@ namespace HuanMeng.DotNetCore.Base
/// <summary>
/// _dao,提供数据访问支持
/// </summary>
protected abstract TDao Dao { get; }
public abstract TDao Dao { get; }
/// <summary>

View File

@ -41,7 +41,7 @@ namespace HuanMeng.MiaoYu.Code.Base
/// <summary>
/// dao 数据库
/// </summary>
protected override DAO Dao
public override DAO Dao
{
get
{

View File

@ -106,12 +106,16 @@ namespace HuanMeng.MiaoYu.Code.Users
{
var user = await Dao.daoDbMiaoYu.context.T_User.FirstOrDefaultAsync(it => it.Id == _UserId);
var userData = await Dao.daoDbMiaoYu.context.T_User_Data.FirstOrDefaultAsync(it => it.Id == _UserId);
//获取用户余额
var Currency = user.GetUserCurrency(Model.EnumModel.User.UserCurrencyType., Dao);
var RemainingChatCount = user.GetUserCurrency(Model.EnumModel.User.UserCurrencyType., Dao);
return new BaseResponse<ResponseUserInfo>(ResonseCode.Success, "请求成功", new ResponseUserInfo
{
NickName = user.NickName,
UserId = user.Id,
Currency = userData.Currency,
UserIconUrl = userData.UserIconUrl
UserIconUrl = userData.UserIconUrl,
RemainingChatCount= RemainingChatCount
});
}
}

View File

@ -0,0 +1,49 @@
using HuanMeng.MiaoYu.Code.Base;
using HuanMeng.MiaoYu.Model.EnumModel.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HuanMeng.MiaoYu.Code.Users
{
/// <summary>
/// 用户货币记录
/// </summary>
public class UserCurrencyBLL(MiaoYuBase miaoYuBase)
{
/// <summary>
/// 获取货币余额
/// </summary>
/// <param name="userCurrencyType"></param>
/// <returns></returns>
public decimal GetUserCurrency(UserCurrencyType userCurrencyType)
{
var userCurrency = miaoYuBase.Dao.daoDbMiaoYu.context.T_User_Currency.FirstOrDefault(it => it.UserId == miaoYuBase._UserId && it.CurrencyType == (int)userCurrencyType);
return userCurrency?.CurrencyMoney ?? 0;
}
}
/// <summary>
///
/// </summary>
public static class UserCurrencyExtend
{
/// <summary>
/// 获取用户货币余额
/// </summary>
/// <param name="user"></param>
/// <param name="userCurrencyType"></param>
/// <param name="dao"></param>
/// <returns></returns>
public static decimal GetUserCurrency(this T_User user, UserCurrencyType userCurrencyType, DAO dao)
{
var userCurrency = dao.daoDbMiaoYu.context.T_User_Currency.FirstOrDefault(it => it.UserId == user.Id && it.CurrencyType == (int)userCurrencyType);
return userCurrency?.CurrencyMoney ?? 0;
}
}
}

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HuanMeng.MiaoYu.Code.Users
{
/// <summary>
/// 用户信息
/// </summary>
public class UserInfoBLL : MiaoYuBase<UserInfoBLL>
{
public UserInfoBLL(IServiceProvider serviceProvider) : base(serviceProvider)
{
}
private T_User? _user;
/// <summary>
/// 用户表
/// </summary>
public T_User User
{
get
{
if (_user == null)
{
if (_UserId == 0)
{
throw new Exception("未找到用户");
}
_user = Dao.daoDbMiaoYu.context.T_User.FirstOrDefault(it => it.Id == _UserId);
if (_user == null)
{
throw new Exception("未找到用户");
}
}
return _user;
}
}
}
}

View File

@ -482,9 +482,11 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext
.HasMaxLength(20)
.HasComment("货币名称");
entity.Property(e => e.CurrencyType).HasComment("货币类型");
entity.Property(e => e.TenantId).HasComment("租户Id");
entity.Property(e => e.UpdateAt)
.HasComment("修改时间")
.HasColumnType("datetime");
entity.Property(e => e.UserId).HasComment("用户Id");
//添加全局筛选器
if (this.TenantInfo != null)
{

View File

@ -33,4 +33,10 @@ public partial class T_User_Currency: MultiTenantEntity
/// 创建时间
/// </summary>
public DateTime CreateAt { get; set; }
/// <summary>
/// 用户Id
/// </summary>
public int UserId { get; set; }
}

View File

@ -31,5 +31,10 @@ namespace HuanMeng.MiaoYu.Model.Dto
/// 用户昵称,需要和主表保持一致
/// </summary>
public string? NickName { get; set; }
/// <summary>
/// 聊天次数
/// </summary>
public int RemainingChatCount { get; set; }
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HuanMeng.MiaoYu.Model.EnumModel.User
{
/// <summary>
/// 用户货币类型
/// </summary>
public enum UserCurrencyType
{
/// <summary>
/// 免费币
/// </summary>
= 0,
/// <summary>
/// 付费币
/// </summary>
= 1,
/// <summary>
///
/// </summary>
= 2
}
}