Pricing - Bill per workspace ($12/mo or $120/yr each); Stripe quantity tracks the workspace count and syncs on workspace create/delete. - 2,500 AI credits per workspace, pooled at the account level; monthly reset on the billing anniversary, annual granted upfront (no rollover). - One social account per network per workspace; remove all count-based limits (workspace/social/member) and the legacy plan tiers (single Workspace plan). Onboarding (cloud only: SELF_HOSTED=false + PostHog) - Replace the /subscribe plan picker with /onboarding persona selection (Creator/Freelancer/Startup/Agency/Small business/Other), saved on the user (users.persona) and mirrored to PostHog, then Stripe Checkout on the monthly price. 8-day trial so Stripe displays 7. Billing screen - Remove the Change Plan dialog (dead with a single plan); add an annual-upgrade banner for monthly subscribers (swapToYearly). - Current-plan card shows the workspace count instead of the plan name. System AI - Brand analyzer / workspace autofill is always allowed and never debits credits (system feature, not the user's usage). Self-hosted (SELF_HOSTED=true) bypasses all billing, credit, limit, network, and onboarding logic.
61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\Ai\UsageType;
|
|
use Carbon\CarbonInterface;
|
|
use Database\Factories\AiUsageLogFactory;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class AiUsageLog extends Model
|
|
{
|
|
/** @use HasFactory<AiUsageLogFactory> */
|
|
use HasFactory, HasUuids;
|
|
|
|
protected $table = 'workspace_ai_usages';
|
|
|
|
protected $fillable = [
|
|
'account_id',
|
|
'workspace_id',
|
|
'user_id',
|
|
'post_id',
|
|
'type',
|
|
'provider',
|
|
'model',
|
|
'prompt_tokens',
|
|
'completion_tokens',
|
|
'total_tokens',
|
|
'credits',
|
|
'metadata',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'type' => UsageType::class,
|
|
'prompt_tokens' => 'integer',
|
|
'completion_tokens' => 'integer',
|
|
'total_tokens' => 'integer',
|
|
'credits' => 'integer',
|
|
'metadata' => 'array',
|
|
];
|
|
}
|
|
|
|
public function account(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Account::class);
|
|
}
|
|
|
|
public static function creditsUsedBetween(string $accountId, CarbonInterface $start, CarbonInterface $end): int
|
|
{
|
|
return (int) static::where('account_id', $accountId)
|
|
->where('created_at', '>=', $start)
|
|
->where('created_at', '<', $end)
|
|
->sum('credits');
|
|
}
|
|
}
|