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) {
|
||||
$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
|
||||
]);
|
||||
$device = $this->findModel($model->device_id);
|
||||
if ($duration === "0") {
|
||||
if ($model->always_close) {
|
||||
$duration = $model->duration;
|
||||
$model->always_close = 0;
|
||||
} else {
|
||||
common::requestToCardService("/ControlDevice", [
|
||||
"DeviceIP" => $device->ip_address,
|
||||
"DoorID" => $model->code,
|
||||
"Duration" => $duration
|
||||
]);
|
||||
$duration = 0;
|
||||
$model->always_close = 1;
|
||||
}
|
||||
$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->save();
|
||||
|
@ -658,7 +669,9 @@ class DeviceController extends Controller {
|
|||
Yii::$app->response->format = "json";
|
||||
return [
|
||||
"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 int $code
|
||||
* @property int $duration
|
||||
* @property int $always_open
|
||||
* @property int $always_close
|
||||
* @property int $created_at
|
||||
* @property int $modified_at
|
||||
*/
|
||||
|
@ -30,7 +32,7 @@ class Door extends \yii\db\ActiveRecord {
|
|||
public function rules() {
|
||||
return [
|
||||
[['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],
|
||||
];
|
||||
}
|
||||
|
|
|
@ -3,10 +3,9 @@
|
|||
<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">
|
||||
<group>
|
||||
<file>file:/C:/xampp/htdocs/Server_AccessControl/views/auth-item/form.tpl</file>
|
||||
<file>file:/C:/xampp/htdocs/Server_AccessControl/controllers/AuthItemController.php</file>
|
||||
<file>file:/C:/xampp/htdocs/Server_AccessControl/web/js/auth_item.js</file>
|
||||
<file>file:/C:/xampp/htdocs/Server_AccessControl/models/AuthItem.php</file>
|
||||
<file>file:/C:/xampp/htdocs/Server_AccessControl/views/device/doors.tpl</file>
|
||||
<file>file:/C:/xampp/htdocs/Server_AccessControl/web/js/device.js</file>
|
||||
<file>file:/C:/xampp/htdocs/Server_AccessControl/controllers/DeviceController.php</file>
|
||||
</group>
|
||||
</open-files>
|
||||
</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])}">
|
||||
Mở
|
||||
</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ở
|
||||
</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
|
||||
</button>
|
||||
</td>
|
||||
|
|
|
@ -555,9 +555,9 @@ function changeDuration(e) {
|
|||
common.modalBlock(false);
|
||||
var id = parseInt(data.id);
|
||||
$(".change-duration-" + id).removeClass("btn-warning").addClass("btn-default");
|
||||
$(e).removeClass("btn-default").addClass("btn-warning");
|
||||
$("#duration-text-" + id).html(data.duration);
|
||||
$("#duration-input-" + id).val(data.duration);
|
||||
if (data.always_close || data.always_open) {
|
||||
$(e).removeClass("btn-default").addClass("btn-warning");
|
||||
}
|
||||
notification.success("Đã lưu thông tin", 2000);
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user