重构初始化

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,33 @@
<?php
namespace app\exception;
use Webman\Exception\BusinessException;
/**
* 商户余额不足异常。
*/
class BalanceInsufficientException extends BusinessException
{
/**
* 构造函数,组装异常信息。
*/
public function __construct(int $merchantId = 0, int $needAmount = 0, int $availableAmount = 0, array $data = [])
{
parent::__construct('余额不足', 40011);
$payload = array_filter([
'merchant_id' => $merchantId ?: null,
'need_amount' => $needAmount ?: null,
'available_amount' => $availableAmount ?: null,
], static fn ($value) => $value !== null && $value !== '');
if (!empty($data)) {
$payload = array_merge($payload, $data);
}
if (!empty($payload)) {
$this->data($payload);
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace app\exception;
use Webman\Exception\BusinessException;
/**
* 业务状态异常。
*
* 用于状态不允许、资源已禁用、资源不可用和不支持等场景,统一业务码为 40910。
*/
class BusinessStateException extends BusinessException
{
/**
* 构造函数,组装异常信息。
*/
public function __construct(string $message = '业务状态不允许当前操作', array $data = [], int $bizCode = 40910)
{
parent::__construct($message, $bizCode);
if (!empty($data)) {
$this->data($data);
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace app\exception;
use Webman\Exception\BusinessException;
/**
* 冲突异常。
*
* 用于幂等冲突、重复请求和重复提交等场景,统一业务码为 40900。
*/
class ConflictException extends BusinessException
{
/**
* 构造函数,组装异常信息。
*/
public function __construct(string $message = '业务冲突', array $data = [], int $bizCode = 40900)
{
parent::__construct($message, $bizCode);
if (!empty($data)) {
$this->data($data);
}
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace app\exception;
use Webman\Exception\BusinessException;
/**
* 通知重试次数超限异常。
*/
class NotifyRetryExceededException extends BusinessException
{
/**
* 构造函数,组装异常信息。
*/
public function __construct(string $notifyNo = '', array $data = [])
{
parent::__construct('通知重试次数超限', 40016);
$payload = array_filter([
'notify_no' => $notifyNo,
], static fn ($value) => $value !== '' && $value !== null);
if (!empty($data)) {
$payload = array_merge($payload, $data);
}
if (!empty($payload)) {
$this->data($payload);
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace app\exception;
use Webman\Exception\BusinessException;
/**
* 支付插件异常。
*
* 用于第三方渠道下单、查单、退款、验签和插件装配失败等场景。
*/
class PaymentException extends BusinessException
{
/**
* 构造函数,统一组装业务码与附加数据。
*/
public function __construct(string $message = '支付渠道处理失败', int $bizCode = 40200, array $data = [])
{
parent::__construct($message, $bizCode);
if (!empty($data)) {
$this->data($data);
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace app\exception;
use Webman\Exception\BusinessException;
/**
* 资源不存在异常。
*
* 作为所有“找不到”类业务异常的统一基类,统一业务码为 40400。
*/
class ResourceNotFoundException extends BusinessException
{
/**
* 构造函数,组装异常信息。
*/
public function __construct(string $message = '资源不存在', array $data = [], int $bizCode = 40400)
{
parent::__construct($message, $bizCode);
if (!empty($data)) {
$this->data($data);
}
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace app\exception;
use Webman\Exception\BusinessException;
/**
* 参数校验异常。
*/
class ValidationException extends BusinessException
{
/**
* 构造函数,组装异常信息。
*/
public function __construct(string $message = '参数校验失败', int|array $bizCodeOrData = 40001, array $data = [])
{
if (is_array($bizCodeOrData)) {
$data = $bizCodeOrData;
$bizCode = 40001;
} else {
$bizCode = $bizCodeOrData;
}
parent::__construct($message, $bizCode);
if (!empty($data)) {
$this->data($data);
}
}
}