refactor(admin): success flash payload提炼AdminFlash::success并复用
This commit is contained in:
@@ -1656,10 +1656,20 @@ class PlatformOrderController extends Controller
|
|||||||
(string) $runId,
|
(string) $runId,
|
||||||
);
|
);
|
||||||
|
|
||||||
return redirect()->back()
|
$flash = \App\Support\AdminFlash::success(
|
||||||
->with('success', '批量同步订阅任务已提交到队列:命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条(limit=' . $limit . ',run_id=' . $runId . ')。')
|
'批量同步订阅任务已提交到队列:命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条(limit=' . $limit . ',run_id=' . $runId . ')。',
|
||||||
->with('success_link_href', '/admin/platform-batches/show?type=bas&run_id=' . urlencode((string) $runId))
|
'/admin/platform-batches/show?type=bas&run_id=' . urlencode((string) $runId),
|
||||||
->with('success_link_label', '进入批次复盘');
|
'进入批次复盘',
|
||||||
|
);
|
||||||
|
|
||||||
|
$res = redirect()->back()->with('success', (string) ($flash['success'] ?? ''));
|
||||||
|
foreach (['success_link_href', 'success_link_label'] as $k) {
|
||||||
|
if (isset($flash[$k]) && (string) $flash[$k] !== '') {
|
||||||
|
$res = $res->with($k, (string) $flash[$k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function batchMarkPaidAndActivate(Request $request, SubscriptionActivationService $service): RedirectResponse
|
public function batchMarkPaidAndActivate(Request $request, SubscriptionActivationService $service): RedirectResponse
|
||||||
@@ -1809,10 +1819,20 @@ class PlatformOrderController extends Controller
|
|||||||
(string) $runId,
|
(string) $runId,
|
||||||
);
|
);
|
||||||
|
|
||||||
return redirect()->back()
|
$flash = \App\Support\AdminFlash::success(
|
||||||
->with('success', '批量 BMPA 任务已提交到队列:命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条(limit=' . $limit . ',run_id=' . $runId . ')。')
|
'批量 BMPA 任务已提交到队列:命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条(limit=' . $limit . ',run_id=' . $runId . ')。',
|
||||||
->with('success_link_href', '/admin/platform-batches/show?type=bmpa&run_id=' . urlencode((string) $runId))
|
'/admin/platform-batches/show?type=bmpa&run_id=' . urlencode((string) $runId),
|
||||||
->with('success_link_label', '进入批次复盘');
|
'进入批次复盘',
|
||||||
|
);
|
||||||
|
|
||||||
|
$res = redirect()->back()->with('success', (string) ($flash['success'] ?? ''));
|
||||||
|
foreach (['success_link_href', 'success_link_label'] as $k) {
|
||||||
|
if (isset($flash[$k]) && (string) $flash[$k] !== '') {
|
||||||
|
$res = $res->with($k, (string) $flash[$k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function batchMarkActivated(Request $request): RedirectResponse
|
public function batchMarkActivated(Request $request): RedirectResponse
|
||||||
@@ -2003,11 +2023,21 @@ class PlatformOrderController extends Controller
|
|||||||
$msg .= ';失败原因Top:' . $topText;
|
$msg .= ';失败原因Top:' . $topText;
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->back()
|
$flash = \App\Support\AdminFlash::success(
|
||||||
->with('success', $msg)
|
$msg,
|
||||||
// 批量“仅标记为已生效”无 run_id(同步执行),这里提供一个“查看本次批量结果”的快捷入口:最近24小时批量生效集合。
|
// 批量“仅标记为已生效”无 run_id(同步执行),这里提供一个“查看本次批量结果”的快捷入口:最近24小时批量生效集合。
|
||||||
->with('success_link_href', '/admin/platform-orders?batch_mark_activated_24h=1#filters')
|
'/admin/platform-orders?batch_mark_activated_24h=1#filters',
|
||||||
->with('success_link_label', '查看本次批量结果');
|
'查看本次批量结果',
|
||||||
|
);
|
||||||
|
|
||||||
|
$res = redirect()->back()->with('success', (string) ($flash['success'] ?? ''));
|
||||||
|
foreach (['success_link_href', 'success_link_label'] as $k) {
|
||||||
|
if (isset($flash[$k]) && (string) $flash[$k] !== '') {
|
||||||
|
$res = $res->with($k, (string) $flash[$k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clearSyncError(Request $request, PlatformOrder $order): RedirectResponse
|
public function clearSyncError(Request $request, PlatformOrder $order): RedirectResponse
|
||||||
|
|||||||
27
app/Support/AdminFlash.php
Normal file
27
app/Support/AdminFlash.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Support;
|
||||||
|
|
||||||
|
class AdminFlash
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array{success:string, success_link_href?:string, success_link_label?:string}
|
||||||
|
*/
|
||||||
|
public static function success(string $message, string $linkHref = '', string $linkLabel = '查看'): array
|
||||||
|
{
|
||||||
|
$message = (string) $message;
|
||||||
|
$linkHref = trim((string) $linkHref);
|
||||||
|
$linkLabel = trim((string) $linkLabel);
|
||||||
|
|
||||||
|
$payload = [
|
||||||
|
'success' => $message,
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($linkHref !== '') {
|
||||||
|
$payload['success_link_href'] = $linkHref;
|
||||||
|
$payload['success_link_label'] = $linkLabel !== '' ? $linkLabel : '查看';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
26
tests/Unit/AdminFlashSuccessPayloadTest.php
Normal file
26
tests/Unit/AdminFlashSuccessPayloadTest.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use App\Support\AdminFlash;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class AdminFlashSuccessPayloadTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_success_should_return_message_only_when_no_link(): void
|
||||||
|
{
|
||||||
|
$p = AdminFlash::success('ok');
|
||||||
|
|
||||||
|
$this->assertSame('ok', (string) ($p['success'] ?? ''));
|
||||||
|
$this->assertArrayNotHasKey('success_link_href', $p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_success_should_include_link_when_href_present(): void
|
||||||
|
{
|
||||||
|
$p = AdminFlash::success('ok', '/admin/x', '查看');
|
||||||
|
|
||||||
|
$this->assertSame('ok', (string) ($p['success'] ?? ''));
|
||||||
|
$this->assertSame('/admin/x', (string) ($p['success_link_href'] ?? ''));
|
||||||
|
$this->assertSame('查看', (string) ($p['success_link_label'] ?? ''));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user