fix bug đồng bộ dữ liệu

This commit is contained in:
dongpd 2020-10-19 17:44:52 +07:00
parent 0314fa4158
commit 5b24af3ad5
3 changed files with 16 additions and 8 deletions

View File

@ -365,7 +365,6 @@ class DeviceController extends Controller {
$schedule = array_unique($schedule);
return [
"IP" => $this->findModel($device_id)->ip_address,
"staffs" => $staffs,
"schedule" => $schedule
];
}
@ -408,9 +407,17 @@ class DeviceController extends Controller {
if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$post = Yii::$app->request->post();
$staff_lists = $post["data"];
$device_id = Device::findOne(['ip_address' => $post['ip']])->id;
$doors = Door::find()->andWhere(["device_id" => $device_id])->all();
$filter = ["OR"];
foreach ($doors as $key => $value) {
$filter[] = ["LIKE", "door_access", '"' . $value->id . '"'];
}
$staff_lists = Staff::find()->andWhere($filter)->all();
$UserInfos = [];
$UserAuthorizeInfos = [];
foreach ($staff_lists as $key => $value) {
$UserInfos[] = [
"CardNo" => $value["card_number"],

View File

@ -131,7 +131,9 @@ class Staff extends \yii\db\ActiveRecord {
if ($this->door_access) {
$ls = json_decode($this->door_access, true);
foreach ($ls as $key => $value) {
$doors[] = Door::findOne($value)->name;
$dInfo = Door::findOne($value);
if ($dInfo)
$doors[] = $dInfo->name;
}
}
return implode(", ", $doors);

View File

@ -307,7 +307,7 @@ function getDataSync(data) {
}
return;
}
syncSchedule(data.schedule, data.staffs, data.IP);
syncSchedule(data.schedule, data.IP);
},
error: function (jqXHR, textStatus, errorThrown) {
common.ajaxError();
@ -315,7 +315,7 @@ function getDataSync(data) {
});
}
function syncSchedule(schedule, staffs, ip) {
function syncSchedule(schedule, ip) {
$.ajax({
url: $("input[name='sync_schedule_url']").val(),
type: 'POST',
@ -337,7 +337,7 @@ function syncSchedule(schedule, staffs, ip) {
progress = 0;
$("#close-modal").attr("disabled", false);
}
syncStaffs(staffs, ip);
syncStaffs(ip);
},
error: function (jqXHR, textStatus, errorThrown) {
common.ajaxError();
@ -345,12 +345,11 @@ function syncSchedule(schedule, staffs, ip) {
});
}
function syncStaffs(data, ip) {
function syncStaffs(ip) {
$.ajax({
url: $("input[name='sync_staffs_url']").val(),
type: 'POST',
data: {
data: data,
ip: ip
},
success: function (data) {