Files
laralog/app/Blog/Services/MarketplaceClient.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

56 lines
1.3 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\Blog\Services;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\File;
class MarketplaceClient
{
/**
* 拉取市场包列表。
*
* @return array<int, array<string, mixed>>
*/
public function items(): array
{
$url = config('market.url');
if (! $url) {
return [];
}
$response = Http::timeout(config('market.timeout', 15))
->withToken(config('market.token', ''))
->get(rtrim($url, '/').'/items');
$response->throw();
$items = $response->json('items', []);
// 规范化市场契约:price 分、typeplugin/theme)、name
return array_map(function (array $item) {
$item['price'] = (int) ($item['price'] ?? 0);
$item['type'] = $item['type'] ?? 'plugin';
$item['name'] = $item['name'] ?? null;
return $item;
}, is_array($items) ? $items : []);
}
public function download(string $url): string
{
$response = Http::timeout(60)->get($url);
$response->throw();
$tmp = storage_path('app/tmp/market-'.basename(parse_url($url, PHP_URL_PATH)));
File::ensureDirectoryExists(dirname($tmp));
File::put($tmp, $response->body());
return $tmp;
}
}