Thêm nút Luôn mở + luôn đóng

This commit is contained in:
2020-10-30 17:38:12 +07:00
parent 41598c6225
commit 35de1bf6b0
3 changed files with 66 additions and 2 deletions

View File

@@ -601,4 +601,36 @@ class DeviceController extends Controller {
}
}
public function actionChangeDuration($id, $duration) {
if (Yii::$app->request->isAjax) {
$model = Door::findOne($id);
if ($model) {
if ($model->duration !== $duration) {
$device = $this->findModel($model->device_id);
if ($duration === "0") {
common::requestToCardService("/ControlDevice/ForceCloseDoor", [
"DeviceIP" => $device->ip_address,
"DoorID" => $model->code,
"Duration" => $duration
]);
} else {
common::requestToCardService("/ControlDevice", [
"DeviceIP" => $device->ip_address,
"DoorID" => $model->code,
"Duration" => $duration
]);
}
$model->duration = $duration;
}
$model->modified_at = time();
$model->save();
}
Yii::$app->response->format = "json";
return [
"id" => $id,
"duration" => $duration
];
}
}
}