Shop, menu, and booking storefronts with OIDC SSO, Pay checkout, and merchant.ladill.com deployment workflow. Co-authored-by: Cursor <cursoragent@cursor.com>
72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Merchant;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\QrCode;
|
|
use App\Models\QrSaleOrder;
|
|
use App\Services\Billing\BillingClient;
|
|
use App\Support\Qr\QrTypeCatalog;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\View\View;
|
|
use Throwable;
|
|
|
|
class OverviewController extends Controller
|
|
{
|
|
public function __construct(private BillingClient $billing) {}
|
|
|
|
public function index(Request $request): View
|
|
{
|
|
$account = ladill_account();
|
|
|
|
$qrIds = $account->qrCodes()
|
|
->whereIn('type', QrTypeCatalog::storefrontTypes())
|
|
->pluck('id');
|
|
|
|
$todayStart = now()->startOfDay();
|
|
|
|
$todayOrders = QrSaleOrder::query()
|
|
->whereIn('qr_code_id', $qrIds)
|
|
->where('status', QrSaleOrder::STATUS_PAID)
|
|
->where('paid_at', '>=', $todayStart);
|
|
|
|
$todayCount = (clone $todayOrders)->count();
|
|
$todayRevenue = (float) (clone $todayOrders)->sum('merchant_amount_ghs');
|
|
|
|
$recentOrders = QrSaleOrder::query()
|
|
->whereIn('qr_code_id', $qrIds)
|
|
->where('status', QrSaleOrder::STATUS_PAID)
|
|
->with('qrCode')
|
|
->latest('paid_at')
|
|
->limit(8)
|
|
->get();
|
|
|
|
$storefrontCount = $qrIds->count();
|
|
$orders30d = QrSaleOrder::query()
|
|
->whereIn('qr_code_id', $qrIds)
|
|
->where('status', QrSaleOrder::STATUS_PAID)
|
|
->where('paid_at', '>=', now()->subDays(30))
|
|
->count();
|
|
|
|
$balanceMinor = 0;
|
|
try {
|
|
$balanceMinor = $this->billing->balanceMinor($account->public_id);
|
|
} catch (Throwable $e) {
|
|
Log::warning('Merchant dashboard could not load wallet balance', [
|
|
'user' => $account->public_id,
|
|
'error' => $e->getMessage(),
|
|
]);
|
|
}
|
|
|
|
return view('merchant.dashboard', [
|
|
'todayCount' => $todayCount,
|
|
'todayRevenue' => $todayRevenue,
|
|
'storefrontCount' => $storefrontCount,
|
|
'orders30d' => $orders30d,
|
|
'recentOrders' => $recentOrders,
|
|
'balanceMinor' => $balanceMinor,
|
|
]);
|
|
}
|
|
}
|