chore(admin-platform-order): failed reason keyword max len uses config

This commit is contained in:
萝卜
2026-03-16 17:47:47 +08:00
parent d6d8748ce6
commit ef46111efb
2 changed files with 82 additions and 2 deletions

View File

@@ -744,7 +744,8 @@
$syncFailedListUrl = $makePlatformOrderIndexUrl(['sync_status' => 'failed']); $syncFailedListUrl = $makePlatformOrderIndexUrl(['sync_status' => 'failed']);
// 避免 URL 过长/特殊字符破坏 query失败原因过长时不生成 keyword 链接 // 避免 URL 过长/特殊字符破坏 query失败原因过长时不生成 keyword 链接
$SYNC_REASON_KEYWORD_MAX_LEN = 80; // 与列表页/仪表盘保持一致:由 config 统一控制阈值。
$SYNC_REASON_KEYWORD_MAX_LEN = (int) config('saasshop.platform_orders.sync_error_keyword_link_max_len', 200);
$syncReasonUrl = ''; $syncReasonUrl = '';
if ($syncMsg !== '' && mb_strlen($syncMsg) <= $SYNC_REASON_KEYWORD_MAX_LEN) { if ($syncMsg !== '' && mb_strlen($syncMsg) <= $SYNC_REASON_KEYWORD_MAX_LEN) {
$syncReasonUrl = $makePlatformOrderIndexUrl([ $syncReasonUrl = $makePlatformOrderIndexUrl([
@@ -794,7 +795,8 @@
$bmpaListUrl = $makePlatformOrderIndexUrl(['bmpa_failed_only' => '1']); $bmpaListUrl = $makePlatformOrderIndexUrl(['bmpa_failed_only' => '1']);
// 避免 URL 过长/特殊字符破坏 query失败原因过长时不生成 keyword 链接 // 避免 URL 过长/特殊字符破坏 query失败原因过长时不生成 keyword 链接
$BMPA_REASON_KEYWORD_MAX_LEN = 80; // 与列表页/仪表盘保持一致:由 config 统一控制阈值。
$BMPA_REASON_KEYWORD_MAX_LEN = (int) config('saasshop.platform_orders.sync_error_keyword_link_max_len', 200);
$bmpaReasonUrl = ''; $bmpaReasonUrl = '';
if ($bmpaMsg !== '' && mb_strlen($bmpaMsg) <= $BMPA_REASON_KEYWORD_MAX_LEN) { if ($bmpaMsg !== '' && mb_strlen($bmpaMsg) <= $BMPA_REASON_KEYWORD_MAX_LEN) {
$bmpaReasonUrl = $makePlatformOrderIndexUrl([ $bmpaReasonUrl = $makePlatformOrderIndexUrl([

View File

@@ -0,0 +1,78 @@
<?php
namespace Tests\Feature;
use App\Models\Admin;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderShowFailedReasonKeywordMaxLenShouldUseConfigTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->seed();
$this->post('/admin/login', [
'email' => 'platform.admin@demo.local',
'password' => 'Platform@123456',
])->assertRedirect('/admin');
}
public function test_platform_order_show_failed_reason_keyword_max_len_should_use_config(): void
{
// 将阈值设为 5len=5 应生成同原因链接len=6 不生成
config()->set('saasshop.platform_orders.sync_error_keyword_link_max_len', 5);
$this->loginAsPlatformAdmin();
$merchantId = (int) Merchant::query()->value('id');
$platformAdminId = (int) Admin::query()->where('email', 'platform.admin@demo.local')->value('id');
$plan = Plan::query()->create([
'code' => 'show_failed_reason_max_len_plan',
'name' => '订单详情原因阈值配置测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$okMsg = '12345';
$longMsg = '123456';
$order = PlatformOrder::query()->create([
'merchant_id' => $merchantId,
'plan_id' => $plan->id,
'site_subscription_id' => null,
'created_by_admin_id' => $platformAdminId ?: null,
'order_no' => 'PO_SHOW_FAILED_REASON_MAX_LEN_0001',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'paid',
'payable_amount' => 10,
'paid_amount' => 10,
'meta' => [
'subscription_activation_error' => ['message' => $okMsg, 'at' => now()->toDateTimeString()],
'batch_mark_paid_and_activate_error' => ['message' => $longMsg, 'at' => now()->toDateTimeString()],
],
]);
$res = $this->get('/admin/platform-orders/' . $order->id);
$res->assertOk();
// 同步失败len=5 应有同原因链接
$res->assertSee('查看同原因失败订单', false);
$res->assertSee('sync_error_keyword=' . $okMsg, false);
// BMPAlen=6 不应生成 keyword 链接(应出现“原因过长”提示)
$res->assertSee('原因过长', false);
$res->assertDontSee('bmpa_error_keyword=' . $longMsg, false);
}
}