mirror of
https://gitee.com/technical-laohu/mpay_v2_webman.git
synced 2026-04-23 18:44:26 +08:00
重构初始化
This commit is contained in:
52
app/repository/account/balance/MerchantAccountRepository.php
Normal file
52
app/repository/account/balance/MerchantAccountRepository.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\account\balance;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\merchant\MerchantAccount;
|
||||
|
||||
/**
|
||||
* 商户余额账户仓库。
|
||||
*/
|
||||
class MerchantAccountRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new MerchantAccount());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商户 ID 查询余额账户。
|
||||
*/
|
||||
public function findByMerchantId(int $merchantId, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('merchant_id', $merchantId)
|
||||
->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商户 ID 加锁查询余额账户。
|
||||
*/
|
||||
public function findForUpdateByMerchantId(int $merchantId, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('merchant_id', $merchantId)
|
||||
->lockForUpdate()
|
||||
->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计商户是否存在资金账户。
|
||||
*/
|
||||
public function countByMerchantId(int $merchantId): int
|
||||
{
|
||||
return (int) $this->model->newQuery()
|
||||
->where('merchant_id', $merchantId)
|
||||
->count();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\account\ledger;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\merchant\MerchantAccountLedger;
|
||||
|
||||
/**
|
||||
* 商户余额流水仓库。
|
||||
*/
|
||||
class MerchantAccountLedgerRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new MerchantAccountLedger());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据幂等键查询流水记录。
|
||||
*/
|
||||
public function findByIdempotencyKey(string $idempotencyKey, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('idempotency_key', $idempotencyKey)
|
||||
->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据追踪号查询流水记录。
|
||||
*/
|
||||
public function findByTraceNo(string $traceNo, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('trace_no', $traceNo)
|
||||
->orderByDesc('id')
|
||||
->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 listByMerchantAndBiz(int $merchantId, int $bizType, string $bizNo, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('merchant_id', $merchantId)
|
||||
->where('biz_type', $bizType)
|
||||
->where('biz_no', $bizNo)
|
||||
->orderByDesc('id')
|
||||
->get($columns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
24
app/repository/file/FileRecordRepository.php
Normal file
24
app/repository/file/FileRecordRepository.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\file;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\file\FileRecord;
|
||||
|
||||
/**
|
||||
* 文件仓储。
|
||||
*/
|
||||
class FileRecordRepository extends BaseRepository
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new FileRecord());
|
||||
}
|
||||
|
||||
public function findById(int $id, array $columns = ['*']): ?FileRecord
|
||||
{
|
||||
$model = $this->find($id, $columns);
|
||||
|
||||
return $model instanceof FileRecord ? $model : null;
|
||||
}
|
||||
}
|
||||
47
app/repository/merchant/base/MerchantGroupRepository.php
Normal file
47
app/repository/merchant/base/MerchantGroupRepository.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\merchant\base;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\merchant\MerchantGroup;
|
||||
|
||||
/**
|
||||
* 商户分组仓库。
|
||||
*/
|
||||
class MerchantGroupRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new MerchantGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有启用的商户分组。
|
||||
*/
|
||||
public function enabledList(array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('status', 1)
|
||||
->orderBy('id', 'asc')
|
||||
->get($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断分组名称是否已存在。
|
||||
*/
|
||||
public function existsByGroupName(string $groupName, int $ignoreId = 0): bool
|
||||
{
|
||||
$query = $this->model->newQuery()
|
||||
->where('group_name', $groupName);
|
||||
|
||||
if ($ignoreId > 0) {
|
||||
$query->where('id', '<>', $ignoreId);
|
||||
}
|
||||
|
||||
return $query->exists();
|
||||
}
|
||||
}
|
||||
|
||||
32
app/repository/merchant/base/MerchantPolicyRepository.php
Normal file
32
app/repository/merchant/base/MerchantPolicyRepository.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\merchant\base;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\merchant\MerchantPolicy;
|
||||
|
||||
/**
|
||||
* 商户策略仓库。
|
||||
*/
|
||||
class MerchantPolicyRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new MerchantPolicy());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商户 ID 查询商户策略。
|
||||
*/
|
||||
public function findByMerchantId(int $merchantId, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('merchant_id', $merchantId)
|
||||
->first($columns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
43
app/repository/merchant/base/MerchantRepository.php
Normal file
43
app/repository/merchant/base/MerchantRepository.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\merchant\base;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\merchant\Merchant;
|
||||
|
||||
/**
|
||||
* 商户仓库。
|
||||
*/
|
||||
class MerchantRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new Merchant());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商户编号查询商户。
|
||||
*/
|
||||
public function findByMerchantNo(string $merchantNo, array $columns = ['*']): ?Merchant
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('merchant_no', $merchantNo)
|
||||
->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有启用的商户。
|
||||
*/
|
||||
public function enabledList(array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('status', 1)
|
||||
->orderBy('id', 'desc')
|
||||
->get($columns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\merchant\credential;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\merchant\MerchantApiCredential;
|
||||
|
||||
/**
|
||||
* 商户 API 凭证仓库。
|
||||
*/
|
||||
class MerchantApiCredentialRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new MerchantApiCredential());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商户 ID 查询 API 凭证。
|
||||
*/
|
||||
public function findByMerchantId(int $merchantId, array $columns = ['*']): ?MerchantApiCredential
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('merchant_id', $merchantId)
|
||||
->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计商户是否已开通 API 凭证。
|
||||
*/
|
||||
public function countByMerchantId(int $merchantId): int
|
||||
{
|
||||
return (int) $this->model->newQuery()
|
||||
->where('merchant_id', $merchantId)
|
||||
->count();
|
||||
}
|
||||
}
|
||||
|
||||
44
app/repository/ops/log/ChannelNotifyLogRepository.php
Normal file
44
app/repository/ops/log/ChannelNotifyLogRepository.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\ops\log;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\admin\ChannelNotifyLog;
|
||||
|
||||
/**
|
||||
* 渠道通知日志仓库。
|
||||
*/
|
||||
class ChannelNotifyLogRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new ChannelNotifyLog());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据通知单号查询渠道通知日志。
|
||||
*/
|
||||
public function findByNotifyNo(string $notifyNo, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('notify_no', $notifyNo)
|
||||
->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据渠道、通知类型和业务单号查询重复通知记录。
|
||||
*/
|
||||
public function findDuplicate(int $channelId, int $notifyType, string $bizNo, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('channel_id', $channelId)
|
||||
->where('notify_type', $notifyType)
|
||||
->where('biz_no', $bizNo)
|
||||
->first($columns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
33
app/repository/ops/log/PayCallbackLogRepository.php
Normal file
33
app/repository/ops/log/PayCallbackLogRepository.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\ops\log;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\admin\PayCallbackLog;
|
||||
|
||||
/**
|
||||
* 支付回调日志仓库。
|
||||
*/
|
||||
class PayCallbackLogRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new PayCallbackLog());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据支付单号查询回调日志列表。
|
||||
*/
|
||||
public function listByPayNo(string $payNo, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('pay_no', $payNo)
|
||||
->orderByDesc('id')
|
||||
->get($columns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
33
app/repository/ops/stat/ChannelDailyStatRepository.php
Normal file
33
app/repository/ops/stat/ChannelDailyStatRepository.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\ops\stat;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\admin\ChannelDailyStat;
|
||||
|
||||
/**
|
||||
* 通道日统计仓库。
|
||||
*/
|
||||
class ChannelDailyStatRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new ChannelDailyStat());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据通道和日期查询统计记录。
|
||||
*/
|
||||
public function findByChannelAndDate(int $channelId, string $statDate, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('channel_id', $channelId)
|
||||
->where('stat_date', $statDate)
|
||||
->first($columns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
81
app/repository/payment/config/PaymentChannelRepository.php
Normal file
81
app/repository/payment/config/PaymentChannelRepository.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\payment\config;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\payment\PaymentChannel;
|
||||
|
||||
/**
|
||||
* 支付通道仓库。
|
||||
*/
|
||||
class PaymentChannelRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new PaymentChannel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定商户启用的支付通道。
|
||||
*/
|
||||
public function enabledByMerchantId(int $merchantId, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('merchant_id', $merchantId)
|
||||
->where('status', 1)
|
||||
->orderBy('sort_no')
|
||||
->get($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商户 ID 和通道 ID 查询通道。
|
||||
*/
|
||||
public function findByMerchantAndId(int $merchantId, int $channelId, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('merchant_id', $merchantId)
|
||||
->whereKey($channelId)
|
||||
->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断通道名称是否已存在。
|
||||
*/
|
||||
public function existsByName(string $name, int $ignoreId = 0): bool
|
||||
{
|
||||
$query = $this->model->newQuery()
|
||||
->where('name', $name);
|
||||
|
||||
if ($ignoreId > 0) {
|
||||
$query->where('id', '<>', $ignoreId);
|
||||
}
|
||||
|
||||
return $query->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计商户名下的支付通道概览。
|
||||
*/
|
||||
public function summaryByMerchantId(int $merchantId): object
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->selectRaw('COUNT(*) AS total_count')
|
||||
->selectRaw('SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) AS enabled_count')
|
||||
->selectRaw('SUM(CASE WHEN channel_mode = 1 THEN 1 ELSE 0 END) AS self_count')
|
||||
->where('merchant_id', $merchantId)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计商户下的支付通道数量。
|
||||
*/
|
||||
public function countByMerchantId(int $merchantId): int
|
||||
{
|
||||
return (int) $this->model->newQuery()
|
||||
->where('merchant_id', $merchantId)
|
||||
->count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\payment\config;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\payment\PaymentPluginConf;
|
||||
|
||||
/**
|
||||
* 支付插件配置仓库。
|
||||
*/
|
||||
class PaymentPluginConfRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new PaymentPluginConf());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据插件编码查询插件配置。
|
||||
*/
|
||||
public function findByPluginCode(string $pluginCode, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('plugin_code', $pluginCode)
|
||||
->orderByDesc('id')
|
||||
->first($columns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
43
app/repository/payment/config/PaymentPluginRepository.php
Normal file
43
app/repository/payment/config/PaymentPluginRepository.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\payment\config;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\payment\PaymentPlugin;
|
||||
|
||||
/**
|
||||
* 支付插件仓库。
|
||||
*/
|
||||
class PaymentPluginRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new PaymentPlugin());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据插件编码查询支付插件。
|
||||
*/
|
||||
public function findByCode(string $code, array $columns = ['*']): ?PaymentPlugin
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->whereKey($code)
|
||||
->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有启用的支付插件。
|
||||
*/
|
||||
public function enabledList(array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('status', 1)
|
||||
->orderBy('code', 'asc')
|
||||
->get($columns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\payment\config;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\payment\PaymentPollGroupBind;
|
||||
|
||||
/**
|
||||
* 商户分组与轮询组绑定仓库。
|
||||
*/
|
||||
class PaymentPollGroupBindRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new PaymentPollGroupBind());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商户分组和支付方式查询启用的绑定关系。
|
||||
*/
|
||||
public function findActiveByMerchantGroupAndPayType(int $merchantGroupId, int $payTypeId, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('merchant_group_id', $merchantGroupId)
|
||||
->where('pay_type_id', $payTypeId)
|
||||
->where('status', 1)
|
||||
->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商户分组下的路由绑定概览。
|
||||
*/
|
||||
public function listSummaryByMerchantGroupId(int $merchantGroupId)
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->from('ma_payment_poll_group_bind as b')
|
||||
->leftJoin('ma_payment_type as t', 'b.pay_type_id', '=', 't.id')
|
||||
->leftJoin('ma_payment_poll_group as p', 'b.poll_group_id', '=', 'p.id')
|
||||
->where('b.merchant_group_id', $merchantGroupId)
|
||||
->orderBy('b.id')
|
||||
->get([
|
||||
'b.id',
|
||||
'b.pay_type_id',
|
||||
'b.poll_group_id',
|
||||
'b.status',
|
||||
'b.remark',
|
||||
't.code as pay_type_code',
|
||||
't.name as pay_type_name',
|
||||
'p.group_name as poll_group_name',
|
||||
'p.route_mode',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\payment\config;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\payment\PaymentPollGroupChannel;
|
||||
|
||||
/**
|
||||
* 轮询组与通道编排仓库。
|
||||
*/
|
||||
class PaymentPollGroupChannelRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new PaymentPollGroupChannel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询轮询组下的通道编排列表。
|
||||
*/
|
||||
public function listByPollGroupId(int $pollGroupId, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('poll_group_id', $pollGroupId)
|
||||
->where('status', 1)
|
||||
->orderBy('sort_no')
|
||||
->get($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空轮询组下其他默认通道标记。
|
||||
*/
|
||||
public function clearDefaultExcept(int $pollGroupId, int $ignoreId = 0): int
|
||||
{
|
||||
$query = $this->model->newQuery()
|
||||
->where('poll_group_id', $pollGroupId)
|
||||
->where('is_default', 1);
|
||||
|
||||
if ($ignoreId > 0) {
|
||||
$query->where('id', '<>', $ignoreId);
|
||||
}
|
||||
|
||||
return (int) $query->update(['is_default' => 0]);
|
||||
}
|
||||
}
|
||||
|
||||
35
app/repository/payment/config/PaymentPollGroupRepository.php
Normal file
35
app/repository/payment/config/PaymentPollGroupRepository.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\payment\config;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\payment\PaymentPollGroup;
|
||||
|
||||
/**
|
||||
* 支付轮询组仓库。
|
||||
*/
|
||||
class PaymentPollGroupRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new PaymentPollGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断轮询组名称是否已存在。
|
||||
*/
|
||||
public function existsByGroupName(string $groupName, int $ignoreId = 0): bool
|
||||
{
|
||||
$query = $this->model->newQuery()
|
||||
->where('group_name', $groupName);
|
||||
|
||||
if ($ignoreId > 0) {
|
||||
$query->where('id', '<>', $ignoreId);
|
||||
}
|
||||
|
||||
return $query->exists();
|
||||
}
|
||||
}
|
||||
43
app/repository/payment/config/PaymentTypeRepository.php
Normal file
43
app/repository/payment/config/PaymentTypeRepository.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\payment\config;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\payment\PaymentType;
|
||||
|
||||
/**
|
||||
* 支付方式字典仓库。
|
||||
*/
|
||||
class PaymentTypeRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new PaymentType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有启用的支付方式。
|
||||
*/
|
||||
public function enabledList(array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('status', 1)
|
||||
->orderBy('sort_no')
|
||||
->get($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据支付方式编码查询字典。
|
||||
*/
|
||||
public function findByCode(string $code, array $columns = ['*']): ?PaymentType
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('code', $code)
|
||||
->first($columns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
43
app/repository/payment/notify/NotifyTaskRepository.php
Normal file
43
app/repository/payment/notify/NotifyTaskRepository.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\payment\notify;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\payment\NotifyTask;
|
||||
|
||||
/**
|
||||
* 商户通知任务仓库。
|
||||
*/
|
||||
class NotifyTaskRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new NotifyTask());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据通知单号查询通知任务。
|
||||
*/
|
||||
public function findByNotifyNo(string $notifyNo, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('notify_no', $notifyNo)
|
||||
->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询可重试的通知任务列表。
|
||||
*/
|
||||
public function listRetryable(int $status, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('status', $status)
|
||||
->orderBy('next_retry_at')
|
||||
->get($columns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\payment\settlement;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\payment\SettlementItem;
|
||||
|
||||
/**
|
||||
* 清算明细仓库。
|
||||
*/
|
||||
class SettlementItemRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new SettlementItem());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定清算单下的明细列表。
|
||||
*/
|
||||
public function listBySettleNo(string $settleNo, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('settle_no', $settleNo)
|
||||
->orderBy('id')
|
||||
->get($columns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
114
app/repository/payment/settlement/SettlementOrderRepository.php
Normal file
114
app/repository/payment/settlement/SettlementOrderRepository.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\payment\settlement;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\payment\SettlementOrder;
|
||||
|
||||
/**
|
||||
* 清算单仓库。
|
||||
*/
|
||||
class SettlementOrderRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new SettlementOrder());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据清算单号查询清算单。
|
||||
*/
|
||||
public function findBySettleNo(string $settleNo, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('settle_no', $settleNo)
|
||||
->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 findByCycle(int $merchantId, int $channelId, int $cycleType, string $cycleKey, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('merchant_id', $merchantId)
|
||||
->where('channel_id', $channelId)
|
||||
->where('cycle_type', $cycleType)
|
||||
->where('cycle_key', $cycleKey)
|
||||
->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据清算单号加锁查询清算单。
|
||||
*/
|
||||
public function findForUpdateBySettleNo(string $settleNo, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('settle_no', $settleNo)
|
||||
->lockForUpdate()
|
||||
->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据追踪号加锁查询清算单。
|
||||
*/
|
||||
public function findForUpdateByTraceNo(string $traceNo, array $columns = ['*'])
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('trace_no', $traceNo)
|
||||
->lockForUpdate()
|
||||
->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商户最近清算单列表,用于总览展示。
|
||||
*/
|
||||
public function recentByMerchantId(int $merchantId, int $limit = 5)
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('merchant_id', $merchantId)
|
||||
->orderByDesc('id')
|
||||
->limit(max(1, $limit))
|
||||
->get([
|
||||
'settle_no',
|
||||
'net_amount',
|
||||
'status',
|
||||
'cycle_key',
|
||||
'created_at',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计商户下的清算单数量。
|
||||
*/
|
||||
public function countByMerchantId(int $merchantId): int
|
||||
{
|
||||
return (int) $this->model->newQuery()
|
||||
->where('merchant_id', $merchantId)
|
||||
->count();
|
||||
}
|
||||
}
|
||||
107
app/repository/payment/trade/BizOrderRepository.php
Normal file
107
app/repository/payment/trade/BizOrderRepository.php
Normal 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();
|
||||
}
|
||||
}
|
||||
|
||||
143
app/repository/payment/trade/PayOrderRepository.php
Normal file
143
app/repository/payment/trade/PayOrderRepository.php
Normal 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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
127
app/repository/payment/trade/RefundOrderRepository.php
Normal file
127
app/repository/payment/trade/RefundOrderRepository.php
Normal 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();
|
||||
}
|
||||
}
|
||||
|
||||
20
app/repository/system/config/SystemConfigRepository.php
Normal file
20
app/repository/system/config/SystemConfigRepository.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\system\config;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\system\SystemConfig;
|
||||
|
||||
/**
|
||||
* 系统配置仓库。
|
||||
*/
|
||||
class SystemConfigRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new SystemConfig());
|
||||
}
|
||||
}
|
||||
32
app/repository/system/user/AdminUserRepository.php
Normal file
32
app/repository/system/user/AdminUserRepository.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace app\repository\system\user;
|
||||
|
||||
use app\common\base\BaseRepository;
|
||||
use app\model\admin\AdminUser;
|
||||
|
||||
/**
|
||||
* 管理员账号仓库。
|
||||
*/
|
||||
class AdminUserRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入对应模型。
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new AdminUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名查询管理员。
|
||||
*/
|
||||
public function findByUsername(string $username, array $columns = ['*']): ?AdminUser
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('username', $username)
|
||||
->first($columns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user