Bổ sung các tính năng điều khiển engine
This commit is contained in:
@@ -882,4 +882,20 @@ class ApiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function actionCheckTimeEngine() {
|
||||
Yii::$app->response->format = "json";
|
||||
$config_engine = ["start_at" => "00:00", "end_at" => "23:59"];
|
||||
$engine_time_config = \app\models\SyncUrl::findOne(['key_config' => 'engine_time_config']);
|
||||
if ($engine_time_config)
|
||||
$config_engine = json_decode($engine_time_config->data, true);
|
||||
|
||||
$start_at = date_format(date_create_from_format('H:i:s d/m/Y', $config_engine['start_at'] . ":00 " . date("d/m/Y")), 'U');
|
||||
$end_at = date_format(date_create_from_format('H:i:s d/m/Y', $config_engine['end_at'] . ":59 " . date("d/m/Y")), 'U');
|
||||
$now = time();
|
||||
if ($now < $start_at || $now > $end_at)
|
||||
return ["status" => false];
|
||||
|
||||
return ["status" => true];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -161,6 +161,8 @@ class ConfigController extends Controller {
|
||||
$this->view->title = Yii::t("app", "CAU_HINH_MAY_CHU");
|
||||
if (Yii::$app->params['type'] != "BiFace")
|
||||
return $this->redirect(['cau-hinh-ip']);
|
||||
if (Yii::$app->user->identity->username != "admin")
|
||||
return $this->redirect(['cau-hinh-nhan-dien']);
|
||||
$options = [
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
@@ -421,6 +423,7 @@ class ConfigController extends Controller {
|
||||
if (!$checkConfig['status']) {
|
||||
return ['status' => false, 'text' => ''];
|
||||
} else {
|
||||
@file_get_contents("http://localhost:4004/SetupMedia");
|
||||
return ['status' => true, 'url' => Url::to(['cau-hinh-thiet-bi'])];
|
||||
}
|
||||
}
|
||||
@@ -430,6 +433,8 @@ class ConfigController extends Controller {
|
||||
$this->view->title = Yii::t("app", "CAU_HINH_THIET_BI");
|
||||
if (Yii::$app->params['type'] != "BiFace")
|
||||
return $this->redirect(['cau-hinh-ip']);
|
||||
if (Yii::$app->user->identity->username != "admin")
|
||||
return $this->redirect(['cau-hinh-nhan-dien']);
|
||||
|
||||
$tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([
|
||||
'http' => [
|
||||
@@ -588,4 +593,171 @@ class ConfigController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function getConfigJson() {
|
||||
$tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
'method' => "POST"
|
||||
]
|
||||
])), true);
|
||||
if (!$tempConfig['status'])
|
||||
return $this->redirect(['/config']);
|
||||
|
||||
$engineConfig = json_decode($tempConfig['data'], true);
|
||||
if (count($engineConfig['data']['engines']) == 0)
|
||||
return $this->redirect(['/config']);
|
||||
|
||||
$checkConfig = json_decode(file_get_contents("http://localhost:4004/ReadConfig", false, stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
'method' => "POST",
|
||||
'content' => json_encode([
|
||||
'path' => $engineConfig['data']['engines'][0]['path']
|
||||
])
|
||||
]
|
||||
])), true);
|
||||
|
||||
if (!$checkConfig['status'])
|
||||
return $this->redirect(['/config']);
|
||||
|
||||
$config_json = $this->config_json;
|
||||
if ($checkConfig['status'])
|
||||
$config_json = json_decode($checkConfig['data'], true);
|
||||
return $config_json;
|
||||
}
|
||||
|
||||
public function actionDieuKhienThietBi() {
|
||||
$this->view->title = Yii::t("app", "DIEU_KHIEN_THIET_BI");
|
||||
$config_json = $this->getConfigJson();
|
||||
|
||||
$config_engine = ["start_at" => "00:00", "end_at" => "23:59"];
|
||||
$engine_time_config = \app\models\SyncUrl::findOne(['key_config' => 'engine_time_config']);
|
||||
if ($engine_time_config)
|
||||
$config_engine = json_decode($engine_time_config->data, true);
|
||||
return $this->render('dieu-khien-thiet-bi', [
|
||||
"background" => $config_json['background'],
|
||||
"config_engine" => $config_engine,
|
||||
"config_light" => isset($config_json['open_door']['light']) ? $config_json['open_door']['light'] : false,
|
||||
"engineStatus" => json_decode(@file_get_contents("http://localhost:4004/EngineStatus"), true),
|
||||
"menu" => $this->renderPartial("menu", ["tab" => "device_controller"])
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionControlEngine($status) {
|
||||
if (Yii::$app->request->isAjax) {
|
||||
$options = [
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
'method' => "POST",
|
||||
'content' => json_encode(["action" => $status]),
|
||||
]
|
||||
];
|
||||
json_decode(@file_get_contents("http://localhost:4004/ControlEngine", false, stream_context_create($options)), true);
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
|
||||
public function actionSaveTimeLightConfig() {
|
||||
if (Yii::$app->request->post()) {
|
||||
$post = Yii::$app->request->post();
|
||||
$config_json = $this->getConfigJson();
|
||||
$config_json['open_door']['light'] = [
|
||||
"enable" => $post['enable'],
|
||||
"start_at" => $post['start_at'],
|
||||
"end_at" => $post['end_at']
|
||||
];
|
||||
$options = [
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
'method' => "POST"
|
||||
]
|
||||
];
|
||||
$tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create($options)), true);
|
||||
|
||||
if (!$tempConfig['status'])
|
||||
return false;
|
||||
|
||||
$engineConfig = json_decode($tempConfig['data'], true);
|
||||
$engineConfig['data']['engines'][0]['isConfig'] = "1";
|
||||
|
||||
file_get_contents("http://localhost:4004/SaveEngineConfig", false, stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
'method' => "POST",
|
||||
'content' => json_encode([
|
||||
'path' => $engineConfig['data']['engines'][0]['path'],
|
||||
'config' => $engineConfig,
|
||||
'configEngine' => json_encode($config_json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
|
||||
])
|
||||
]
|
||||
]));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function actionSaveTimeEngineConfig() {
|
||||
if (Yii::$app->request->post()) {
|
||||
$post = Yii::$app->request->post();
|
||||
$engine_time_config = \app\models\SyncUrl::findOne(['key_config' => 'engine_time_config']);
|
||||
$config_engine = ["start_at" => $post['start_at'], "end_at" => $post['end_at']];
|
||||
if ($engine_time_config) {
|
||||
$engine_time_config->data = json_encode($config_engine);
|
||||
$engine_time_config->save();
|
||||
} else {
|
||||
$model = new \app\models\SyncUrl();
|
||||
$model->create([
|
||||
'key_config' => 'engine_time_config',
|
||||
'data' => json_encode($config_engine)
|
||||
]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function actionBackground() {
|
||||
if (Yii::$app->request->post()) {
|
||||
$model = new \app\models\UploadForm();
|
||||
$path = "bg";
|
||||
$url = $model->UploadGlobal("image", ["PNG", "JPG", "JPEG", "GIF"], $path);
|
||||
|
||||
$config_json = $this->getConfigJson();
|
||||
$config_json['background'] = "/uploads" . $url;
|
||||
$options = [
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
'method' => "POST"
|
||||
]
|
||||
];
|
||||
$tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create($options)), true);
|
||||
|
||||
if (!$tempConfig['status'])
|
||||
return false;
|
||||
|
||||
$engineConfig = json_decode($tempConfig['data'], true);
|
||||
$engineConfig['data']['engines'][0]['isConfig'] = "1";
|
||||
|
||||
file_get_contents("http://localhost:4004/SaveEngineConfig", false, stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
'method' => "POST",
|
||||
'content' => json_encode([
|
||||
'path' => $engineConfig['data']['engines'][0]['path'],
|
||||
'config' => $engineConfig,
|
||||
'configEngine' => json_encode($config_json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
|
||||
])
|
||||
]
|
||||
]));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function actionSound() {
|
||||
if (Yii::$app->request->post()) {
|
||||
$model = new \app\models\UploadForm();
|
||||
$path = "audio";
|
||||
$model->UploadSound("sound", ["WAV"], $path);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user