chỉ đồng bộ logs với event type được lựa chọn

This commit is contained in:
dongpd 2020-10-20 11:10:01 +07:00
parent 018ca540d5
commit b5619f7a5f
2 changed files with 12 additions and 1 deletions

View File

@ -16,6 +16,7 @@ use yii\filters\VerbFilter;
use yii\helpers\Html;
use yii\helpers\Url;
use app\models\Logs;
use app\models\EventType;
/**
* DeviceController implements the CRUD actions for Device model.
@ -472,8 +473,9 @@ class DeviceController extends Controller {
$device = $this->findModel(Yii::$app->request->post("data"));
$response = json_decode(common::requestToCardService("/GetDeviceData/GetLog", ["DeviceIP" => $device->ip_address]), true);
$datas = [];
$eventTypeCode = EventType::eventTypeCode();
foreach ($response as $key => $value) {
if ($value["Cardno"] !== "0")
if ($value["Cardno"] !== "0" && in_array($value["EventType"], $eventTypeCode))
$datas[] = [$value["Pin"], $value["Cardno"], $device->id, $value["DoorID"], $value["InOutState"], Logs::parseTime($value["Time_second"]), $value["EventType"]];
}
$model = new Logs();

View File

@ -54,4 +54,13 @@ class EventType extends \yii\db\ActiveRecord {
return $results;
}
public static function eventTypeCode() {
$lists = self::find()->all();
$results = [];
foreach ($lists as $key => $value) {
$results[] = $value->code;
}
return $results;
}
}