task: 完成支付宝共享基础(迁移/WechatConfig/PaymentStore/pkg/alipay)

This commit is contained in:
2026-05-22 12:09:55 +08:00
parent 2768deb0b6
commit 53e95751b1
13 changed files with 342 additions and 4 deletions

View File

@@ -150,3 +150,18 @@ func (s *PaymentStore) GetByOrderIDAndStatus(ctx context.Context, orderID uint,
}
return &payment, nil
}
// FindLatestPendingByOrderAndMethod 按业务单、支付方式查找最新一条待支付记录
// 用于支付宝支付单复用:同一业务单同一支付方式只允许一个有效 pending 支付单
func (s *PaymentStore) FindLatestPendingByOrderAndMethod(ctx context.Context, orderID uint, orderType string, paymentMethod string) (*model.Payment, error) {
var payment model.Payment
err := s.db.WithContext(ctx).
Where("order_id = ? AND order_type = ? AND payment_method = ? AND status = ?",
orderID, orderType, paymentMethod, model.PaymentRecordStatusPending).
Order("created_at DESC").
First(&payment).Error
if err != nil {
return nil, err
}
return &payment, nil
}