refactor 代码优化

This commit is contained in:
2024-08-14 15:43:37 +08:00
parent 96b43876b8
commit 23d3e1028b

View File

@@ -583,12 +583,29 @@ public class OrderService : BaseOrderService, IOrderService
try try
{ {
await EMealVoucherConsumeAsync(request.Adapt<ConsumeRequest>(), gainfo); await EMealVoucherConsumeAsync(request.Adapt<ConsumeRequest>(), gainfo, eMealVoucherQrCode.OriginData, no, ts, idNo);
} }
catch (Exception ex) catch (Exception ex)
{ {
message = ex.Message; message = ex.Message;
} }
//获取餐券余额
var data = await DbContext.Queryable<EMealVoucherEntity>()
.LeftJoin<EMealVoucherDetailEntity>((x, d) => x.No == d.No)
.Where((x, d) => d.IdNo == idNo)
.Select((x, d) => new OrderResultResponse
{
CurrentBalance = d.Balance
})
.SingleAsync();
return new DefaultApiResult<OrderResultResponse>
{
Code = message.IsPresent() ? ApiStateCode.Error : ApiStateCode.Success,
Data = data,
Msg = message
};
} }
else else
{ {
@@ -692,7 +709,6 @@ public class OrderService : BaseOrderService, IOrderService
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 ts, string idNo)
{ {
var nowDate = DateTime.Now.Date; var nowDate = DateTime.Now.Date;
var current = await DbContext.Queryable<EMealVoucherDetailEntity>() var current = await DbContext.Queryable<EMealVoucherDetailEntity>()
.Where(x => x.No == no && x.IdNo == idNo).SingleAsync(); .Where(x => x.No == no && x.IdNo == idNo).SingleAsync();
@@ -767,7 +783,6 @@ public class OrderService : BaseOrderService, IOrderService
.SetColumns(x => x.ModifiedTime == DateTime.Now) .SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => x.Id == orderId) .Where(x => x.Id == orderId)
.ExecuteCommandAsync(); .ExecuteCommandAsync();
} }
catch (Exception ex) catch (Exception ex)
{ {