update mở tất cả cửa các thiết bị được chọn

This commit is contained in:
2020-11-05 13:57:18 +07:00
parent d420323d4b
commit 05545bafc9
4 changed files with 129 additions and 1 deletions

View File

@@ -626,7 +626,9 @@ class DeviceController extends Controller {
$model = $this->findModel($id);
return json_decode(common::requestToCardService("/ControlDevice", [
"DeviceIP" => $model->ip_address,
"DoorID" => $door
"DoorID" => [
"Door" . $door => "5"
]
]), true);
}
}
@@ -722,4 +724,46 @@ class DeviceController extends Controller {
}
}
public function actionOpenAllDoors() {
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-reply"]) . " Mở tất cả cửa",
"form" => $this->renderPartial("openDoor"),
"lists" => $lists
];
}
}
public function actionOpenDoorsOfDevice() {
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] = "5";
}
$response = json_decode(common::requestToCardService("/ControlDevice", [
"DeviceIP" => $device->ip_address,
"DoorID" => $doorOpen
]), true);
return [
"totals" => count($doors),
"IP" => $device->ip_address,
"response" => $response
];
}
}
}