From ed4b8a01447227fb2b17be6e85c25a0c3a40796e Mon Sep 17 00:00:00 2001 From: dongpd Date: Wed, 9 Dec 2020 11:04:33 +0700 Subject: [PATCH] =?UTF-8?q?check=20duplicate=20khi=20=C4=91=E1=BB=93ng=20b?= =?UTF-8?q?=E1=BB=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/ApiController.php | 6 ++++-- controllers/ListManagementController.php | 10 ++++++++-- models/ListManagement.php | 9 +++++++++ web/js/list-management.js | 4 ++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/controllers/ApiController.php b/controllers/ApiController.php index 271bce1d..585d7fdd 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -97,8 +97,10 @@ class ApiController extends Controller { } public function actionData() { - Yii::$app->response->format = "json"; - return ListManagement::find()->orderBy(['id' => SORT_DESC])->all(); + if (Yii::$app->request->post()) { + Yii::$app->response->format = "json"; + return ListManagement::find()->andWhere(["NOT IN", "name", Yii::$app->request->post()])->orderBy(['id' => SORT_DESC])->all(); + } } public function actionFullData() { diff --git a/controllers/ListManagementController.php b/controllers/ListManagementController.php index 8d86140c..a6c5500d 100644 --- a/controllers/ListManagementController.php +++ b/controllers/ListManagementController.php @@ -236,12 +236,18 @@ class ListManagementController extends Controller { public function actionFormSync() { if (Yii::$app->request->post()) { $data = Yii::$app->request->post(); - $results = file_get_contents("http://" . $data['ip'] . "/api/data"); + $results = json_decode(file_get_contents("http://" . $data['ip'] . "/api/data", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST", + 'content' => json_encode(ListManagement::nameArray()) + ] + ])), true); Yii::$app->response->format = "json"; return [ "title" => $data['ip'], "form" => $this->renderPartial("list", [ - "results" => json_decode($results, true), + "results" => $results, "typeArray" => ListManagement::$typeArray, "ip" => $data['ip'] ]) diff --git a/models/ListManagement.php b/models/ListManagement.php index af3de96a..d01ff70c 100644 --- a/models/ListManagement.php +++ b/models/ListManagement.php @@ -83,4 +83,13 @@ class ListManagement extends \yii\db\ActiveRecord { "Female" => "Female" ]; + public static function nameArray() { + $res = []; + $ls = self::find()->all(); + foreach ($ls as $key => $value) { + $res[] = $value->name; + } + return $res; + } + } diff --git a/web/js/list-management.js b/web/js/list-management.js index 5d763c8b..990a8a37 100644 --- a/web/js/list-management.js +++ b/web/js/list-management.js @@ -316,6 +316,10 @@ function _sync(e) { $.each($("#sync-lists").find(".success"), function () { lists.push($(this).attr("data-id")); }); + if (lists.length == 0) { + alert("Không có dữ liệu đồng bộ!"); + return; + } common.modalBlock(true); $.ajax({ url: $(e).attr("data-href"),