fix: 完善退款完成售后单自动对齐机制与汇付多日期幂等自愈
这个提交包含在:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* 订单与售后退款自动对齐单元测试 (TDD)
|
||||
*/
|
||||
|
||||
class OrderRefundAutoAlignTest
|
||||
{
|
||||
private $passed = 0;
|
||||
private $failed = 0;
|
||||
|
||||
public function run()
|
||||
{
|
||||
echo "=== 开始执行 订单与售后退款自动对齐单元测试 (TDD) ===\n";
|
||||
$this->testOrderOperRefundFinishAlignsAftersale();
|
||||
$this->testAftersaleRefundAutoAlignsWhenItemAlreadyRefunded();
|
||||
$this->testHuifuRefundServiceMultiDateAndSelfHealing();
|
||||
|
||||
echo "\n测试结果: {$this->passed} 通过, {$this->failed} 失败\n";
|
||||
if ($this->failed > 0) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private function assert($condition, $message)
|
||||
{
|
||||
if ($condition) {
|
||||
echo " [PASS] {$message}\n";
|
||||
$this->passed++;
|
||||
} else {
|
||||
echo " [FAIL] {$message}\n";
|
||||
$this->failed++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证 OrderOper::refundFinish 会自动联动对齐该商品项下的待处理售后单
|
||||
*/
|
||||
public function testOrderOperRefundFinishAlignsAftersale()
|
||||
{
|
||||
$filePath = __DIR__ . '/../addons/shopro/library/traits/model/order/OrderOper.php';
|
||||
$this->assert(is_file($filePath), "OrderOper.php 必须存在");
|
||||
|
||||
$content = file_get_contents($filePath);
|
||||
$startPos = strpos($content, 'function refundFinish(');
|
||||
$this->assert($startPos !== false, "OrderOper.php 必须包含 refundFinish 方法");
|
||||
|
||||
$nextFuncPos = strpos($content, 'public function ', $startPos + 20);
|
||||
$methodBody = substr($content, $startPos, $nextFuncPos - $startPos);
|
||||
|
||||
$hasAftersaleAlign = strpos($methodBody, 'OrderAftersale') !== false
|
||||
&& (strpos($methodBody, 'aftersale_status') !== false);
|
||||
$this->assert($hasAftersaleAlign, "refundFinish 必须联动更新关联的 OrderAftersale 状态以实现自动对齐");
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证 Aftersale 控制器的 refund 方法在商品已退款时自动对齐售后单状态,而不是直接抛异常卡死
|
||||
*/
|
||||
public function testAftersaleRefundAutoAlignsWhenItemAlreadyRefunded()
|
||||
{
|
||||
$filePath = __DIR__ . '/../application/admin/controller/shopro/order/Aftersale.php';
|
||||
$content = file_get_contents($filePath);
|
||||
|
||||
$startPos = strpos($content, 'function refund(');
|
||||
$nextFuncPos = strpos($content, 'public function ', $startPos + 20);
|
||||
$methodBody = substr($content, $startPos, $nextFuncPos - $startPos);
|
||||
|
||||
// 检查当 $orderItem 已经退款时,是否进行售后单自动对齐保存
|
||||
$hasAutoAlign = strpos($methodBody, 'AFTERSALE_STATUS_OK') !== false
|
||||
&& strpos($methodBody, 'REFUND_STATUS_FINISH') !== false
|
||||
&& preg_match('/OrderAftersaleLog::operAdd.+?对齐/s', $methodBody);
|
||||
|
||||
$this->assert((bool)$hasAutoAlign, "Aftersale.php 的 refund 方法在检测到商品已退款时,必须自动对齐售后单并记录对齐日志");
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证 HuifuRefundService 支持跨日期核验(当天及原交易日)和全局异常自愈对齐
|
||||
*/
|
||||
public function testHuifuRefundServiceMultiDateAndSelfHealing()
|
||||
{
|
||||
$filePath = __DIR__ . '/../addons/shopro_huifu/library/HuifuRefundService.php';
|
||||
$content = file_get_contents($filePath);
|
||||
|
||||
$hasMultiDate = strpos($content, "date('Ymd')") !== false && strpos($content, "req_date") !== false;
|
||||
$this->assert($hasMultiDate, "HuifuRefundService 幂等核验必须支持多日期(当天与原交易日)检查");
|
||||
|
||||
$hasSelfHealing = strpos($content, 'isAlreadyRefunded') !== false
|
||||
&& strpos($content, 'idempotent') !== false;
|
||||
$this->assert($hasSelfHealing, "HuifuRefundService 必须包含汇付已退款场景的自动对齐自愈机制");
|
||||
}
|
||||
}
|
||||
|
||||
$test = new OrderRefundAutoAlignTest();
|
||||
$test->run();
|
||||
在新工单中引用
屏蔽一个用户