mirror of
https://gitee.com/technical-laohu/mpay_v2_webman.git
synced 2026-04-26 03:54:25 +08:00
重构初始化
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user