- MarketPackage 模型/迁移:市场商品作为可购买实体(payable),复用 Payment 订单 - MarketPurchaseService:购买创建订单、已购判断、免费/付费门槛校验 - payment.paid 监听(核心注册,仅支付插件启用时)标记商品已购 - 市场契约:条目含 name/type/price(分)/download_url;插件市场 Tab 只显示 plugin、主题市场 Tab 只显示 theme;付费商品显示「购买」按钮与「已购买」徽章,未购买无法安装 - 新增主题市场 Tab(原仅插件页有市场) - 测试:购买/沙箱支付标记已购/重复购买/安装门槛/免费条目/支付插件禁用
48 lines
985 B
PHP
48 lines
985 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Plugins\Neatstudio\Payment\Models\Payment;
|
|
|
|
class MarketPackage extends Model
|
|
{
|
|
protected $fillable = [
|
|
'item_key', 'item_type', 'title', 'price', 'status', 'payment_id', 'user_id',
|
|
];
|
|
|
|
public function payment(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Payment::class);
|
|
}
|
|
|
|
public function isPaid(): bool
|
|
{
|
|
return $this->status === 'paid';
|
|
}
|
|
|
|
public function markPaid(Payment $payment): void
|
|
{
|
|
$this->update([
|
|
'status' => 'paid',
|
|
'payment_id' => $payment->id,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 作为可购买实体(市场商品)的展示约定。
|
|
*/
|
|
public function payableLabel(): string
|
|
{
|
|
return '市场商品:'.$this->title;
|
|
}
|
|
|
|
public function payableUrl(): ?string
|
|
{
|
|
return null;
|
|
}
|
|
}
|