check duplicate khi đồng bộ

This commit is contained in:
dongpd 2020-12-09 11:04:33 +07:00
parent 4cb2f77598
commit ed4b8a0144
4 changed files with 25 additions and 4 deletions

View File

@ -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() {

View File

@ -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']
])

View File

@ -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;
}
}

View File

@ -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"),