1. 维护代码健壮

2. 更新项目结构文档
This commit is contained in:
技术老胡
2026-04-27 16:20:41 +08:00
parent 9a16a88640
commit 0e5de50337
198 changed files with 21038 additions and 702 deletions

View File

@@ -73,6 +73,27 @@ class PaymentChannelRepository extends BaseRepository
return $query->exists();
}
/**
* 判断指定商户的通道名称是否已存在。
*
* @param int $merchantId 商户ID
* @param string $name 通道名称
* @param int $ignoreId 需要排除的记录ID
* @return bool 是否存在
*/
public function existsByMerchantName(int $merchantId, string $name, int $ignoreId = 0): bool
{
$query = $this->model->newQuery()
->where('merchant_id', $merchantId)
->where('name', $name);
if ($ignoreId > 0) {
$query->where('id', '<>', $ignoreId);
}
return $query->exists();
}
/**
* 统计商户名下的支付通道概览。
*
@@ -104,4 +125,3 @@ class PaymentChannelRepository extends BaseRepository
}

View File

@@ -32,14 +32,30 @@ class PaymentPluginConfRepository extends BaseRepository
public function findByPluginCode(string $pluginCode, array $columns = ['*'])
{
return $this->model->newQuery()
->where('merchant_id', 0)
->where('plugin_code', $pluginCode)
->orderByDesc('id')
->first($columns);
}
/**
* 查询当前商户可访问的插件配置。
*
* @param int $merchantId 商户ID
* @param int $id 配置ID
* @param array $columns 字段列表
* @return PaymentPluginConf|null 插件配置记录
*/
public function findByMerchantAndId(int $merchantId, int $id, array $columns = ['*'])
{
return $this->model->newQuery()
->where('merchant_id', $merchantId)
->whereKey($id)
->first($columns);
}
}

View File

@@ -49,10 +49,40 @@ class PaymentPluginRepository extends BaseRepository
->orderBy('code', 'asc')
->get($columns);
}
/**
* 获取商户端允许使用的支付插件。
*
* @param array $columns 字段列表
* @return \Illuminate\Database\Eloquent\Collection<int, PaymentPlugin> 插件列表
*/
public function merchantEnabledList(array $columns = ['*'])
{
return $this->model->newQuery()
->where('status', 1)
->where('allow_merchant', 1)
->orderBy('code', 'asc')
->get($columns);
}
/**
* 查询商户端允许使用的支付插件。
*
* @param string $code 插件编码
* @param array $columns 字段列表
* @return PaymentPlugin|null 插件记录
*/
public function findMerchantAllowed(string $code, array $columns = ['*']): ?PaymentPlugin
{
return $this->model->newQuery()
->whereKey($code)
->where('status', 1)
->where('allow_merchant', 1)
->first($columns);
}
}

View File

@@ -36,6 +36,37 @@ class NotifyTaskRepository extends BaseRepository
->first($columns);
}
/**
* 根据通知事件和引用单号查询通知任务。
*
* @param string $eventType 通知事件类型
* @param string $refNo 事件引用单号
* @param array $columns 字段列表
* @return NotifyTask|null 通知任务记录
*/
public function findByEventRef(string $eventType, string $refNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('event_type', $eventType)
->where('ref_no', $refNo)
->first($columns);
}
/**
* 查询指定支付单的通知任务列表。
*
* @param string $payNo 支付单号
* @param array $columns 字段列表
* @return \Illuminate\Database\Eloquent\Collection<int, NotifyTask> 通知任务列表
*/
public function listByPayNo(string $payNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('pay_no', $payNo)
->orderByDesc('id')
->get($columns);
}
/**
* 查询可重试的通知任务列表。
*
@@ -47,6 +78,8 @@ class NotifyTaskRepository extends BaseRepository
{
return $this->model->newQuery()
->where('status', $status)
->whereNotNull('next_retry_at')
->where('next_retry_at', '<=', date('Y-m-d H:i:s'))
->orderBy('next_retry_at')
->get($columns);
}
@@ -54,6 +87,3 @@ class NotifyTaskRepository extends BaseRepository

View File

@@ -3,6 +3,7 @@
namespace app\repository\payment\trade;
use app\common\base\BaseRepository;
use app\common\constant\TradeConstant;
use app\model\payment\PayOrder;
/**
@@ -159,6 +160,47 @@ class PayOrderRepository extends BaseRepository
->first($columns);
}
/**
* 查询已过期但还未进入终态的支付单。
*
* @param string $now 当前时间
* @param int $limit 限制条数
* @return \Illuminate\Database\Eloquent\Collection<int, PayOrder> 支付单列表
*/
public function listExpiredMutable(string $now, int $limit = 100)
{
return $this->model->newQuery()
->whereIn('status', TradeConstant::orderMutableStatuses())
->whereNotNull('expire_at')
->where('expire_at', '<=', $now)
->orderBy('expire_at')
->orderBy('id')
->limit(max(1, $limit))
->get();
}
/**
* 查询需要主动查单的支付中订单。
*
* @param string $before 最早拉起时间
* @param int $limit 限制条数
* @return \Illuminate\Database\Eloquent\Collection<int, PayOrder> 支付单列表
*/
public function listPayingForActiveQuery(string $before, int $limit = 50)
{
return $this->model->newQuery()
->where('status', TradeConstant::ORDER_STATUS_PAYING)
->where('request_at', '<=', $before)
->where(function ($query) {
$query->whereNull('expire_at')
->orWhere('expire_at', '>', date('Y-m-d H:i:s'));
})
->orderBy('request_at')
->orderBy('id')
->limit(max(1, $limit))
->get();
}
/**
* 查询商户最近支付单列表,用于总览展示。
*
@@ -189,4 +231,3 @@ class PayOrderRepository extends BaseRepository

View File

@@ -107,6 +107,7 @@ class RefundOrderRepository extends BaseRepository
{
return $this->model->newQuery()
->where('pay_no', $payNo)
->orderByDesc('id')
->first($columns);
}
@@ -151,6 +152,7 @@ class RefundOrderRepository extends BaseRepository
{
return $this->model->newQuery()
->where('pay_no', $payNo)
->orderByDesc('id')
->lockForUpdate()
->first($columns);
}
@@ -171,5 +173,3 @@ class RefundOrderRepository extends BaseRepository

View File

@@ -0,0 +1,50 @@
<?php
namespace app\repository\payment\trade;
use app\common\base\BaseRepository;
use app\model\payment\TransferOrder;
/**
* 转账单仓库。
*/
class TransferOrderRepository extends BaseRepository
{
public function __construct()
{
parent::__construct(new TransferOrder());
}
public function findByBizNo(string $bizNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('biz_no', $bizNo)
->first($columns);
}
public function findByOutBizNo(int $merchantId, string $outBizNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('merchant_id', $merchantId)
->where('out_biz_no', $outBizNo)
->first($columns);
}
public function findForUpdateByBizNo(string $bizNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('biz_no', $bizNo)
->lockForUpdate()
->first($columns);
}
public function findForUpdateByOutBizNo(int $merchantId, string $outBizNo, array $columns = ['*'])
{
return $this->model->newQuery()
->where('merchant_id', $merchantId)
->where('out_biz_no', $outBizNo)
->lockForUpdate()
->first($columns);
}
}