71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* Created by IntelliJ IDEA.
|
|
* User: rocho
|
|
* Date: 2018.08.29.
|
|
* Time: 21:58
|
|
*/
|
|
|
|
namespace rest\controllers;
|
|
|
|
|
|
use common\components\Helper;
|
|
use common\models\Card;
|
|
use common\models\Customer;
|
|
use common\models\Fingerprint;
|
|
use common\models\Ticket;
|
|
use yii\web\BadRequestHttpException;
|
|
use yii\web\HttpException;
|
|
use yii\web\NotFoundHttpException;
|
|
|
|
class FingerprintController extends RestController
|
|
{
|
|
|
|
public function actionAdd($idCustomer,$fingerPrint)
|
|
{
|
|
$customer = Customer::findOne($idCustomer);
|
|
|
|
if ( null === $customer) {
|
|
throw new HttpException(404, 'Not Found');
|
|
}
|
|
|
|
// Fingerprint::deleteAll(['id_customer' =>$idCustomer]);
|
|
|
|
$fingerPrintModel = new Fingerprint();
|
|
$fingerPrintModel->id_customer = $customer->id_customer;
|
|
$fingerPrintModel->fingerprint = $fingerPrint;
|
|
$fingerPrintModel->save(false);
|
|
}
|
|
|
|
/**
|
|
* @param string the sha string of the fingerprint $fingerPrint
|
|
* @return array the response
|
|
* @throws HttpException on any error
|
|
*/
|
|
public function actionEnter($fingerPrint)
|
|
{
|
|
|
|
|
|
/** @var Fingerprint $fingerPrint */
|
|
$fingerPrint = Fingerprint::find()->andWhere(['fingerPrint' => $fingerPrint])->one();
|
|
|
|
if ( null === $fingerPrint) {
|
|
throw new HttpException(404, 'Not Found');
|
|
}
|
|
|
|
$customer = Customer::findOne($fingerPrint->id_customer);
|
|
|
|
|
|
if ( null === $customer) {
|
|
throw new HttpException(404, 'Not Found');
|
|
}
|
|
|
|
return
|
|
[
|
|
'id_customer' => $customer->id_customer
|
|
];
|
|
|
|
}
|
|
|
|
}
|