All checks were successful
Build and Deploy / deploy (push) Successful in 1m29s
回调/查单/补偿走事务内原子占单再入账;关单同步驳回充值;创建先落单失败即 Failed;列表标记在线支付态。 Co-authored-by: Cursor <cursoragent@cursor.com>
85 lines
2.7 KiB
C#
85 lines
2.7 KiB
C#
using Fake.DependencyInjection;
|
|
using Oms.Domain.PaymentAggregate.Entities;
|
|
using Oms.Domain.PaymentAggregate.Enums;
|
|
using Oms.Domain.PaymentAggregate.Repositories;
|
|
using Oms.SqlSugarCore.Repositories;
|
|
|
|
namespace Oms.SqlSugarCore.Payment;
|
|
|
|
public class PaymentOrderRepository
|
|
: OmsSqlSugarRepository<PaymentOrder>, IPaymentOrderRepository, IScopedDependency
|
|
{
|
|
public Task<PaymentOrder?> GetByOutTradeNoAsync(string outTradeNo, CancellationToken cancellationToken = default)
|
|
{
|
|
var no = (outTradeNo ?? string.Empty).Trim();
|
|
if (string.IsNullOrEmpty(no))
|
|
{
|
|
return Task.FromResult<PaymentOrder?>(null);
|
|
}
|
|
|
|
return FirstOrDefaultAsync(x => x.OutTradeNo == no, cancellationToken);
|
|
}
|
|
|
|
public Task<bool> ExistsOutTradeNoAsync(string outTradeNo, CancellationToken cancellationToken = default)
|
|
{
|
|
var no = (outTradeNo ?? string.Empty).Trim();
|
|
if (string.IsNullOrEmpty(no))
|
|
{
|
|
return Task.FromResult(false);
|
|
}
|
|
|
|
return AnyAsync(x => x.OutTradeNo == no, cancellationToken);
|
|
}
|
|
|
|
public async Task<PaymentOrder?> GetLatestByRechargeBizIdAsync(
|
|
int rechargeRecordId,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
if (rechargeRecordId <= 0)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var db = await GetDbContextAsync(cancellationToken);
|
|
return await db.Queryable<PaymentOrder>()
|
|
.Where(x =>
|
|
!x.IsDeleted
|
|
&& x.BizType == PaymentBizTypeCodes.Recharge
|
|
&& x.BizId == rechargeRecordId)
|
|
.OrderBy(x => x.Id, SqlSugar.OrderByType.Desc)
|
|
.FirstAsync(cancellationToken);
|
|
}
|
|
|
|
public async Task<bool> TryClaimSuccessAsync(
|
|
string outTradeNo,
|
|
string? transactionId,
|
|
DateTime paidTime,
|
|
string? remark,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
var no = (outTradeNo ?? string.Empty).Trim();
|
|
if (string.IsNullOrEmpty(no))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var db = await GetDbContextAsync(cancellationToken);
|
|
var now = DateTime.Now;
|
|
var affected = await db.Updateable<PaymentOrder>()
|
|
.SetColumns(x => new PaymentOrder
|
|
{
|
|
Status = PaymentOrderStatus.Success,
|
|
TransactionId = transactionId,
|
|
PaidTime = paidTime,
|
|
Remark = remark,
|
|
UpdateTime = now
|
|
})
|
|
.Where(x =>
|
|
x.OutTradeNo == no
|
|
&& !x.IsDeleted
|
|
&& (x.Status == PaymentOrderStatus.Created || x.Status == PaymentOrderStatus.Paying))
|
|
.ExecuteCommandAsync(cancellationToken);
|
|
return affected > 0;
|
|
}
|
|
}
|