get logs from device
This commit is contained in:
77
models/Logs.php
Normal file
77
models/Logs.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "logs".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $staff_id
|
||||
* @property int $card_number
|
||||
* @property int $device_id
|
||||
* @property int $door_id
|
||||
* @property int $in_out_state
|
||||
* @property int $time
|
||||
* @property int $event_type
|
||||
*/
|
||||
class Logs extends \yii\db\ActiveRecord {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName() {
|
||||
return 'logs';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules() {
|
||||
return [
|
||||
[['staff_id', 'device_id', 'door_id', 'in_out_state', 'time', 'event_type', 'card_number'], 'integer'],
|
||||
[['device_id', 'door_id', 'in_out_state', 'time', 'event_type', 'card_number'], 'required'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels() {
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'staff_id' => 'Staff ID',
|
||||
'card_number' => 'card_number',
|
||||
'device_id' => 'Device ID',
|
||||
'door_id' => 'Door ID',
|
||||
'in_out_state' => 'In Out State',
|
||||
'time' => 'Time',
|
||||
'event_type' => 'Event Type',
|
||||
];
|
||||
}
|
||||
|
||||
public function multiCreate($datas) {
|
||||
$field = ['staff_id', 'card_number', 'device_id', 'door_id', 'in_out_state', 'time', 'event_type'];
|
||||
static::getDb()->createCommand()->batchInsert($this->tableName(), $field, $datas)->execute();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function parseTime($time) {
|
||||
$temp = intval($time);
|
||||
$second = $temp % 60;
|
||||
$temp = $temp / 60;
|
||||
$minute = $temp % 60;
|
||||
$temp = $temp / 60;
|
||||
$hour = $temp % 24;
|
||||
$temp = $temp / 24;
|
||||
$day = $temp % 31 + 1;
|
||||
$temp = $temp / 31;
|
||||
$month = $temp % 12 + 1;
|
||||
$temp = $temp / 12;
|
||||
$year = $temp + 2000;
|
||||
$timeFull = sprintf("%02d", $hour) . ":" . sprintf("%02d", $minute) . ":" . sprintf("%02d", $second) . " " . sprintf("%02d", $day) . "/" . sprintf("%02d", $month) . "/" . intval($year);
|
||||
return date_format(date_create_from_format('H:i:s d/m/Y', $timeFull), 'U');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user