get logs from device
This commit is contained in:
@@ -240,61 +240,13 @@ class DepartmentController extends Controller {
|
||||
}
|
||||
|
||||
public function actionTest() {
|
||||
$timezone = [
|
||||
"DeviceIP" => "192.168.1.200",
|
||||
"TimezoneId" => 1,
|
||||
"SunTime1" => 0, "SunTime2" => 0, "SunTime3" => 0,
|
||||
"MonTime1" => 0, "MonTime2" => 0, "MonTime3" => 0,
|
||||
"TueTime1" => 0, "TueTime2" => 0, "TueTime3" => 0,
|
||||
"WedTime1" => 0, "WedTime2" => 0, "WedTime3" => 0,
|
||||
"ThuTime1" => 0, "ThuTime2" => 0, "ThuTime3" => 0,
|
||||
"FriTime1" => $this->convertTime("8:30", "12:30"), "FriTime2" => $this->convertTime("13:30", "18:30"), "FriTime3" => 0,
|
||||
"SatTime1" => 0, "SatTime2" => 0, "SatTime3" => 0,
|
||||
"Hol1Time1" => 0, "Hol1Time2" => 0, "Hol1Time3" => 0,
|
||||
"Hol2Time1" => 0, "Hol2Time2" => 0, "Hol2Time3" => 0,
|
||||
"Hol3Time1" => 0, "Hol3Time2" => 0, "Hol3Time3" => 0
|
||||
];
|
||||
$timezoneRq = $this->requestToMCard("/SetDeviceData/timezone", $timezone);
|
||||
|
||||
$user = [
|
||||
"DeviceIP" => "192.168.1.200",
|
||||
"CardNo" => 16673827,
|
||||
"Pin" => 69,
|
||||
"Password" => "",
|
||||
"Group" => "",
|
||||
"StartTime" => "",
|
||||
"EndTime" => ""
|
||||
];
|
||||
$userRq = $this->requestToMCard("/SetDeviceData/user", $user);
|
||||
|
||||
$userAuthor = [
|
||||
"DeviceIP" => "192.168.1.200",
|
||||
"Pin" => 69,
|
||||
"AuthorizeTimezoneId" => 1,
|
||||
"AuthorizeDoorId" => 2
|
||||
];
|
||||
|
||||
$userAuthorRq = $this->requestToMCard("/SetDeviceData/userauthorize", $userAuthor);
|
||||
|
||||
return var_dump($timezoneRq, $userRq, $userAuthorRq);
|
||||
}
|
||||
|
||||
public function requestToMCard($path, $data) {
|
||||
return file_get_contents("http://192.168.2.119:2001" . $path, false, stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
'method' => "POST",
|
||||
'content' => json_encode($data)
|
||||
]
|
||||
]));
|
||||
}
|
||||
|
||||
public function convertTime($from, $to) {
|
||||
$fTemp = explode(":", $from);
|
||||
$front = dechex(intval($fTemp[0]) * 100 + intval($fTemp[1]));
|
||||
$tTemp = explode(":", $to);
|
||||
$back = dechex(intval($tTemp[0]) * 100 + intval($tTemp[1]));
|
||||
return hexdec("0" . $front . "0" . $back);
|
||||
$datas = json_decode(common::requestToCardService("/GetDeviceData/GetLog", [
|
||||
"DeviceIP" => "192.168.1.200"
|
||||
]), true);
|
||||
echo "<pre>";
|
||||
var_dump($datas);
|
||||
echo "</pre>";
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
use app\models\Logs;
|
||||
|
||||
/**
|
||||
* DeviceController implements the CRUD actions for Device model.
|
||||
@@ -338,7 +339,7 @@ class DeviceController extends Controller {
|
||||
if (Yii::$app->request->post()) {
|
||||
Yii::$app->response->format = "json";
|
||||
return [
|
||||
"title" => Html::tag("i", "", ["class" => "fa fa-exchange"]) . " Đồng bộ dữ liệu đến thiết bị",
|
||||
"title" => Html::tag("i", "", ["class" => "fa fa-refresh"]) . " Đồng bộ dữ liệu đến thiết bị",
|
||||
"form" => $this->renderPartial("sync"),
|
||||
"lists" => Yii::$app->request->post("lists")
|
||||
];
|
||||
@@ -444,4 +445,36 @@ class DeviceController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function actionGetLogs() {
|
||||
if (Yii::$app->request->post()) {
|
||||
Yii::$app->response->format = "json";
|
||||
return [
|
||||
"title" => Html::tag("i", "", ["class" => "fa fa-exchange"]) . " Lấy các sự kiện",
|
||||
"form" => $this->renderPartial("logs"),
|
||||
"lists" => Yii::$app->request->post("lists")
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function actionSyncLogs() {
|
||||
if (Yii::$app->request->post()) {
|
||||
Yii::$app->response->format = "json";
|
||||
$device = $this->findModel(Yii::$app->request->post("data"));
|
||||
$response = json_decode(common::requestToCardService("/GetDeviceData/GetLog", ["DeviceIP" => $device->ip_address]), true);
|
||||
$datas = [];
|
||||
foreach ($response as $key => $value) {
|
||||
if ($value["Cardno"] !== "0")
|
||||
$datas[] = [$value["Pin"], $value["Cardno"], $device->id, $value["DoorID"], $value["InOutState"], Logs::parseTime($value["Time_second"]), $value["EventType"]];
|
||||
}
|
||||
$model = new Logs();
|
||||
if ($model->multiCreate($datas)) {
|
||||
common::requestToCardService("/DeleteDeviceData/DeleteLog", ["DeviceIP" => $device->ip_address]);
|
||||
}
|
||||
return [
|
||||
"totals" => count($datas),
|
||||
"IP" => $device->ip_address
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
56
controllers/LogsController.php
Normal file
56
controllers/LogsController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers;
|
||||
|
||||
use Yii;
|
||||
use app\models\Logs;
|
||||
use app\models\LogsSearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
|
||||
/**
|
||||
* LogsController implements the CRUD actions for Logs model.
|
||||
*/
|
||||
class LogsController extends Controller {
|
||||
|
||||
public function init() {
|
||||
parent::init();
|
||||
if (Yii::$app->user->isGuest)
|
||||
return $this->redirect(['/site/login']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function behaviors() {
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['POST'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionIndex() {
|
||||
$this->view->title = 'Sự kiện hôm nay';
|
||||
$searchModel = new LogsSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function findModel($id) {
|
||||
if (($model = Logs::findOne($id)) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user