fix 餐补消费暂不扣费

This commit is contained in:
2024-03-23 18:31:44 +08:00
parent 517527365b
commit aa0fca2c09
2 changed files with 42 additions and 42 deletions

View File

@@ -94,38 +94,37 @@ public class BookingOrderService : BaseOrderService, IBookingOrderService
menuDetail.ThrowIfNull("预定失败,菜品已经下架"); menuDetail.ThrowIfNull("预定失败,菜品已经下架");
menuDetail.Number -= request.Number; menuDetail.Number -= request.Number;
(menuDetail.Number < 0).ThrowIfTrue($"{menuDetail.DishesName}已售罄"); (menuDetail.Number < 0).ThrowIfTrue($"{menuDetail.DishesName}剩余数量不足");
//餐补 //餐补 //todo 餐补暂不入账
if (request.Source == BalanceRecordSourceEnumType.LocalTenantSubsidies) if (request.Source == BalanceRecordSourceEnumType.LocalTenantSubsidies)
{ {
//var mealInfo = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).FirstAsync();
//if (mealInfo == null)
//{
// await DbContext.InsertAsync(new GainfoMealEntity
// {
// Balance = 0,
// BalanceOfRecharge = 0,
// BalanceOfSubsidies = 0,
// UserCode = gainfo.Code,
// UserNo = gainfo.No,
// Version = 0,
// });
var mealInfo = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).FirstAsync(); // (mealInfo == null).ThrowIfTrue("余额不足,无法消费");
if (mealInfo == null) //}
{ ////金额+-
await DbContext.InsertAsync(new GainfoMealEntity //mealInfo.Balance += order.Amount;
{ //(mealInfo.Balance < 0).ThrowIfTrue("余额不足,无法消费");
Balance = 0,
BalanceOfRecharge = 0,
BalanceOfSubsidies = 0,
UserCode = gainfo.Code,
UserNo = gainfo.No,
Version = 0,
});
(mealInfo == null).ThrowIfTrue("余额不足,无法消费"); //var effectMeal = await DbContext.Updateable<GainfoMealEntity>()
} // .SetColumns(x => x.Balance == mealInfo.Balance)
//金额+- // .SetColumns(x => x.Version == x.Version + 1)
mealInfo.Balance += order.Amount; // .Where(x => x.UserNo == order.UserNo && x.Version == mealInfo.Version)//必须与查询时的version一致
(mealInfo.Balance < 0).ThrowIfTrue("余额不足,无法消费"); // .ExecuteCommandAsync();
var effectMeal = await DbContext.Updateable<GainfoMealEntity>() //if (effectMeal <= 0) throw new VersionExceptions("更新版本冲突");
.SetColumns(x => x.Balance == mealInfo.Balance)
.SetColumns(x => x.Version == x.Version + 1)
.Where(x => x.UserNo == order.UserNo && x.Version == mealInfo.Version)//必须与查询时的version一致
.ExecuteCommandAsync();
if (effectMeal <= 0) throw new VersionExceptions("更新版本冲突");
} }
@@ -238,24 +237,24 @@ public class BookingOrderService : BaseOrderService, IBookingOrderService
if (order.Source != BalanceRecordSourceEnumType.Cash) if (order.Source != BalanceRecordSourceEnumType.Cash)
{ {
//尝试5次 //todo 餐补暂不入账
await ContinueUpdateAsync(async () => //await ContinueUpdateAsync(async () =>
{ //{
var mealInfo = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).FirstAsync(); // var mealInfo = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).FirstAsync();
var setBalance = mealInfo.Balance + Math.Abs(order.Amount); // var setBalance = mealInfo.Balance + Math.Abs(order.Amount);
var effect = await DbContext.Updateable<GainfoMealEntity>() // var effect = await DbContext.Updateable<GainfoMealEntity>()
.SetColumns(x => x.Balance == setBalance) // .SetColumns(x => x.Balance == setBalance)
.SetColumns(x => x.ModifiedTime == now) // .SetColumns(x => x.ModifiedTime == now)
.SetColumns(x => x.ModifiedBy == userId) // .SetColumns(x => x.ModifiedBy == userId)
.Where(x => x.Id == mealInfo.Id && x.Version == mealInfo.Version) // .Where(x => x.Id == mealInfo.Id && x.Version == mealInfo.Version)
.ExecuteCommandAsync(); // .ExecuteCommandAsync();
if (effect <= 0) // if (effect <= 0)
{ // {
throw new VersionExceptions("取消订单失败!"); // throw new VersionExceptions("取消订单失败!");
} // }
}, 5); //}, 5);
} }
} }

View File

@@ -40,6 +40,7 @@ public class MealSupplementHandlerJob
//档案不存在 //档案不存在
if (gainfo == null) if (gainfo == null)
{ {
_logger.LogWarning("档案code:{code}不存在.flowno:{flowno}", item.Code, item.UniqueId);
continue; continue;
} }
else else