From c4e631befecf20bebb2d0e464384ec321b3c37e8 Mon Sep 17 00:00:00 2001 From: dongpd Date: Wed, 11 Nov 2020 13:39:46 +0700 Subject: [PATCH] =?UTF-8?q?update=20m=E1=BB=9F=20t=E1=BA=A5t=20c=E1=BA=A3?= =?UTF-8?q?=20+=20=C4=91=C3=B3ng=20t=E1=BA=A5t=20c=E1=BA=A3=20c=E1=BB=ADa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/DeviceController.php | 49 +++++++++++++++++++++-- views/device/doors.tpl | 4 +- views/device/index.tpl | 4 ++ web/js/device.js | 67 ++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 5 deletions(-) diff --git a/controllers/DeviceController.php b/controllers/DeviceController.php index 45592a1e..1c32a5c1 100644 --- a/controllers/DeviceController.php +++ b/controllers/DeviceController.php @@ -707,8 +707,9 @@ class DeviceController extends Controller { } common::requestToCardService("/ControlDevice", [ "DeviceIP" => $device->ip_address, - "DoorID" => $model->code, - "Duration" => $duration + "DoorID" => [ + "Door" . $model->code => $duration + ] ]); } $model->modified_at = time(); @@ -752,7 +753,49 @@ class DeviceController extends Controller { $doors = Door::find()->andWhere(['device_id' => $device->id])->all(); $doorOpen = []; foreach ($doors as $key => $value) { - $doorOpen["Door" . $value->code] = "5"; + $doorOpen["Door" . $value->code] = 255; + } + $response = json_decode(common::requestToCardService("/ControlDevice", [ + "DeviceIP" => $device->ip_address, + "DoorID" => $doorOpen + ]), true); + return [ + "totals" => count($doors), + "IP" => $device->ip_address, + "response" => $response + ]; + } + } + + public function actionCloseAllDoors() { + if (Yii::$app->request->post()) { + Yii::$app->response->format = "json"; + $post = Yii::$app->request->post(); + $lists = $post["lists"]; + if ($post["all"] === "true") { + $temp = []; + $devices = Device::find()->all(); + foreach ($devices as $key => $value) { + $temp[] = $value->id; + } + $lists = $temp; + } + return [ + "title" => Html::tag("i", "", ["class" => "fa fa-remove"]) . " Đóng tất cả cửa", + "form" => $this->renderPartial("openDoor"), + "lists" => $lists + ]; + } + } + + public function actionCloseDoorsOfDevice() { + if (Yii::$app->request->post()) { + Yii::$app->response->format = "json"; + $device = $this->findModel(Yii::$app->request->post("data")); + $doors = Door::find()->andWhere(['device_id' => $device->id])->all(); + $doorOpen = []; + foreach ($doors as $key => $value) { + $doorOpen["Door" . $value->code] = 0; } $response = json_decode(common::requestToCardService("/ControlDevice", [ "DeviceIP" => $device->ip_address, diff --git a/views/device/doors.tpl b/views/device/doors.tpl index 15f7a6c6..0db8187b 100644 --- a/views/device/doors.tpl +++ b/views/device/doors.tpl @@ -35,10 +35,10 @@ - {* - *} diff --git a/views/device/index.tpl b/views/device/index.tpl index dfef4908..8bca0ac4 100644 --- a/views/device/index.tpl +++ b/views/device/index.tpl @@ -9,6 +9,7 @@ + @@ -55,6 +56,9 @@ + {/if}