Files
laralog/app/Providers/AppServiceProvider.php
T
ak e06e7c4300 feat: 商城付费购买流 + 市场契约
- MarketPackage 模型/迁移:市场商品作为可购买实体(payable),复用 Payment 订单
- MarketPurchaseService:购买创建订单、已购判断、免费/付费门槛校验
- payment.paid 监听(核心注册,仅支付插件启用时)标记商品已购
- 市场契约:条目含 name/type/price(分)/download_url;插件市场 Tab 只显示 plugin、主题市场 Tab 只显示 theme;付费商品显示「购买」按钮与「已购买」徽章,未购买无法安装
- 新增主题市场 Tab(原仅插件页有市场)
- 测试:购买/沙箱支付标记已购/重复购买/安装门槛/免费条目/支付插件禁用
2026-08-12 01:34:04 +08:00

74 lines
2.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace App\Providers;
use Filament\Facades\Filament;
use Filament\View\PanelsRenderHook;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
private function registerMarketPurchaseListener(): void
{
$manager = app(\App\Blog\Support\PluginManager::class);
if (! $manager->isEnabled('neatstudio.payment')) {
return;
}
$manager->addAction('payment.paid', function (\Plugins\Neatstudio\Payment\Models\Payment $payment) {
$payable = $payment->payable;
if ($payable instanceof \App\Models\MarketPackage) {
$payable->markPaid($payment);
}
}, 10);
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
// 自动加载所有插件的迁移(插件目录下 database/migrations
foreach (glob(base_path('plugins/*/database/migrations')) ?: [] as $path) {
$this->loadMigrationsFrom($path);
}
// 商城付费:支付成功标记市场商品已购(仅当支付插件启用时注册)
$this->registerMarketPurchaseListener();
// 前台页面缓存(匿名 GET,缓存含 SEO 注入后的最终 HTML)
app('router')->pushMiddlewareToGroup('web', \App\Blog\Support\PageCacheMiddleware::class);
// 后台侧边栏紧凑化(更窄的菜单项)
Filament::serving(function () {
Filament::registerRenderHook(
PanelsRenderHook::STYLES_AFTER,
fn () => Blade::render(<<<'HTML'
<style>
.fi-sidebar { padding-inline: 0.75rem; }
.fi-sidebar-nav { padding-inline: 0; }
.fi-sidebar-nav-groups { margin-inline: 0; }
.fi-sidebar-nav .fi-sidebar-item-button { padding-inline: 0.6rem; border-radius: 0.5rem; }
.fi-sidebar-nav .fi-sidebar-item-label { font-size: 0.82rem; }
.fi-sidebar-nav .fi-sidebar-group-label { font-size: 0.68rem; letter-spacing: 0.04em; }
.fi-sidebar-brand { padding-block: 0.9rem; }
</style>
HTML)
);
});
}
}