You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
3.4 KiB
Go
135 lines
3.4 KiB
Go
package repo
|
|
|
|
import (
|
|
"cls/internal/domain/payment"
|
|
"cls/pkg/logger"
|
|
"cls/pkg/util/page"
|
|
"cls/pkg/xorm_engine"
|
|
"errors"
|
|
"xorm.io/builder"
|
|
)
|
|
|
|
// PaymentRepositoryORM 支付订单仓储实现
|
|
type PaymentRepositoryORM struct {
|
|
engine *xorm_engine.Engine
|
|
log logger.Logger
|
|
}
|
|
|
|
func (r *PaymentRepositoryORM) Create(payment *payment.Payment) error {
|
|
//TODO implement me
|
|
panic("implement me")
|
|
}
|
|
|
|
func (r *PaymentRepositoryORM) GetByID(id uint64) (*payment.Payment, error) {
|
|
//TODO implement me
|
|
panic("implement me")
|
|
}
|
|
|
|
func (r *PaymentRepositoryORM) GetByOrderNo(orderNo string) (*payment.Payment, error) {
|
|
//TODO implement me
|
|
panic("implement me")
|
|
}
|
|
|
|
func (r *PaymentRepositoryORM) GetByTransactionID(transactionID string) (*payment.Payment, error) {
|
|
//TODO implement me
|
|
panic("implement me")
|
|
}
|
|
|
|
func (r *PaymentRepositoryORM) ListByUserID(userID uint64, page *page.Page, conds []builder.Cond) error {
|
|
//TODO implement me
|
|
panic("implement me")
|
|
}
|
|
|
|
func (r *PaymentRepositoryORM) FindAll(page *page.Page, conds []builder.Cond) error {
|
|
//TODO implement me
|
|
panic("implement me")
|
|
}
|
|
|
|
var _ payment.PaymentRepository = (*PaymentRepositoryORM)(nil)
|
|
|
|
// NewPaymentRepositoryORM 创建支付订单仓储实现
|
|
func NewPaymentRepositoryORM(engine *xorm_engine.Engine, log logger.New) *PaymentRepositoryORM {
|
|
return &PaymentRepositoryORM{
|
|
engine: engine,
|
|
log: log("cls:repo:payment"),
|
|
}
|
|
}
|
|
|
|
// Save 保存支付订单
|
|
func (r *PaymentRepositoryORM) Save(payment *payment.Payment) error {
|
|
if _, err := r.engine.Insert(payment); err != nil {
|
|
r.log.Error(err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// FindByID 根据ID获取支付订单
|
|
func (r *PaymentRepositoryORM) FindByID(id uint64) (*payment.Payment, error) {
|
|
payment := &payment.Payment{}
|
|
has, err := r.engine.ID(id).Get(payment)
|
|
if err != nil {
|
|
r.log.Error(err)
|
|
return nil, err
|
|
}
|
|
if !has {
|
|
return nil, errors.New("支付订单不存在")
|
|
}
|
|
return payment, nil
|
|
}
|
|
|
|
// FindByOrderNo 根据订单号获取支付订单
|
|
func (r *PaymentRepositoryORM) FindByOrderNo(orderNo string) (*payment.Payment, error) {
|
|
payment := &payment.Payment{}
|
|
has, err := r.engine.Where(builder.Eq{"order_no": orderNo}).Get(payment)
|
|
if err != nil {
|
|
r.log.Error(err)
|
|
return nil, err
|
|
}
|
|
if !has {
|
|
return nil, errors.New("支付订单不存在")
|
|
}
|
|
return payment, nil
|
|
}
|
|
|
|
// FindByTransactionID 根据交易号获取支付订单
|
|
func (r *PaymentRepositoryORM) FindByTransactionID(transactionID string) (*payment.Payment, error) {
|
|
payment := &payment.Payment{}
|
|
has, err := r.engine.Where(builder.Eq{"transaction_id": transactionID}).Get(payment)
|
|
if err != nil {
|
|
r.log.Error(err)
|
|
return nil, err
|
|
}
|
|
if !has {
|
|
return nil, errors.New("支付订单不存在")
|
|
}
|
|
return payment, nil
|
|
}
|
|
|
|
// Update 更新支付订单
|
|
func (r *PaymentRepositoryORM) Update(payment *payment.Payment) error {
|
|
if _, err := r.engine.ID(payment.ID).Update(payment); err != nil {
|
|
r.log.Error(err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// UpdateStatus 更新支付订单状态
|
|
func (r *PaymentRepositoryORM) UpdateStatus(id uint64, status payment.PaymentStatus) error {
|
|
if _, err := r.engine.ID(id).Update(&payment.Payment{Status: status}); err != nil {
|
|
r.log.Error(err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Delete 删除支付订单
|
|
func (r *PaymentRepositoryORM) Delete(id uint64) error {
|
|
if _, err := r.engine.ID(id).Delete(&payment.Payment{}); err != nil {
|
|
r.log.Error(err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|