fix 数据状态处理

This commit is contained in:
2024-04-11 12:48:00 +08:00
parent 7884b4d70e
commit 03c49b5e9f
3 changed files with 34 additions and 35 deletions

View File

@@ -241,27 +241,36 @@ public class OrderService : BaseOrderService, IOrderService
{
if (!allowNoBalance)
{
var gainfoMeal = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).FirstAsync();
if (gainfoMeal == null)
GainfoMealEntity gainfoMeal = null;
using (var handler = await _redisCache.LockAsync($"gainfo:meal:{order.UserNo}", retryInterval: TimeSpan.FromSeconds(1)))
{
gainfoMeal = new GainfoMealEntity
if (handler.Acquired)
{
Balance = 0,
BalanceOfRecharge = 0,
BalanceOfSubsidies = 0,
Version = 0,
TenantId = gainfo.Factory,
UserNo = order.UserNo,
UserCode = order.UserCode,
gainfoMeal = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).FirstAsync();
if (gainfoMeal == null)
{
gainfoMeal = new GainfoMealEntity
{
Balance = 0,
BalanceOfRecharge = 0,
BalanceOfSubsidies = 0,
Version = 0,
TenantId = gainfo.Factory,
UserNo = order.UserNo,
UserCode = order.UserCode,
CreatedBy = 1,
CreateTime = DateTime.Now,
ModifiedBy = 1,
ModifiedTime = DateTime.Now,
};
CreatedBy = 1,
CreateTime = DateTime.Now,
ModifiedBy = 1,
ModifiedTime = DateTime.Now,
};
await DbContext.InsertAsync(gainfoMeal);
await DbContext.InsertAsync(gainfoMeal);
}
}
}
//金额+-
gainfoMeal.Balance += order.Amount;