修改问题
This commit is contained in:
parent
036154aa20
commit
928bc023ea
|
|
@ -147,7 +147,7 @@ namespace HuanMeng.MiaoYu.Code.Order
|
|||
try
|
||||
{
|
||||
var price = (((int)product.Price) * buyCount);
|
||||
user.ConsumeMoneyNoWork(UserCurrencyType.语珠, -price, Dao, title: $"购买{product.ProductName}消耗{price}{UserCurrencyType.语珠}");
|
||||
user.ConsumeMoneyNoWork(UserCurrencyType.语珠, -price, Dao, title: $"购买{product.ProductName}*{buyCount}");
|
||||
for (int i = 0; i < buyCount; i++)
|
||||
{
|
||||
|
||||
|
|
@ -161,7 +161,9 @@ namespace HuanMeng.MiaoYu.Code.Order
|
|||
var money = reward.Money;
|
||||
var currency = (UserCurrencyType)reward.CurrencyType;
|
||||
var userCurrency = new T_User_Currency();
|
||||
user.ConsumeMoneyNoWork(currency, money, Dao, userCurrency, productId: productId, imageUrl: image);
|
||||
var _log = new T_User_Currency_Log();
|
||||
user.ConsumeMoneyNoWork(currency, money, Dao, userCurrency, productId: productId, imageUrl: image, log: _log);
|
||||
_log.IsHide = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ namespace HuanMeng.MiaoYu.Code.Users
|
|||
{
|
||||
return new BaseResponse<List<TransactionDto>>(ResonseCode.Success, "", new List<TransactionDto>());
|
||||
}
|
||||
var logs = await Dao.daoDbMiaoYu.context.T_User_Currency_Log.Where(it => it.UserId == _UserId && !(it.CurrencyType == (int)UserCurrencyType.聊天次数 && it.ConsumeType == 0)).OrderByDescending(it => it.Id).Take(50).ToListAsync();
|
||||
var logs = await Dao.daoDbMiaoYu.context.T_User_Currency_Log.Where(it => it.UserId == _UserId && !(it.CurrencyType == (int)UserCurrencyType.聊天次数 && it.ConsumeType == 0) && !it.IsHide).OrderByDescending(it => it.Id).Take(50).ToListAsync();
|
||||
List<TransactionDto> list = new List<TransactionDto>();
|
||||
foreach (var item in logs)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -110,14 +110,16 @@ namespace HuanMeng.MiaoYu.Code.Users
|
|||
/// <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 = "", string productId = "", string imageUrl = "")
|
||||
public static bool ConsumeMoneyNoWork(this T_User user, UserCurrencyType userCurrencyType, decimal money, DAO dao, T_User_Currency? _currency = null, string orderId = "", string title = "", string productId = "", string imageUrl = ""
|
||||
,
|
||||
T_User_Currency_Log? log = null)
|
||||
{
|
||||
if (user == null || user.Id == 0)
|
||||
{
|
||||
throw new ArgumentNullException("用户不能为空");
|
||||
}
|
||||
int userId = user.Id;
|
||||
return ConsumeMoneyNoWork(userId, userCurrencyType, money, dao, _currency, orderId: orderId, title: title, productId: productId, imageUrl: imageUrl);
|
||||
return ConsumeMoneyNoWork(userId, userCurrencyType, money, dao, _currency, orderId: orderId, title: title, productId: productId, imageUrl: imageUrl, log: log);
|
||||
}
|
||||
/// <summary>
|
||||
/// 扣除或者充值货币
|
||||
|
|
@ -204,7 +206,8 @@ namespace HuanMeng.MiaoYu.Code.Users
|
|||
/// <param name="imageUrl"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static bool ConsumeMoneyNoWork(int userId, UserCurrencyType userCurrencyType, decimal money, DAO dao, T_User_Currency? _currency = null, string remarks = "", string title = "", string orderId = "", string productId = "", string imageUrl = "")
|
||||
public static bool ConsumeMoneyNoWork(int userId, UserCurrencyType userCurrencyType, decimal money, DAO dao, T_User_Currency? _currency = null, string remarks = "", string title = "", string orderId = "", string productId = "", string imageUrl = "",
|
||||
T_User_Currency_Log? log = null)
|
||||
{
|
||||
//记忆卡特殊处理
|
||||
if (MUserCurrencyType.Contains(userCurrencyType) && money > 0)
|
||||
|
|
@ -253,7 +256,7 @@ namespace HuanMeng.MiaoYu.Code.Users
|
|||
throw new Exception("余额不足");
|
||||
}
|
||||
|
||||
T_User_Currency_Log? log = null;
|
||||
|
||||
UserCurrencyConsumeType userCurrencyConsumeType = UserCurrencyConsumeType.消耗;
|
||||
if (money >= 0)
|
||||
{
|
||||
|
|
@ -266,7 +269,7 @@ namespace HuanMeng.MiaoYu.Code.Users
|
|||
log = dao.daoDbMiaoYu.context.T_User_Currency_Log.Where(it => it.CreateTime > mintes && it.ConsumeType == (int)UserCurrencyConsumeType.消耗 && it.CurrencyType == (int)userCurrencyType).OrderByDescending(it => it.CreateTime).FirstOrDefault();
|
||||
}
|
||||
var tempMoney = Math.Abs(money);
|
||||
if (string.IsNullOrEmpty(title))
|
||||
if (string.IsNullOrEmpty(title) && UserCurrencyConsumeType.消耗 == userCurrencyConsumeType)
|
||||
{
|
||||
title = $"{userCurrencyConsumeType}{money}{userCurrencyType}";
|
||||
}
|
||||
|
|
@ -284,7 +287,8 @@ namespace HuanMeng.MiaoYu.Code.Users
|
|||
UserId = userId,
|
||||
Remarks = remarks,
|
||||
Title = title,
|
||||
OrderId = orderId
|
||||
OrderId = orderId,
|
||||
IsHide = false
|
||||
};
|
||||
dao.daoDbMiaoYu.context.T_User_Currency_Log.Add(log);
|
||||
}
|
||||
|
|
@ -381,82 +385,13 @@ namespace HuanMeng.MiaoYu.Code.Users
|
|||
/// <returns></returns>
|
||||
public static bool ConsumeMoney(int userId, UserCurrencyType userCurrencyType, decimal money, DAO dao, string _remarks = "")
|
||||
{
|
||||
var userCurrency = dao.daoDbMiaoYu.context.T_User_Currency.FirstOrDefault(it => it.UserId == userId && it.CurrencyType == (int)userCurrencyType);
|
||||
if (userCurrency == null)
|
||||
{
|
||||
userCurrency = new T_User_Currency()
|
||||
{
|
||||
CreateAt = DateTime.Now,
|
||||
CurrencyMoney = 0,
|
||||
CurrencyName = userCurrencyType.ToString(),
|
||||
CurrencyType = (int)userCurrencyType,
|
||||
TenantId = dao.daoDbMiaoYu.context.TenantInfo.TenantId,
|
||||
UpdateAt = DateTime.Now,
|
||||
UserId = userId
|
||||
};
|
||||
dao.daoDbMiaoYu.context.Add(userCurrency);
|
||||
dao.daoDbMiaoYu.context.SaveChanges();
|
||||
}
|
||||
var tempCurrencyMoney = userCurrency.CurrencyMoney + money;
|
||||
if (tempCurrencyMoney < 0)
|
||||
{
|
||||
//余额不足
|
||||
return false;
|
||||
}
|
||||
|
||||
// 开启事务
|
||||
using (IDbContextTransaction transaction = dao.daoDbMiaoYu.context.Database.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
userCurrency.CurrencyMoney += money;
|
||||
if (userCurrency.CurrencyMoney < 0)
|
||||
{
|
||||
transaction.Rollback();
|
||||
//余额不足
|
||||
return false;
|
||||
}
|
||||
T_User_Currency_Log? log = null;
|
||||
UserCurrencyConsumeType userCurrencyConsumeType = UserCurrencyConsumeType.消耗;
|
||||
if (money >= 0)
|
||||
{
|
||||
userCurrencyConsumeType = UserCurrencyConsumeType.购买;
|
||||
}
|
||||
|
||||
if (userCurrencyType == UserCurrencyType.聊天次数 && userCurrencyConsumeType == UserCurrencyConsumeType.消耗)
|
||||
{
|
||||
var mintes = DateTime.Now.AddMinutes(-5);
|
||||
log = dao.daoDbMiaoYu.context.T_User_Currency_Log.Where(it => it.CreateTime > mintes).OrderByDescending(it => it.CreateTime).FirstOrDefault();
|
||||
}
|
||||
var tempMoney = Math.Abs(money);
|
||||
//消费
|
||||
if (log == null)
|
||||
{
|
||||
log = new T_User_Currency_Log()
|
||||
{
|
||||
Consume = 0,
|
||||
ConsumeType = (int)userCurrencyConsumeType,
|
||||
CreateTime = DateTime.Now,
|
||||
CurrencyType = (int)userCurrencyType,
|
||||
TenantId = dao.daoDbMiaoYu.context.TenantInfo.TenantId,
|
||||
UpdateTime = DateTime.Now,
|
||||
UserId = userId,
|
||||
Remarks = ""
|
||||
};
|
||||
dao.daoDbMiaoYu.context.T_User_Currency_Log.Add(log);
|
||||
}
|
||||
log.Consume += money;
|
||||
if (!string.IsNullOrEmpty(_remarks))
|
||||
{
|
||||
log.Remarks += _remarks;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.Remarks += $"于{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}{userCurrencyConsumeType.ToString()}[{tempMoney}]{userCurrencyType.ToString()};";
|
||||
}
|
||||
if (log.Remarks.Length > 200)
|
||||
{
|
||||
log.Remarks = log.Remarks.Substring(log.Remarks.Length - 200);
|
||||
}
|
||||
ConsumeMoneyNoWork(userId, userCurrencyType, money, dao, remarks: _remarks);
|
||||
dao.daoDbMiaoYu.context.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1120,6 +1120,7 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext
|
|||
.HasComment("创建时间")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.CurrencyType).HasComment("金额类型");
|
||||
entity.Property(e => e.IsHide).HasComment("是否不显示");
|
||||
entity.Property(e => e.OrderId).HasMaxLength(64);
|
||||
entity.Property(e => e.Remarks)
|
||||
.HasMaxLength(200)
|
||||
|
|
|
|||
|
|
@ -49,4 +49,9 @@ public partial class T_User_Currency_Log: MultiTenantEntity
|
|||
public virtual string? Title { get; set; }
|
||||
|
||||
public virtual string? OrderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否不显示
|
||||
/// </summary>
|
||||
public virtual bool IsHide { get; set; }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user