feat: 前台 paywall——整篇锁定渲染付费墙,付费块替换为 teaser

- membership/post.rendered 过滤:整篇锁定(members_only)渲染 paywall 视图(封面+标题+价格+单篇解锁/开通会员按钮,游客引导登录);[paid] 块替换为带解锁按钮的 teaser;替换改用 preg_replace_callback 避免 $ 转义问题
- 视图放 resources/views/membership/(主题同名文件可覆盖),两主题补充 .paywall/.paid-teaser 样式
- 修复泄漏:excerpt_or_fallback 对 members_only 文章不再回退截取正文,防止内容泄漏到 paywall 与 SEO meta
- 测试:更新 teaser 断言,新增 guest 见 paywall、登录用户见解锁/会员按钮
This commit is contained in:
ak
2026-08-12 01:02:10 +08:00
parent 6a7daa79da
commit 8ef250ba80
7 changed files with 144 additions and 6 deletions
+42 -2
View File
@@ -87,11 +87,12 @@ class MembershipFlowTest extends TestCase
'published_at' => now(),
]);
// 游客:付费部分被替换
// 游客:付费部分被替换为 teaser
$this->get('/posts/paid-post.shtml')
->assertOk()
->assertDontSee('付费隐藏内容')
->assertSee('付费内容已隐藏');
->assertSee('本文包含付费内容')
->assertSee('登录后查看');
// 会员:可见
$this->actingAs($this->user)->post('/membership/'.$this->plan->id.'/subscribe');
@@ -184,4 +185,43 @@ class MembershipFlowTest extends TestCase
$this->assertSame(0, Payment::query()->count());
}
public function test_members_only_post_shows_paywall_to_guest(): void
{
$post = Post::create([
'title' => '会员专享文章',
'slug' => 'members-only-post',
'content' => '这是会员才能看到的正文内容',
'content_format' => 'markdown',
'status' => 'published',
'published_at' => now(),
'meta' => ['members_only' => true, 'price' => 500],
]);
$this->get('/posts/members-only-post.shtml')
->assertOk()
->assertSee('登录后解锁')
->assertSee('单篇解锁')
->assertSee('会员专享文章')
->assertDontSee('这是会员才能看到的正文内容');
}
public function test_members_only_post_paywall_shows_unlock_buttons_to_user(): void
{
$post = Post::create([
'title' => '会员专享文章2',
'slug' => 'members-only-post-2',
'content' => '正文内容不可见',
'content_format' => 'markdown',
'status' => 'published',
'published_at' => now(),
'meta' => ['members_only' => true, 'price' => 9900],
]);
$this->actingAs($this->user)->get('/posts/members-only-post-2.shtml')
->assertOk()
->assertSee('单篇解锁')
->assertSee('开通会员')
->assertDontSee('正文内容不可见');
}
}