diff --git a/controllers/DeviceController.php b/controllers/DeviceController.php index dae80f9b..cb7ce2a2 100644 --- a/controllers/DeviceController.php +++ b/controllers/DeviceController.php @@ -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 + ]; + } + } + } diff --git a/views/device/doors.tpl b/views/device/doors.tpl index 9501c213..ad8423ce 100644 --- a/views/device/doors.tpl +++ b/views/device/doors.tpl @@ -5,7 +5,7 @@