add mobile api services: virtual-key-page and ticket-page
This commit is contained in:
@@ -1,20 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace mobileapi\manager;
|
||||
|
||||
use common\models\Card;
|
||||
use common\models\CardKeyAssignment;
|
||||
use common\models\Key;
|
||||
use common\models\Ticket;
|
||||
use Endroid\QrCode\QrCode;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
class ApiManager
|
||||
{
|
||||
public function getCardPage(){
|
||||
public function getCardPage()
|
||||
{
|
||||
$customer = \Yii::$app->user->getIdentity();
|
||||
|
||||
if ( $customer == null ){
|
||||
if (!isset($customer)) {
|
||||
throw new \yii\web\NotFoundHttpException();
|
||||
}
|
||||
$card = Card::findOne($customer->id_customer_card);
|
||||
|
||||
if ( $card == null ){
|
||||
if (!isset($card)) {
|
||||
throw new \yii\web\NotFoundHttpException();
|
||||
}
|
||||
|
||||
@@ -27,4 +33,82 @@ class ApiManager
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
function getTicketPage()
|
||||
{
|
||||
$customer = \Yii::$app->user->getIdentity();
|
||||
|
||||
if (!isset($customer)) {
|
||||
throw new \yii\web\NotFoundHttpException();
|
||||
}
|
||||
$card = Card::findOne($customer->id_customer_card);
|
||||
|
||||
if (!isset($card)) {
|
||||
throw new \yii\web\NotFoundHttpException();
|
||||
}
|
||||
$tickets = Ticket::readActive($card);
|
||||
|
||||
$result = [];
|
||||
foreach ($tickets as $ticket) {
|
||||
$result[] = [
|
||||
'id_ticket' => $ticket->id_ticket,
|
||||
'type' => [
|
||||
'id_type' => $ticket->ticketType->id_ticket_type,
|
||||
'name' => $ticket->ticketType->name,
|
||||
],
|
||||
'usage_count' => $ticket->usage_count,
|
||||
'start' => $ticket->start,
|
||||
'end' => $ticket->end
|
||||
];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getVirtualKeyPage()
|
||||
{
|
||||
$customer = \Yii::$app->user->getIdentity();
|
||||
|
||||
if (!isset($customer)) {
|
||||
throw new \yii\web\NotFoundHttpException();
|
||||
}
|
||||
$card = Card::findOne($customer->id_customer_card);
|
||||
|
||||
if (!isset($card)) {
|
||||
throw new \yii\web\NotFoundHttpException();
|
||||
}
|
||||
|
||||
$keyObject = null;
|
||||
try {
|
||||
$keyAssignment = CardKeyAssignment::findOne(['id_card' => $card->id_card]);
|
||||
|
||||
if (!isset($keyAssignment)) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
$key = Key::findOne(['id_key' => $keyAssignment->id_key]);
|
||||
|
||||
if (!isset($key)) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
$qrCode = new QrCode($keyAssignment->virtual_key );
|
||||
|
||||
$keyObject = [
|
||||
'qrcode' => $qrCode->writeDataUri(),
|
||||
'created_at' => $card->created_at,
|
||||
'key' => $key->number,
|
||||
'id_key' => $key->id_key
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
// failed to get key
|
||||
\Yii::error('Failed to get virtual key: '.$e->getMessage());
|
||||
}
|
||||
|
||||
return [
|
||||
'key' => $keyObject
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user