feat: integrate dynamic geofence fetching, service area spatial boundaries, partner store profiles & editing with Leaflet maps, custom store portal icons, QR distribution charts with geographic/LGU filters, and optimize admin dashboards
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Store;
|
||||
|
||||
use App\Http\Controllers\Api\V1\ApiController;
|
||||
use App\Models\QrCode;
|
||||
use App\Models\QrPurchaseOrder;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StoreQrPurchaseController extends ApiController
|
||||
{
|
||||
public function pending(Request $request): JsonResponse
|
||||
{
|
||||
$orders = QrPurchaseOrder::with(['resident'])
|
||||
->where('store_id', $request->user()->id)
|
||||
->where('status', 'pending_payment')
|
||||
->orderBy('created_at')
|
||||
->get();
|
||||
|
||||
return $this->ok($orders);
|
||||
}
|
||||
|
||||
public function complete(Request $request, string $uuid): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'scanned_qr_data' => 'required|string',
|
||||
]);
|
||||
|
||||
$order = QrPurchaseOrder::where('uuid', $uuid)
|
||||
->where('store_id', $request->user()->id)
|
||||
->where('status', 'pending_payment')
|
||||
->firstOrFail();
|
||||
|
||||
// Find the scanned QR code
|
||||
$qrCode = QrCode::where('serial', $request->scanned_qr_data)->first();
|
||||
|
||||
if (!$qrCode) {
|
||||
return $this->fail('Invalid QR Code. Not found in the system.', null, 404);
|
||||
}
|
||||
|
||||
if (! $qrCode->status->equals(\App\States\QrCode\Allocated::class) && ! $qrCode->status->equals(\App\States\QrCode\Unassigned::class)) {
|
||||
return $this->fail('This QR Code cannot be assigned (already used or active).', null, 422);
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($order, $qrCode) {
|
||||
$order->update([
|
||||
'status' => 'completed',
|
||||
'completed_at' => now(),
|
||||
'qr_code_id' => $qrCode->id,
|
||||
]);
|
||||
|
||||
$qrCode->status->transitionTo(\App\States\QrCode\Active::class);
|
||||
$qrCode->update([
|
||||
'assigned_to_user_id' => $order->resident_id,
|
||||
'activated_at' => now(),
|
||||
]);
|
||||
});
|
||||
|
||||
return $this->ok($order->fresh(), 'QR Purchase completed and assigned successfully.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user