This commit is contained in:
2026-06-11 14:26:41 +08:00
parent 08249451a7
commit e5959fd89a
7 changed files with 121 additions and 46 deletions
+34 -14
View File
@@ -23,9 +23,9 @@ use think\facade\Log;
class OrderLogic
{
/**
* 创建方式统一三值normal 普通订单 / wechat_work 企业微信对外收款 / fubei 付呗
* 创建方式:normal 普通订单 / wechat_work 企业微信对外收款 / fubei 付呗 / express_cod 快递代收
*/
private const CREATE_TYPES = ['normal', 'wechat_work', 'fubei'];
private const CREATE_TYPES = ['normal', 'wechat_work', 'fubei', 'express_cod'];
/**
* @notes 生成订单号
@@ -64,6 +64,15 @@ class OrderLogic
return 'normal';
}
/**
* 是否为「待审核(5)且需人工确认到账」的单:付呗(payment_method=fubei) 或 快递代收(create_type=express_cod)
*/
private static function isPendingManualAudit(Order $order): bool
{
return (string)($order->payment_method ?? '') === 'fubei'
|| (string)($order->create_type ?? '') === 'express_cod';
}
/**
* @notes 创建订单
* @param array $params
@@ -73,11 +82,16 @@ class OrderLogic
{
try {
$channel = (string)($params['payment_channel'] ?? 'normal');
if (!in_array($channel, ['normal', 'fubei'], true)) {
if (!in_array($channel, ['normal', 'fubei', 'express_cod'], true)) {
$channel = 'normal';
}
$paymentMethod = $channel === 'fubei' ? 'fubei' : null;
$createType = self::normalizeCreateType((string)($params['create_type'] ?? ''), $paymentMethod);
// 快递代收:以 express_cod 标记创建方式(与 fubei 流转一致,但 payment_method 待到账时再写)
$createTypeHint = $channel === 'express_cod' ? 'express_cod' : '';
$createType = self::normalizeCreateType(
(string)($params['create_type'] ?? $createTypeHint),
$paymentMethod
);
$requirePaymentSlipAudit = (int)($params['require_payment_slip_audit'] ?? 0) === 1;
$order = new Order();
@@ -87,10 +101,13 @@ class OrderLogic
$order->order_type = $params['order_type'];
$order->amount = $params['amount'];
$order->create_type = $createType;
// 付呗且申请审核支付单:待审核(5);否则待支付(1)
// 付呗/快递代收且申请审核支付单:待审核(5);否则待支付(1)
if ($channel === 'fubei') {
$order->payment_method = 'fubei';
$order->status = $requirePaymentSlipAudit ? 5 : 1;
} elseif ($channel === 'express_cod') {
// payment_method 留空,待人工确认到账时再写真实支付方式
$order->status = $requirePaymentSlipAudit ? 5 : 1;
} else {
$order->status = 1; // 待支付
}
@@ -387,11 +404,11 @@ class OrderLogic
}
$st = (int)$order->status;
// 1=待支付;5=待审核(付呗+申请支付单审核) 时允许录入手动到账
// 1=待支付;5=待审核(付呗/快递代收+申请支付单审核) 时允许录入手动到账
if ($st === 1) {
// 正常待支付
} elseif ($st === 5 && (string)($order->payment_method ?? '') === 'fubei') {
// 待审核的付呗单,通过人工确认后标记已支付
} elseif ($st === 5 && self::isPendingManualAudit($order)) {
// 待审核的付呗/快递代收单,通过人工确认后标记已支付
} else {
self::setError('订单状态不允许支付');
return false;
@@ -424,8 +441,8 @@ class OrderLogic
}
$st = (int)$order->status;
if ($st !== 1 && !($st === 5 && (string)($order->payment_method ?? '') === 'fubei')) {
self::setError('只有待支付或待审核(付呗)的订单才能取消');
if ($st !== 1 && !($st === 5 && self::isPendingManualAudit($order))) {
self::setError('只有待支付或待审核(付呗/快递代收)的订单才能取消');
return false;
}
@@ -509,13 +526,13 @@ class OrderLogic
}
$st = (int) $order->status;
if ($st === 5 && (string) ($order->payment_method ?? '') !== 'fubei') {
self::setError('待审核订单仅支持付呗渠道拆分');
if ($st === 5 && !self::isPendingManualAudit($order)) {
self::setError('待审核订单仅支持付呗/快递代收渠道拆分');
return false;
}
if (! in_array($st, [1, 5, 2], true)) {
self::setError('仅「待支付」「待审核(付呗)」或「已支付」的订单可拆分');
self::setError('仅「待支付」「待审核(付呗/快递代收)」或「已支付」的订单可拆分');
return false;
}
@@ -586,7 +603,10 @@ class OrderLogic
(string) ($order->remark ?? '')
);
if ($st === 5) {
$n->payment_method = 'fubei';
// 付呗子单沿用 payment_method=fubei;快递代收子单 payment_method 留空,靠 create_type 标记
if ((string) ($order->payment_method ?? '') === 'fubei') {
$n->payment_method = 'fubei';
}
$n->status = 5;
} elseif ($st === 2) {
$n->status = 2;