fix tính năng luôn mở , luôn đóng
This commit is contained in:
parent
e4a665dd2e
commit
4cae8b3cb4
|
@ -635,22 +635,33 @@ class DeviceController extends Controller {
|
||||||
if (Yii::$app->request->isAjax) {
|
if (Yii::$app->request->isAjax) {
|
||||||
$model = Door::findOne($id);
|
$model = Door::findOne($id);
|
||||||
if ($model) {
|
if ($model) {
|
||||||
if ($model->duration !== $duration) {
|
$device = $this->findModel($model->device_id);
|
||||||
$device = $this->findModel($model->device_id);
|
if ($duration === "0") {
|
||||||
if ($duration === "0") {
|
if ($model->always_close) {
|
||||||
common::requestToCardService("/ControlDevice/ForceCloseDoor", [
|
$duration = $model->duration;
|
||||||
"DeviceIP" => $device->ip_address,
|
$model->always_close = 0;
|
||||||
"DoorID" => $model->code,
|
|
||||||
"Duration" => $duration
|
|
||||||
]);
|
|
||||||
} else {
|
} else {
|
||||||
common::requestToCardService("/ControlDevice", [
|
$duration = 0;
|
||||||
"DeviceIP" => $device->ip_address,
|
$model->always_close = 1;
|
||||||
"DoorID" => $model->code,
|
|
||||||
"Duration" => $duration
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
$model->duration = $duration;
|
common::requestToCardService("/SetDeviceData/DoorDriverTime", [
|
||||||
|
"DeviceIP" => $device->ip_address,
|
||||||
|
"DoorID" => $model->code,
|
||||||
|
"DoorDriverTime" => $duration
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
if ($model->always_open) {
|
||||||
|
$duration = 0;
|
||||||
|
$model->always_open = 0;
|
||||||
|
} else {
|
||||||
|
$duration = 255;
|
||||||
|
$model->always_open = 1;
|
||||||
|
}
|
||||||
|
common::requestToCardService("/ControlDevice", [
|
||||||
|
"DeviceIP" => $device->ip_address,
|
||||||
|
"DoorID" => $model->code,
|
||||||
|
"Duration" => $duration
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
$model->modified_at = time();
|
$model->modified_at = time();
|
||||||
$model->save();
|
$model->save();
|
||||||
|
@ -658,7 +669,9 @@ class DeviceController extends Controller {
|
||||||
Yii::$app->response->format = "json";
|
Yii::$app->response->format = "json";
|
||||||
return [
|
return [
|
||||||
"id" => $id,
|
"id" => $id,
|
||||||
"duration" => $duration
|
"duration" => $duration,
|
||||||
|
"always_close" => $model->always_close,
|
||||||
|
"always_open" => $model->always_open
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ use Yii;
|
||||||
* @property string $name
|
* @property string $name
|
||||||
* @property int $code
|
* @property int $code
|
||||||
* @property int $duration
|
* @property int $duration
|
||||||
|
* @property int $always_open
|
||||||
|
* @property int $always_close
|
||||||
* @property int $created_at
|
* @property int $created_at
|
||||||
* @property int $modified_at
|
* @property int $modified_at
|
||||||
*/
|
*/
|
||||||
|
@ -30,7 +32,7 @@ class Door extends \yii\db\ActiveRecord {
|
||||||
public function rules() {
|
public function rules() {
|
||||||
return [
|
return [
|
||||||
[['device_id', 'name', 'code'], 'required'],
|
[['device_id', 'name', 'code'], 'required'],
|
||||||
[['device_id', 'code', 'created_at', 'modified_at', 'duration'], 'integer'],
|
[['device_id', 'code', 'created_at', 'modified_at', 'duration', 'always_open', 'always_close'], 'integer'],
|
||||||
[['name'], 'string', 'max' => 100],
|
[['name'], 'string', 'max' => 100],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,9 @@
|
||||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||||
<group>
|
<group>
|
||||||
<file>file:/C:/xampp/htdocs/Server_AccessControl/views/auth-item/form.tpl</file>
|
<file>file:/C:/xampp/htdocs/Server_AccessControl/views/device/doors.tpl</file>
|
||||||
<file>file:/C:/xampp/htdocs/Server_AccessControl/controllers/AuthItemController.php</file>
|
<file>file:/C:/xampp/htdocs/Server_AccessControl/web/js/device.js</file>
|
||||||
<file>file:/C:/xampp/htdocs/Server_AccessControl/web/js/auth_item.js</file>
|
<file>file:/C:/xampp/htdocs/Server_AccessControl/controllers/DeviceController.php</file>
|
||||||
<file>file:/C:/xampp/htdocs/Server_AccessControl/models/AuthItem.php</file>
|
|
||||||
</group>
|
</group>
|
||||||
</open-files>
|
</open-files>
|
||||||
</project-private>
|
</project-private>
|
||||||
|
|
|
@ -35,10 +35,10 @@
|
||||||
<button class="btn btn-primary" onclick="openDoor(this);" data-href="{yii\helpers\Url::to(['open-door', 'id' => $model->id, 'door' => $d->code])}">
|
<button class="btn btn-primary" onclick="openDoor(this);" data-href="{yii\helpers\Url::to(['open-door', 'id' => $model->id, 'door' => $d->code])}">
|
||||||
Mở
|
Mở
|
||||||
</button>
|
</button>
|
||||||
<button class="change-duration-{$d->id} btn btn-{if $d->duration==255}warning{else}default{/if}" onclick="changeDuration(this);" data-href="{yii\helpers\Url::to(['change-duration', 'id' => $d->id, 'duration' => 255])}">
|
<button class="change-duration-{$d->id} btn btn-{if $d->always_open}warning{else}default{/if}" onclick="changeDuration(this);" data-href="{yii\helpers\Url::to(['change-duration', 'id' => $d->id, 'duration' => 255])}">
|
||||||
Luôn mở
|
Luôn mở
|
||||||
</button>
|
</button>
|
||||||
<button class="change-duration-{$d->id} btn btn-{if $d->duration==0}warning{else}default{/if}" onclick="changeDuration(this);" data-href="{yii\helpers\Url::to(['change-duration', 'id' => $d->id, 'duration' => 0])}">
|
<button class="change-duration-{$d->id} btn btn-{if $d->always_close}warning{else}default{/if}" onclick="changeDuration(this);" data-href="{yii\helpers\Url::to(['change-duration', 'id' => $d->id, 'duration' => 0])}">
|
||||||
Luôn đóng
|
Luôn đóng
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -555,9 +555,9 @@ function changeDuration(e) {
|
||||||
common.modalBlock(false);
|
common.modalBlock(false);
|
||||||
var id = parseInt(data.id);
|
var id = parseInt(data.id);
|
||||||
$(".change-duration-" + id).removeClass("btn-warning").addClass("btn-default");
|
$(".change-duration-" + id).removeClass("btn-warning").addClass("btn-default");
|
||||||
$(e).removeClass("btn-default").addClass("btn-warning");
|
if (data.always_close || data.always_open) {
|
||||||
$("#duration-text-" + id).html(data.duration);
|
$(e).removeClass("btn-default").addClass("btn-warning");
|
||||||
$("#duration-input-" + id).val(data.duration);
|
}
|
||||||
notification.success("Đã lưu thông tin", 2000);
|
notification.success("Đã lưu thông tin", 2000);
|
||||||
},
|
},
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user