mirror of
https://gitee.com/technical-laohu/mpay_v2_webman.git
synced 2026-04-24 19:14:27 +08:00
重构初始化
This commit is contained in:
154
app/service/ops/log/ChannelNotifyLogService.php
Normal file
154
app/service/ops/log/ChannelNotifyLogService.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace app\service\ops\log;
|
||||
|
||||
use app\common\base\BaseService;
|
||||
use app\common\constant\NotifyConstant;
|
||||
use app\model\admin\ChannelNotifyLog;
|
||||
use app\repository\ops\log\ChannelNotifyLogRepository;
|
||||
|
||||
/**
|
||||
* 渠道通知日志查询服务。
|
||||
*/
|
||||
class ChannelNotifyLogService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入渠道通知日志仓库。
|
||||
*/
|
||||
public function __construct(
|
||||
protected ChannelNotifyLogRepository $channelNotifyLogRepository
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询渠道通知日志。
|
||||
*/
|
||||
public function paginate(array $filters = [], int $page = 1, int $pageSize = 10)
|
||||
{
|
||||
$query = $this->baseQuery();
|
||||
|
||||
$keyword = trim((string) ($filters['keyword'] ?? ''));
|
||||
if ($keyword !== '') {
|
||||
$query->where(function ($builder) use ($keyword) {
|
||||
$builder->where('n.notify_no', 'like', '%' . $keyword . '%')
|
||||
->orWhere('n.biz_no', 'like', '%' . $keyword . '%')
|
||||
->orWhere('n.pay_no', 'like', '%' . $keyword . '%')
|
||||
->orWhere('n.channel_request_no', 'like', '%' . $keyword . '%')
|
||||
->orWhere('n.channel_trade_no', 'like', '%' . $keyword . '%')
|
||||
->orWhere('n.last_error', 'like', '%' . $keyword . '%')
|
||||
->orWhere('p.merchant_order_no', 'like', '%' . $keyword . '%')
|
||||
->orWhere('p.subject', 'like', '%' . $keyword . '%')
|
||||
->orWhere('m.merchant_no', 'like', '%' . $keyword . '%')
|
||||
->orWhere('m.merchant_name', 'like', '%' . $keyword . '%')
|
||||
->orWhere('m.merchant_short_name', 'like', '%' . $keyword . '%')
|
||||
->orWhere('g.group_name', 'like', '%' . $keyword . '%')
|
||||
->orWhere('c.name', 'like', '%' . $keyword . '%')
|
||||
->orWhere('c.plugin_code', 'like', '%' . $keyword . '%');
|
||||
});
|
||||
}
|
||||
|
||||
$merchantId = (string) ($filters['merchant_id'] ?? '');
|
||||
if ($merchantId !== '') {
|
||||
$query->where('p.merchant_id', (int) $merchantId);
|
||||
}
|
||||
|
||||
$channelId = (string) ($filters['channel_id'] ?? '');
|
||||
if ($channelId !== '') {
|
||||
$query->where('n.channel_id', (int) $channelId);
|
||||
}
|
||||
|
||||
$notifyType = (string) ($filters['notify_type'] ?? '');
|
||||
if ($notifyType !== '') {
|
||||
$query->where('n.notify_type', (int) $notifyType);
|
||||
}
|
||||
|
||||
$verifyStatus = (string) ($filters['verify_status'] ?? '');
|
||||
if ($verifyStatus !== '') {
|
||||
$query->where('n.verify_status', (int) $verifyStatus);
|
||||
}
|
||||
|
||||
$processStatus = (string) ($filters['process_status'] ?? '');
|
||||
if ($processStatus !== '') {
|
||||
$query->where('n.process_status', (int) $processStatus);
|
||||
}
|
||||
|
||||
$paginator = $query
|
||||
->orderByDesc('n.id')
|
||||
->paginate(max(1, $pageSize), ['*'], 'page', max(1, $page));
|
||||
|
||||
$paginator->getCollection()->transform(function ($row) {
|
||||
return $this->decorateRow($row);
|
||||
});
|
||||
|
||||
return $paginator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 ID 查询详情。
|
||||
*/
|
||||
public function findById(int $id): ?ChannelNotifyLog
|
||||
{
|
||||
$row = $this->baseQuery()
|
||||
->where('n.id', $id)
|
||||
->first();
|
||||
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化单条记录。
|
||||
*/
|
||||
private function decorateRow(object $row): object
|
||||
{
|
||||
$row->notify_type_text = (string) (NotifyConstant::notifyTypeMap()[(int) $row->notify_type] ?? '未知');
|
||||
$row->verify_status_text = (string) (NotifyConstant::verifyStatusMap()[(int) $row->verify_status] ?? '未知');
|
||||
$row->process_status_text = (string) (NotifyConstant::processStatusMap()[(int) $row->process_status] ?? '未知');
|
||||
$row->next_retry_at_text = $this->formatDateTime($row->next_retry_at ?? null);
|
||||
$row->created_at_text = $this->formatDateTime($row->created_at ?? null);
|
||||
$row->updated_at_text = $this->formatDateTime($row->updated_at ?? null);
|
||||
$row->raw_payload_text = $this->formatJson($row->raw_payload ?? null);
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建基础查询。
|
||||
*/
|
||||
private function baseQuery()
|
||||
{
|
||||
return $this->channelNotifyLogRepository->query()
|
||||
->from('ma_channel_notify_log as n')
|
||||
->leftJoin('ma_pay_order as p', 'p.pay_no', '=', 'n.pay_no')
|
||||
->leftJoin('ma_merchant as m', 'm.id', '=', 'p.merchant_id')
|
||||
->leftJoin('ma_merchant_group as g', 'g.id', '=', 'm.group_id')
|
||||
->leftJoin('ma_payment_channel as c', 'c.id', '=', 'n.channel_id')
|
||||
->select([
|
||||
'n.id',
|
||||
'n.notify_no',
|
||||
'n.channel_id',
|
||||
'n.notify_type',
|
||||
'n.biz_no',
|
||||
'n.pay_no',
|
||||
'n.channel_request_no',
|
||||
'n.channel_trade_no',
|
||||
'n.raw_payload',
|
||||
'n.verify_status',
|
||||
'n.process_status',
|
||||
'n.retry_count',
|
||||
'n.next_retry_at',
|
||||
'n.last_error',
|
||||
'n.created_at',
|
||||
'n.updated_at',
|
||||
'p.merchant_id',
|
||||
'p.merchant_order_no',
|
||||
'p.subject',
|
||||
])
|
||||
->selectRaw("COALESCE(m.merchant_no, '') AS merchant_no")
|
||||
->selectRaw("COALESCE(m.merchant_name, '') AS merchant_name")
|
||||
->selectRaw("COALESCE(m.merchant_short_name, '') AS merchant_short_name")
|
||||
->selectRaw("COALESCE(g.group_name, '') AS merchant_group_name")
|
||||
->selectRaw("COALESCE(c.name, '') AS channel_name")
|
||||
->selectRaw("COALESCE(c.plugin_code, '') AS channel_plugin_code");
|
||||
}
|
||||
|
||||
}
|
||||
141
app/service/ops/log/PayCallbackLogService.php
Normal file
141
app/service/ops/log/PayCallbackLogService.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace app\service\ops\log;
|
||||
|
||||
use app\common\base\BaseService;
|
||||
use app\common\constant\NotifyConstant;
|
||||
use app\model\admin\PayCallbackLog;
|
||||
use app\repository\ops\log\PayCallbackLogRepository;
|
||||
|
||||
/**
|
||||
* 支付回调日志查询服务。
|
||||
*/
|
||||
class PayCallbackLogService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入支付回调日志仓库。
|
||||
*/
|
||||
public function __construct(
|
||||
protected PayCallbackLogRepository $payCallbackLogRepository
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询支付回调日志。
|
||||
*/
|
||||
public function paginate(array $filters = [], int $page = 1, int $pageSize = 10)
|
||||
{
|
||||
$query = $this->baseQuery();
|
||||
|
||||
$keyword = trim((string) ($filters['keyword'] ?? ''));
|
||||
if ($keyword !== '') {
|
||||
$query->where(function ($builder) use ($keyword) {
|
||||
$builder->where('l.pay_no', 'like', '%' . $keyword . '%')
|
||||
->orWhere('p.merchant_order_no', 'like', '%' . $keyword . '%')
|
||||
->orWhere('p.subject', 'like', '%' . $keyword . '%')
|
||||
->orWhere('m.merchant_no', 'like', '%' . $keyword . '%')
|
||||
->orWhere('m.merchant_name', 'like', '%' . $keyword . '%')
|
||||
->orWhere('m.merchant_short_name', 'like', '%' . $keyword . '%')
|
||||
->orWhere('g.group_name', 'like', '%' . $keyword . '%')
|
||||
->orWhere('c.name', 'like', '%' . $keyword . '%')
|
||||
->orWhere('c.plugin_code', 'like', '%' . $keyword . '%');
|
||||
});
|
||||
}
|
||||
|
||||
$merchantId = (string) ($filters['merchant_id'] ?? '');
|
||||
if ($merchantId !== '') {
|
||||
$query->where('p.merchant_id', (int) $merchantId);
|
||||
}
|
||||
|
||||
$channelId = (string) ($filters['channel_id'] ?? '');
|
||||
if ($channelId !== '') {
|
||||
$query->where('l.channel_id', (int) $channelId);
|
||||
}
|
||||
|
||||
$callbackType = (string) ($filters['callback_type'] ?? '');
|
||||
if ($callbackType !== '') {
|
||||
$query->where('l.callback_type', (int) $callbackType);
|
||||
}
|
||||
|
||||
$verifyStatus = (string) ($filters['verify_status'] ?? '');
|
||||
if ($verifyStatus !== '') {
|
||||
$query->where('l.verify_status', (int) $verifyStatus);
|
||||
}
|
||||
|
||||
$processStatus = (string) ($filters['process_status'] ?? '');
|
||||
if ($processStatus !== '') {
|
||||
$query->where('l.process_status', (int) $processStatus);
|
||||
}
|
||||
|
||||
$paginator = $query
|
||||
->orderByDesc('l.id')
|
||||
->paginate(max(1, $pageSize), ['*'], 'page', max(1, $page));
|
||||
|
||||
$paginator->getCollection()->transform(function ($row) {
|
||||
return $this->decorateRow($row);
|
||||
});
|
||||
|
||||
return $paginator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 ID 查询详情。
|
||||
*/
|
||||
public function findById(int $id): ?PayCallbackLog
|
||||
{
|
||||
$row = $this->baseQuery()
|
||||
->where('l.id', $id)
|
||||
->first();
|
||||
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化单条记录。
|
||||
*/
|
||||
private function decorateRow(object $row): object
|
||||
{
|
||||
$row->callback_type_text = (string) (NotifyConstant::callbackTypeMap()[(int) $row->callback_type] ?? '未知');
|
||||
$row->verify_status_text = (string) (NotifyConstant::verifyStatusMap()[(int) $row->verify_status] ?? '未知');
|
||||
$row->process_status_text = (string) (NotifyConstant::processStatusMap()[(int) $row->process_status] ?? '未知');
|
||||
$row->created_at_text = $this->formatDateTime($row->created_at ?? null);
|
||||
$row->request_data_text = $this->formatJson($row->request_data ?? null);
|
||||
$row->process_result_text = $this->formatJson($row->process_result ?? null);
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建基础查询。
|
||||
*/
|
||||
private function baseQuery()
|
||||
{
|
||||
return $this->payCallbackLogRepository->query()
|
||||
->from('ma_pay_callback_log as l')
|
||||
->leftJoin('ma_pay_order as p', 'p.pay_no', '=', 'l.pay_no')
|
||||
->leftJoin('ma_merchant as m', 'm.id', '=', 'p.merchant_id')
|
||||
->leftJoin('ma_merchant_group as g', 'g.id', '=', 'm.group_id')
|
||||
->leftJoin('ma_payment_channel as c', 'c.id', '=', 'l.channel_id')
|
||||
->select([
|
||||
'l.id',
|
||||
'l.pay_no',
|
||||
'l.channel_id',
|
||||
'l.callback_type',
|
||||
'l.request_data',
|
||||
'l.verify_status',
|
||||
'l.process_status',
|
||||
'l.process_result',
|
||||
'l.created_at',
|
||||
'p.merchant_id',
|
||||
'p.merchant_order_no',
|
||||
'p.subject',
|
||||
])
|
||||
->selectRaw("COALESCE(m.merchant_no, '') AS merchant_no")
|
||||
->selectRaw("COALESCE(m.merchant_name, '') AS merchant_name")
|
||||
->selectRaw("COALESCE(m.merchant_short_name, '') AS merchant_short_name")
|
||||
->selectRaw("COALESCE(g.group_name, '') AS merchant_group_name")
|
||||
->selectRaw("COALESCE(c.name, '') AS channel_name")
|
||||
->selectRaw("COALESCE(c.plugin_code, '') AS channel_plugin_code");
|
||||
}
|
||||
|
||||
}
|
||||
132
app/service/ops/stat/ChannelDailyStatService.php
Normal file
132
app/service/ops/stat/ChannelDailyStatService.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace app\service\ops\stat;
|
||||
|
||||
use app\common\base\BaseService;
|
||||
use app\model\admin\ChannelDailyStat;
|
||||
use app\repository\ops\stat\ChannelDailyStatRepository;
|
||||
|
||||
/**
|
||||
* 通道日统计查询服务。
|
||||
*/
|
||||
class ChannelDailyStatService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入通道日统计仓库。
|
||||
*/
|
||||
public function __construct(
|
||||
protected ChannelDailyStatRepository $channelDailyStatRepository
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询通道日统计。
|
||||
*/
|
||||
public function paginate(array $filters = [], int $page = 1, int $pageSize = 10)
|
||||
{
|
||||
$query = $this->baseQuery();
|
||||
|
||||
$keyword = trim((string) ($filters['keyword'] ?? ''));
|
||||
if ($keyword !== '') {
|
||||
$query->where(function ($builder) use ($keyword) {
|
||||
$builder->where('s.stat_date', 'like', '%' . $keyword . '%')
|
||||
->orWhere('m.merchant_no', 'like', '%' . $keyword . '%')
|
||||
->orWhere('m.merchant_name', 'like', '%' . $keyword . '%')
|
||||
->orWhere('m.merchant_short_name', 'like', '%' . $keyword . '%')
|
||||
->orWhere('g.group_name', 'like', '%' . $keyword . '%')
|
||||
->orWhere('c.name', 'like', '%' . $keyword . '%')
|
||||
->orWhere('c.plugin_code', 'like', '%' . $keyword . '%');
|
||||
});
|
||||
}
|
||||
|
||||
$merchantId = (string) ($filters['merchant_id'] ?? '');
|
||||
if ($merchantId !== '') {
|
||||
$query->where('s.merchant_id', (int) $merchantId);
|
||||
}
|
||||
|
||||
$channelId = (string) ($filters['channel_id'] ?? '');
|
||||
if ($channelId !== '') {
|
||||
$query->where('s.channel_id', (int) $channelId);
|
||||
}
|
||||
|
||||
$statDate = trim((string) ($filters['stat_date'] ?? ''));
|
||||
if ($statDate !== '') {
|
||||
$query->where('s.stat_date', $statDate);
|
||||
}
|
||||
|
||||
$paginator = $query
|
||||
->orderByDesc('s.stat_date')
|
||||
->orderByDesc('s.id')
|
||||
->paginate(max(1, $pageSize), ['*'], 'page', max(1, $page));
|
||||
|
||||
$paginator->getCollection()->transform(function ($row) {
|
||||
return $this->decorateRow($row);
|
||||
});
|
||||
|
||||
return $paginator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 ID 查询详情。
|
||||
*/
|
||||
public function findById(int $id): ?ChannelDailyStat
|
||||
{
|
||||
$row = $this->baseQuery()
|
||||
->where('s.id', $id)
|
||||
->first();
|
||||
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化单条统计记录。
|
||||
*/
|
||||
private function decorateRow(object $row): object
|
||||
{
|
||||
$row->pay_amount_text = $this->formatAmount((int) $row->pay_amount);
|
||||
$row->refund_amount_text = $this->formatAmount((int) $row->refund_amount);
|
||||
$row->success_rate_text = $this->formatRate((int) $row->success_rate_bp);
|
||||
$row->avg_latency_ms_text = $this->formatLatency((int) $row->avg_latency_ms);
|
||||
$row->stat_date_text = $this->formatDate($row->stat_date ?? null);
|
||||
$row->created_at_text = $this->formatDateTime($row->created_at ?? null);
|
||||
$row->updated_at_text = $this->formatDateTime($row->updated_at ?? null);
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建基础查询。
|
||||
*/
|
||||
private function baseQuery()
|
||||
{
|
||||
return $this->channelDailyStatRepository->query()
|
||||
->from('ma_channel_daily_stat as s')
|
||||
->leftJoin('ma_merchant as m', 's.merchant_id', '=', 'm.id')
|
||||
->leftJoin('ma_merchant_group as g', 's.merchant_group_id', '=', 'g.id')
|
||||
->leftJoin('ma_payment_channel as c', 's.channel_id', '=', 'c.id')
|
||||
->select([
|
||||
's.id',
|
||||
's.merchant_id',
|
||||
's.merchant_group_id',
|
||||
's.channel_id',
|
||||
's.stat_date',
|
||||
's.pay_success_count',
|
||||
's.pay_fail_count',
|
||||
's.pay_amount',
|
||||
's.refund_count',
|
||||
's.refund_amount',
|
||||
's.avg_latency_ms',
|
||||
's.success_rate_bp',
|
||||
's.health_score',
|
||||
's.created_at',
|
||||
's.updated_at',
|
||||
])
|
||||
->selectRaw("COALESCE(m.merchant_no, '') AS merchant_no")
|
||||
->selectRaw("COALESCE(m.merchant_name, '') AS merchant_name")
|
||||
->selectRaw("COALESCE(m.merchant_short_name, '') AS merchant_short_name")
|
||||
->selectRaw("COALESCE(g.group_name, '') AS merchant_group_name")
|
||||
->selectRaw("COALESCE(c.name, '') AS channel_name")
|
||||
->selectRaw("COALESCE(c.plugin_code, '') AS channel_plugin_code");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user