From 5b24af3ad5603cb9b7a1481c340afa8d32b5fe98 Mon Sep 17 00:00:00 2001 From: dongpd Date: Mon, 19 Oct 2020 17:44:52 +0700 Subject: [PATCH] =?UTF-8?q?fix=20bug=20=C4=91=E1=BB=93ng=20b=E1=BB=99=20d?= =?UTF-8?q?=E1=BB=AF=20li=E1=BB=87u?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/DeviceController.php | 11 +++++++++-- models/Staff.php | 4 +++- web/js/device.js | 9 ++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/controllers/DeviceController.php b/controllers/DeviceController.php index 70c8b28a..33a0bf0f 100644 --- a/controllers/DeviceController.php +++ b/controllers/DeviceController.php @@ -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"], diff --git a/models/Staff.php b/models/Staff.php index fc8bcf2a..cd5dc248 100644 --- a/models/Staff.php +++ b/models/Staff.php @@ -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); diff --git a/web/js/device.js b/web/js/device.js index 2d492e89..18578410 100644 --- a/web/js/device.js +++ b/web/js/device.js @@ -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) {