fix 修复电子餐券退款问题
This commit is contained in:
@@ -87,8 +87,7 @@ public class EMealVoucherService : IEMealVoucherService
|
||||
eMealVoucherDetail.ThrowIfNull("无效地址");
|
||||
var eMealVoucher = await _dbContext.Queryable<EMealVoucherEntity>().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 =>
|
||||
{
|
||||
|
||||
@@ -61,9 +61,9 @@ public class BalancesController : ControllerBase
|
||||
[HttpPost("refund")]
|
||||
[IgnoreTenant]
|
||||
[Transactional(IsolationLevel.ReadCommitted)]
|
||||
public async Task<OrderResultResponse> RefundAsync(BalanceRecordRefundRequest request)
|
||||
public async Task RefundAsync(BalanceRecordRefundRequest request)
|
||||
{
|
||||
return await _balanceService.RefundAsync(request.No);
|
||||
await _balanceService.RefundAsync(request.No);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public interface IBalanceService : IScopeDependency
|
||||
/// </summary>
|
||||
/// <param name="no"></param>
|
||||
/// <returns></returns>
|
||||
Task<OrderResultResponse> RefundAsync(string no);
|
||||
Task RefundAsync(string no);
|
||||
|
||||
/// <summary>
|
||||
/// 营业点消费明细
|
||||
|
||||
@@ -105,7 +105,7 @@ public class BalanceService : IBalanceService
|
||||
return page;
|
||||
}
|
||||
|
||||
public async Task<OrderResultResponse> RefundAsync(string no)
|
||||
public async Task RefundAsync(string no)
|
||||
{
|
||||
var cache = App.GetServiceProvider().GetService<RedisCache>();
|
||||
var balanceRecord = await _dbContext.Queryable<BalanceRecordEntity>().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<EMealVoucherDetailEntity>().Where(x => x.No == eNo && x.IdNo == idNo).SingleAsync();
|
||||
var amount = Math.Abs(balanceRecord.Amount);
|
||||
await _dbContext.Updateable<EMealVoucherDetailEntity>()
|
||||
.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<GainfoMealEntity>()
|
||||
.LeftJoin<GainfoEntity>((x, ga) => x.UserCode == ga.Code)
|
||||
.LeftJoin<DepartmentEntity>((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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<ConsumeRequest>(), gainfo, eMealVoucherQrCode.OriginData, no, ts, idNo);
|
||||
await EMealVoucherConsumeAsync(request.Adapt<ConsumeRequest>(), gainfo, eMealVoucherQrCode.OriginData, no, idNo);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -667,17 +665,13 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
return await DbContext.Queryable<GainfoEntity>().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<EMealVoucherDetailEntity>()
|
||||
.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<EMealVoucherEntity>().Where(x => x.No == no).SingleAsync();
|
||||
|
||||
var checkData = await PreCheckAsync(request.DeviceUniqueNo, request.CostDateTime);
|
||||
|
||||
Reference in New Issue
Block a user