Server_AccessControl/models/Logs.php

90 lines
2.5 KiB
PHP

<?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' => 'Mã nhân viên',
'card_number' => 'Mã thẻ',
'device_id' => 'Thiết bị',
'door_id' => 'Cửa',
'in_out_state' => 'Trạng thái vào/ra',
'time' => 'Thời gian',
'event_type' => 'Mô tả sự kiện',
'staff_name' => 'Tên nhân viên',
'staff_department' => 'Phòng ban',
'staff_code' => 'Mã nhân viên'
];
}
public static $stateArray = [
0 => "Vào",
1 => "Ra"
];
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 function getStaff() {
return $this->hasOne(Staff::className(), ["id" => "staff_id"]);
}
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');
}
}