update: lấy dữ liệu mã thẻ từ thiết bị, mở cửa từ phần mềm

This commit is contained in:
dongpd 2020-10-26 14:25:49 +07:00
parent 579ec676cb
commit 2b88dbb695
7 changed files with 138 additions and 7 deletions

View File

@ -541,4 +541,15 @@ class DeviceController extends Controller {
} }
} }
public function actionOpenDoor($id, $door) {
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = "json";
$model = $this->findModel($id);
return json_decode(common::requestToCardService("/ControlDevice", [
"DeviceIP" => $model->ip_address,
"DoorID" => $door
]), true);
}
}
} }

View File

@ -12,6 +12,7 @@ use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\Url; use yii\helpers\Url;
use app\models\Device;
/** /**
* StaffController implements the CRUD actions for Staff model. * StaffController implements the CRUD actions for Staff model.
@ -79,7 +80,8 @@ class StaffController extends Controller {
"model" => $model, "model" => $model,
"url" => Url::to(["create"]), "url" => Url::to(["create"]),
"departmentArray" => Department::departmentArray(), "departmentArray" => Department::departmentArray(),
"genderArray" => Staff::$genderArray "genderArray" => Staff::$genderArray,
"deviceArray" => Device::deviceArray()
]) ])
]; ];
} }
@ -125,7 +127,8 @@ class StaffController extends Controller {
"model" => $model, "model" => $model,
"url" => Url::to(["update", "id" => $id]), "url" => Url::to(["update", "id" => $id]),
"departmentArray" => Department::departmentArray(), "departmentArray" => Department::departmentArray(),
"genderArray" => Staff::$genderArray "genderArray" => Staff::$genderArray,
"deviceArray" => Device::deviceArray()
]) ])
]; ];
} }
@ -302,4 +305,13 @@ class StaffController extends Controller {
} }
} }
public function actionGetRtlog() {
if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$device_id = Yii::$app->request->post("device");
$device = Device::findOne($device_id);
return json_decode(common::requestToCardService("/GetRTLog", ["DeviceIP" => $device->ip_address]), true);
}
}
} }

View File

@ -2,6 +2,10 @@
namespace app\helpers; namespace app\helpers;
use app\models\Door;
use yii\helpers\Html;
use yii\helpers\Url;
class DeviceGrid extends CommonGrid { class DeviceGrid extends CommonGrid {
public static function status($array) { public static function status($array) {
@ -30,4 +34,20 @@ class DeviceGrid extends CommonGrid {
}; };
} }
public static function openDoor() {
return function($model) {
$doors = Door::find()->andWhere(["device_id" => $model->id])->all();
$html = "";
foreach ($doors as $key => $value) {
$html .= Html::button($value->code, [
'class' => 'btn btn-info',
'data' => ['toggle' => 'tooltip', 'href' => Url::to(['open-door', 'id' => $model->id, 'door' => $value->code])],
'title' => \Yii::t('app', 'Mở cửa'),
'onclick' => "openDoor(this);"
]) . " ";
}
return $html;
};
}
} }

View File

@ -68,8 +68,14 @@
'value' => \app\helpers\DeviceGrid::checkbox("device", false) 'value' => \app\helpers\DeviceGrid::checkbox("device", false)
], ],
'name', 'name',
'serial', [
'ip_address', 'attribute' => 'serial',
'headerOptions' => ['style' => 'width:10%']
],
[
'attribute' => 'ip_address',
'headerOptions' => ['style' => 'width:10%']
],
'subnet_mask', 'subnet_mask',
'gateway', 'gateway',
'mac_address', 'mac_address',
@ -80,7 +86,11 @@
'contentOptions' => ['class' => 'text-center'], 'contentOptions' => ['class' => 'text-center'],
'value' => \app\helpers\DeviceGrid::status($statusArray) 'value' => \app\helpers\DeviceGrid::status($statusArray)
], ],
'type', [
'attribute' => 'type',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['style' => 'width:5%']
],
[ [
'attribute' => 'area_id', 'attribute' => 'area_id',
'format' => 'raw', 'format' => 'raw',
@ -88,7 +98,12 @@
'contentOptions' => ['class' => 'text-center'], 'contentOptions' => ['class' => 'text-center'],
'value' => \app\helpers\DeviceGrid::area($areaArray) 'value' => \app\helpers\DeviceGrid::area($areaArray)
], ],
'version' 'version',
[
'format' => 'raw',
'headerOptions' => ['style' => 'width:10%'],
'value' => \app\helpers\DeviceGrid::openDoor()
]
] ]
])} ])}
{/Pjax} {/Pjax}

View File

@ -81,9 +81,28 @@
<div class="input-group"> <div class="input-group">
<div class="input-group-addon">Mã thẻ</div> <div class="input-group-addon">Mã thẻ</div>
<input type="number" class="form-control" value="{$model->card_number|default:""}" name="CardNumber"> <input type="number" class="form-control" value="{$model->card_number|default:""}" name="CardNumber">
<div class="input-group-btn">
<button class="btn btn-warning" onclick="formGetRTLog(this);" data-stt="true" id="btn-get-rtlog">
<i class="fa fa-credit-card"></i>
</button>
</div>
</div> </div>
<span class="help-block hidden"></span> <span class="help-block hidden"></span>
</div> </div>
<div class="form-group hidden" id='device-lists'>
<div class="input-group">
<div class="input-group-addon">Chọn thiết bị</div>
<select class="form-control" name='Device'>
{html_options options=$deviceArray}
</select>
<div class="input-group-btn">
<button class="btn btn-info" onclick="getRTLog(this);" data-href='{yii\helpers\Url::to(["get-rtlog"])}' title='Lấy mã thẻ từ đầu đọc'>
<i class="fa fa-download"></i>
</button>
</div>
</div>
<span class="help-block hidden"></span>
</div>
<div class="form-group"> <div class="form-group">
<div class="input-group"> <div class="input-group">
<div class="input-group-addon">Phòng ban</div> <div class="input-group-addon">Phòng ban</div>

View File

@ -478,3 +478,22 @@ function processProgress(ai) {
$("#close-modal").attr("disabled", false); $("#close-modal").attr("disabled", false);
} }
} }
function openDoor(e) {
common.modalBlock(true);
$.ajax({
url: $(e).attr('data-href'),
type: 'POST',
success: function (data) {
common.modalBlock(false);
if (data.ErrorCode === "0")
notification.success("Mở cửa thành công", 2000);
else
notification.error("Mở cửa thất bại, không có kết nối tới thiết bị", 2000);
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}

View File

@ -257,4 +257,39 @@ function btnImage() {
} }
}).addInstance('AnhNhanVien'); }).addInstance('AnhNhanVien');
} }
;
function formGetRTLog(e) {
var stt = $(e).attr("data-stt");
if (stt === "true") {
$("#device-lists").removeClass("hidden");
$(e).attr("data-stt", false);
} else {
$("#device-lists").addClass("hidden");
$(e).attr("data-stt", true);
}
}
function getRTLog(e) {
common.modalBlock(true);
$.ajax({
url: $(e).attr('data-href'),
type: 'POST',
data: {
device: $("select[name='Device']").val()
},
success: function (data) {
common.modalBlock(false);
if (data.ErrorCode === "1") {
$("input[name='CardNumber']").val(data.CardNumber);
$("#device-lists").addClass("hidden");
$("#btn-get-rtlog").attr("data-stt", true);
} else {
alert("Không có tín hiệu thẻ");
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
alert("Không có tín hiệu thẻ");
}
});
}