fix 增加image记录,移除balance负数处理
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.Data;
|
||||
using Dlhis.Basic.Api;
|
||||
using Dlhis.Basic.Api;
|
||||
using Dlhis.Canteen.Setting.Services;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
@@ -600,40 +599,40 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
|
||||
var allowNoBalance = await GetSettingAsync<bool>(order.TenantId, CanteenSettingItemEnumType.AllowNoBalance);
|
||||
|
||||
//降级到读已提交
|
||||
await DbContext.Client.Ado.BeginTranAsync(IsolationLevel.ReadCommitted);
|
||||
try
|
||||
////降级到读已提交
|
||||
// await DbContext.Client.Ado.BeginTranAsync(IsolationLevel.ReadCommitted);
|
||||
// try
|
||||
// {
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
{
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
if (!allowNoBalance)
|
||||
{
|
||||
if (!allowNoBalance)
|
||||
{
|
||||
var gainfoMeal = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).SingleAsync();
|
||||
//金额+-
|
||||
gainfoMeal.Balance += order.Amount;
|
||||
var gainfoMeal = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).SingleAsync();
|
||||
//金额+-
|
||||
gainfoMeal.Balance += order.Amount;
|
||||
|
||||
(gainfoMeal.Balance < 0).ThrowIfTrue("余额不足,无法消费");
|
||||
(gainfoMeal.Balance < 0).ThrowIfTrue("余额不足,无法消费");
|
||||
|
||||
await DbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Balance == gainfoMeal.Balance)
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.Where(x => x.UserNo == order.UserNo && x.Version == gainfoMeal.Version) //必须与查询时的version一致
|
||||
.ExecuteCommandThrowVersionAsync();
|
||||
}
|
||||
await DbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Balance == gainfoMeal.Balance)
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.Where(x => x.UserNo == order.UserNo && x.Version == gainfoMeal.Version) //必须与查询时的version一致
|
||||
.ExecuteCommandThrowVersionAsync();
|
||||
}
|
||||
|
||||
//写入记录
|
||||
var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
||||
await DbContext.InsertAsync(balanceRecord);
|
||||
}, 5);
|
||||
//写入记录
|
||||
var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
||||
await DbContext.InsertAsync(balanceRecord);
|
||||
}, 5);
|
||||
|
||||
await DbContext.Client.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
await DbContext.Client.Ado.RollbackTranAsync();
|
||||
throw;
|
||||
}
|
||||
// await DbContext.Client.Ado.CommitTranAsync();
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// await DbContext.Client.Ado.RollbackTranAsync();
|
||||
// throw;
|
||||
// }
|
||||
}
|
||||
|
||||
public async Task ReCalcOfflineAsync(ReCalcOfflineRequest request)
|
||||
|
||||
Reference in New Issue
Block a user