From 153a8f9341e0d890d6ff3abfabf19e1552a5e201 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 18 Oct 2024 11:07:15 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E7=94=B5=E5=AD=90?= =?UTF-8?q?=E9=A4=90=E5=88=B8=E9=80=80=E6=AC=BE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/EMealVoucherService.cs | 3 +- .../Order/Controllers/BalancesController.cs | 4 +-- .../Order/Services/IBalanceService.cs | 2 +- .../Services/Implements/BalanceService.cs | 35 ++++++++++--------- .../Order/Services/Implements/OrderService.cs | 12 ++----- 5 files changed, 26 insertions(+), 30 deletions(-) diff --git a/Src/Dlhis.Canteen/EMealVoucher/Services/Implements/EMealVoucherService.cs b/Src/Dlhis.Canteen/EMealVoucher/Services/Implements/EMealVoucherService.cs index 4b562870..629dc340 100644 --- a/Src/Dlhis.Canteen/EMealVoucher/Services/Implements/EMealVoucherService.cs +++ b/Src/Dlhis.Canteen/EMealVoucher/Services/Implements/EMealVoucherService.cs @@ -87,8 +87,7 @@ public class EMealVoucherService : IEMealVoucherService eMealVoucherDetail.ThrowIfNull("无效地址"); var eMealVoucher = await _dbContext.Queryable().Where(x => x.No == eMealVoucherDetail.No).SingleAsync(); - var ts = DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString().Reverse().Join(string.Empty); - var originData = string.Concat(eMealVoucher.No, ":", ts, ":", eMealVoucher.Code, ":", eMealVoucherDetail.IdNo); + var originData = string.Concat(eMealVoucher.No, ":", eMealVoucher.Code, ":", eMealVoucherDetail.IdNo); var qrCode = "02" + originData.ToArray().Select(x => { diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index 4c3ad403..b32b684d 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -61,9 +61,9 @@ public class BalancesController : ControllerBase [HttpPost("refund")] [IgnoreTenant] [Transactional(IsolationLevel.ReadCommitted)] - public async Task RefundAsync(BalanceRecordRefundRequest request) + public async Task RefundAsync(BalanceRecordRefundRequest request) { - return await _balanceService.RefundAsync(request.No); + await _balanceService.RefundAsync(request.No); } diff --git a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs index efb27b66..bedc7a72 100644 --- a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs @@ -23,7 +23,7 @@ public interface IBalanceService : IScopeDependency /// /// /// - Task RefundAsync(string no); + Task RefundAsync(string no); /// /// 营业点消费明细 diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index de93f8b6..3ee3e407 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -105,7 +105,7 @@ public class BalanceService : IBalanceService return page; } - public async Task RefundAsync(string no) + public async Task RefundAsync(string no) { var cache = App.GetServiceProvider().GetService(); var balanceRecord = await _dbContext.Queryable().Where(x => x.No == no).SingleAsync(); @@ -126,23 +126,26 @@ public class BalanceService : IBalanceService { await ReCalcAsync(balanceRecord.UserCode); } + else if (balanceRecord.Source == BalanceRecordSourceEnumType.EMealVoucher) + { + var originData = balanceRecord.UserNo.Split(":"); + var eNo = originData[0]; + var idNo = originData.Last(); + + await CommonHelper.RetryAsync(async () => + { + var eDetail = await _dbContext.Queryable().Where(x => x.No == eNo && x.IdNo == idNo).SingleAsync(); + var amount = Math.Abs(balanceRecord.Amount); + await _dbContext.Updateable() + .SetColumns(x => x.Version == x.Version + 1) + .SetColumns(x => x.Balance == x.Balance + amount) + .SetColumns(x => x.ModifiedTime == DateTime.Now) + .Where(x => x.No == eNo && x.IdNo == idNo && x.Version == eDetail.Version) + .ExecuteCommandThrowVersionAsync(); + }, 5); + } } } - - //获取人员余额 - return await _dbContext.Queryable() - .LeftJoin((x, ga) => x.UserCode == ga.Code) - .LeftJoin((x, ga, department) => ga.DepartmentNo == department.No) - .Where(x => x.UserCode == balanceRecord.UserCode) - .Select((x, ga, department) => new OrderResultResponse - { - UserCode = ga.Code, - UserName = ga.Name, - DepartmentNo = ga.DepartmentNo, - DepartmentName = department.Name, - CurrentBalance = x.Balance - }) - .SingleAsync(); } diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs index 2fc753f1..44574448 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs @@ -536,14 +536,12 @@ public class OrderService : BaseOrderService, IOrderService } var originData = eMealVoucherQrCode.OriginData.Split(':'); - var no = originData[0]; - var ts = originData[1]; - var idNo = originData[3]; + var idNo = originData.Length == 4 ? originData[3] : originData[2]; try { - await EMealVoucherConsumeAsync(request.Adapt(), gainfo, eMealVoucherQrCode.OriginData, no, ts, idNo); + await EMealVoucherConsumeAsync(request.Adapt(), gainfo, eMealVoucherQrCode.OriginData, no, idNo); } catch (Exception ex) { @@ -667,17 +665,13 @@ public class OrderService : BaseOrderService, IOrderService return await DbContext.Queryable().Where(x => x.Code == gainfoQrCode.UserCode).SingleAsync(); } - private async Task EMealVoucherConsumeAsync(ConsumeRequest request, GainfoEntity gainfo, string originData, string no, string ts, string idNo) + private async Task EMealVoucherConsumeAsync(ConsumeRequest request, GainfoEntity gainfo, string originData, string no, string idNo) { var nowDate = DateTime.Now.Date; var current = await DbContext.Queryable() .Where(x => x.No == no && x.IdNo == idNo).SingleAsync(); (nowDate >= current.Start && nowDate <= current.End).ThrowIfFalse("餐券已过期"); - //todo 临时注释 - // var time = DateTimeOffset.FromUnixTimeMilliseconds(Convert.ToInt64(ts.Reverse().Join(string.Empty))).ToLocalTime().DateTime; - // (time.AddMinutes(60) >= DateTime.Now).ThrowIfFalse("餐券二维码已过期"); - var eMealVoucher = await DbContext.Queryable().Where(x => x.No == no).SingleAsync(); var checkData = await PreCheckAsync(request.DeviceUniqueNo, request.CostDateTime);