重构初始化

This commit is contained in:
技术老胡
2026-04-15 11:45:46 +08:00
parent 72d72d735b
commit 7612026773
381 changed files with 28287 additions and 14717 deletions

View File

@@ -0,0 +1,107 @@
<?php
namespace app\repository\payment\trade;
use app\common\base\BaseRepository;
use app\model\payment\BizOrder;
/**
* 业务订单仓库。
*/
class BizOrderRepository extends BaseRepository
{
/**
* 构造函数,注入对应模型。
*/
public function __construct()
{
parent::__construct(new BizOrder());
}
/**
* 根据业务单号查询业务订单。
*/
public function findByBizNo(string $bizNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('biz_no', $bizNo)
->first($columns);
}
/**
* 根据追踪号查询业务订单。
*/
public function findByTraceNo(string $traceNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('trace_no', $traceNo)
->first($columns);
}
/**
* 根据商户 ID 和商户订单号查询业务订单。
*/
public function findByMerchantAndOrderNo(int $merchantId, string $merchantOrderNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('merchant_id', $merchantId)
->where('merchant_order_no', $merchantOrderNo)
->first($columns);
}
/**
* 根据业务单号查询当前有效的业务订单。
*/
public function findActiveByBizNo(string $bizNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('biz_no', $bizNo)
->whereIn('status', [0, 1])
->first($columns);
}
/**
* 根据业务单号加锁查询业务订单。
*/
public function findForUpdateByBizNo(string $bizNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('biz_no', $bizNo)
->lockForUpdate()
->first($columns);
}
/**
* 根据追踪号加锁查询业务订单。
*/
public function findForUpdateByTraceNo(string $traceNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('trace_no', $traceNo)
->lockForUpdate()
->first($columns);
}
/**
* 根据商户 ID 和商户订单号加锁查询业务订单。
*/
public function findForUpdateByMerchantAndOrderNo(int $merchantId, string $merchantOrderNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('merchant_id', $merchantId)
->where('merchant_order_no', $merchantOrderNo)
->lockForUpdate()
->first($columns);
}
/**
* 统计商户下的业务订单数量。
*/
public function countByMerchantId(int $merchantId): int
{
return (int) $this->model->newQuery()
->where('merchant_id', $merchantId)
->count();
}
}

View File

@@ -0,0 +1,143 @@
<?php
namespace app\repository\payment\trade;
use app\common\base\BaseRepository;
use app\model\payment\PayOrder;
/**
* 支付单仓库。
*/
class PayOrderRepository extends BaseRepository
{
/**
* 构造函数,注入对应模型。
*/
public function __construct()
{
parent::__construct(new PayOrder());
}
/**
* 根据支付单号查询支付单。
*/
public function findByPayNo(string $payNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('pay_no', $payNo)
->first($columns);
}
/**
* 根据追踪号查询支付单。
*/
public function findByTraceNo(string $traceNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('trace_no', $traceNo)
->first($columns);
}
/**
* 根据追踪号查询支付单列表。
*/
public function listByTraceNo(string $traceNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('trace_no', $traceNo)
->orderByDesc('attempt_no')
->orderByDesc('id')
->get($columns);
}
/**
* 根据业务单号查询支付单列表。
*/
public function listByBizNo(string $bizNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('biz_no', $bizNo)
->orderByDesc('attempt_no')
->orderByDesc('id')
->get($columns);
}
/**
* 根据业务单号查询最新支付单。
*/
public function findLatestByBizNo(string $bizNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('biz_no', $bizNo)
->orderByDesc('attempt_no')
->first($columns);
}
/**
* 根据商户和渠道请求号查询支付单。
*/
public function findByChannelRequestNo(int $merchantId, string $channelRequestNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('merchant_id', $merchantId)
->where('channel_request_no', $channelRequestNo)
->first($columns);
}
/**
* 根据支付单号加锁查询支付单。
*/
public function findForUpdateByPayNo(string $payNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('pay_no', $payNo)
->lockForUpdate()
->first($columns);
}
/**
* 根据追踪号加锁查询支付单。
*/
public function findForUpdateByTraceNo(string $traceNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('trace_no', $traceNo)
->lockForUpdate()
->first($columns);
}
/**
* 根据业务单号加锁查询最新支付单。
*/
public function findLatestForUpdateByBizNo(string $bizNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('biz_no', $bizNo)
->orderByDesc('attempt_no')
->lockForUpdate()
->first($columns);
}
/**
* 查询商户最近支付单列表,用于总览展示。
*/
public function recentByMerchantId(int $merchantId, int $limit = 5)
{
return $this->model->newQuery()
->from('ma_pay_order as po')
->leftJoin('ma_payment_type as t', 'po.pay_type_id', '=', 't.id')
->leftJoin('ma_payment_channel as c', 'po.channel_id', '=', 'c.id')
->where('po.merchant_id', $merchantId)
->orderByDesc('po.id')
->limit(max(1, $limit))
->get([
'po.pay_no',
'po.pay_amount',
'po.status',
'po.created_at',
't.name as pay_type_name',
'c.name as channel_name',
]);
}
}

View File

@@ -0,0 +1,127 @@
<?php
namespace app\repository\payment\trade;
use app\common\base\BaseRepository;
use app\model\payment\RefundOrder;
/**
* 退款单仓库。
*/
class RefundOrderRepository extends BaseRepository
{
/**
* 构造函数,注入对应模型。
*/
public function __construct()
{
parent::__construct(new RefundOrder());
}
/**
* 根据退款单号查询退款单。
*/
public function findByRefundNo(string $refundNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('refund_no', $refundNo)
->first($columns);
}
/**
* 根据追踪号查询退款单。
*/
public function findByTraceNo(string $traceNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('trace_no', $traceNo)
->first($columns);
}
/**
* 根据追踪号查询退款单列表。
*/
public function listByTraceNo(string $traceNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('trace_no', $traceNo)
->orderByDesc('id')
->get($columns);
}
/**
* 根据业务单号查询退款单列表。
*/
public function listByBizNo(string $bizNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('biz_no', $bizNo)
->orderByDesc('id')
->get($columns);
}
/**
* 根据商户退款单号查询退款单。
*/
public function findByMerchantRefundNo(int $merchantId, string $merchantRefundNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('merchant_id', $merchantId)
->where('merchant_refund_no', $merchantRefundNo)
->first($columns);
}
/**
* 根据支付单号查询退款单。
*/
public function findByPayNo(string $payNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('pay_no', $payNo)
->first($columns);
}
/**
* 根据退款单号加锁查询退款单。
*/
public function findForUpdateByRefundNo(string $refundNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('refund_no', $refundNo)
->lockForUpdate()
->first($columns);
}
/**
* 根据追踪号加锁查询退款单。
*/
public function findForUpdateByTraceNo(string $traceNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('trace_no', $traceNo)
->lockForUpdate()
->first($columns);
}
/**
* 根据支付单号加锁查询退款单。
*/
public function findForUpdateByPayNo(string $payNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('pay_no', $payNo)
->lockForUpdate()
->first($columns);
}
/**
* 统计商户下的退款订单数量。
*/
public function countByMerchantId(int $merchantId): int
{
return (int) $this->model->newQuery()
->where('merchant_id', $merchantId)
->count();
}
}