Replace Mini/QR Plus copy and system prompt with Transfer file-sharing context, suggestions, and dashboard metrics. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
namespace App\Http\Controllers\Qr;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\QrCode;
|
||||
use App\Models\Transfer;
|
||||
use App\Models\TransferDownloadEvent;
|
||||
use App\Services\Afia\AfiaService;
|
||||
use App\Services\Billing\BillingClient;
|
||||
use App\Support\Qr\QrTypeCatalog;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -45,19 +45,32 @@ class AfiaController extends Controller
|
||||
return ['signed_in' => 'no'];
|
||||
}
|
||||
|
||||
$types = QrTypeCatalog::eventTypes();
|
||||
$codes = $account->qrCodes()->whereIn('type', $types);
|
||||
$active = Transfer::query()
|
||||
->where('user_id', $account->id)
|
||||
->where('status', Transfer::STATUS_ACTIVE);
|
||||
|
||||
$storageBytes = (int) (clone $active)->sum('storage_bytes');
|
||||
$storageGb = round($storageBytes / (1024 * 1024 * 1024), 2);
|
||||
|
||||
$transferIds = Transfer::query()
|
||||
->where('user_id', $account->id)
|
||||
->pluck('id');
|
||||
|
||||
$ctx = [
|
||||
'signed_in' => 'yes',
|
||||
'qr_codes_total' => (clone $codes)->count(),
|
||||
'qr_codes_active' => (clone $codes)->where('is_active', true)->count(),
|
||||
'scans_total' => (int) (clone $codes)->sum('scans_total'),
|
||||
'top_code_type' => (clone $codes)
|
||||
->selectRaw('type, count(*) as total')
|
||||
->groupBy('type')
|
||||
->orderByDesc('total')
|
||||
->value('type') ?: 'none yet',
|
||||
'active_transfers' => (clone $active)->count(),
|
||||
'storage_gb' => $storageGb,
|
||||
'downloads_30d' => TransferDownloadEvent::query()
|
||||
->whereIn('transfer_id', $transferIds)
|
||||
->where('downloaded_at', '>=', now()->subDays(30))
|
||||
->count(),
|
||||
'expiring_within_7_days' => Transfer::query()
|
||||
->where('user_id', $account->id)
|
||||
->where('status', Transfer::STATUS_ACTIVE)
|
||||
->whereNotNull('expires_at')
|
||||
->whereBetween('expires_at', [now(), now()->addDays(7)])
|
||||
->count(),
|
||||
'storage_price_per_gb_month_ghs' => number_format((float) config('transfer.price_per_gb_month', 1.0), 2),
|
||||
];
|
||||
|
||||
if ($account->public_id) {
|
||||
@@ -67,18 +80,21 @@ class AfiaController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$recent = $account->qrCodes()
|
||||
->whereIn('type', $types)
|
||||
->latest('updated_at')
|
||||
$recent = Transfer::query()
|
||||
->where('user_id', $account->id)
|
||||
->where('status', Transfer::STATUS_ACTIVE)
|
||||
->with('qrCode:id,short_code')
|
||||
->latest()
|
||||
->limit(3)
|
||||
->get(['type', 'label', 'short_code', 'scans_total']);
|
||||
->get(['id', 'title', 'qr_code_id', 'download_count', 'expires_at']);
|
||||
|
||||
if ($recent->isNotEmpty()) {
|
||||
$ctx['recent_codes'] = $recent->map(fn (QrCode $code): string => sprintf(
|
||||
'%s (%s, %d scans)',
|
||||
$code->label ?: $code->short_code,
|
||||
QrTypeCatalog::label($code->type),
|
||||
$code->scans_total,
|
||||
$ctx['recent_transfers'] = $recent->map(fn (Transfer $transfer): string => sprintf(
|
||||
'%s (%s, %d downloads%s)',
|
||||
$transfer->title,
|
||||
$transfer->qrCode?->short_code ?? 'no QR',
|
||||
$transfer->download_count,
|
||||
$transfer->expires_at ? ', expires '.$transfer->expires_at->toDateString() : '',
|
||||
))->implode('; ');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user