Просмотр исходного кода

:bug: 删除文章 不能更新collect库

visuddhinanda 5 лет назад
Родитель
Сommit
43547acf06

+ 33 - 5
app/article/add_article_to_collect.php

@@ -8,11 +8,23 @@ require_once '../ucenter/function.php';
 
 $output  = array();
 $respond = array();
+$respond['status']=0;
+$respond['message']="";
+$respond['id']=$_POST["id"];
+
 if(isset($_POST["id"])){
+    $dirty_collect = array();
     $data = json_decode($_POST["data"]);
     $title = $_POST["title"];
     PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
     $article_id=$_POST["id"];
+    //找出脏的collect
+    $query = "SELECT collect_id FROM article_list  WHERE article_id = ? ";
+    $collect = PDO_FetchAll($query,array($article_id));
+    foreach ($collect as $key => $value) {
+        # code...
+        $dirty_collect[$value["collect_id"]] = 1;
+    }
     $query = "DELETE FROM article_list WHERE article_id = ? ";
      PDO_Execute($query,array($article_id));
      if(count($data)>0){
@@ -31,14 +43,30 @@ if(isset($_POST["id"])){
             $respond['status']=1;
             $respond['message']=$error[2];
         }
-        else{
-            $respond['status']=0;
-            $respond['message']="成功";
-        }	         
      }
 
-	echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+     # 更新collect
+     $query = "SELECT collect_id FROM article_list WHERE article_id  = ?";
+     $collect = PDO_FetchAll($query,array($article_id));
+     foreach ($collect as $key => $value) {
+        # code...
+        $dirty_collect[$value["collect_id"]] = 1;
+    }
+     foreach ($dirty_collect as $key => $value) {
+         # code...
+         $query = "SELECT level,article_id as article , title FROM article_list WHERE collect_id  = ?";
+         $collect_info = PDO_FetchAll($query,array($key));
+         $query = "UPDATE collect SET article_list = ? WHERE id = ? ";
+         $strArticleList = json_encode($collect_info, JSON_UNESCAPED_UNICODE);
+         $stmt = PDO_Execute($query,array( $strArticleList ,$key));
+         if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+             $error = PDO_ErrorInfo();
+             $respond['status']=1;
+             $respond['message']=$error[2];
+         }
+     }
 
 }
 
+	echo json_encode($respond, JSON_UNESCAPED_UNICODE);
 ?>

+ 20 - 4
app/article/add_to_collect_dlg.js

@@ -2,7 +2,7 @@ function add_to_collect_dlg_init() {
   $("[vui='collect-dlg']").each(function () {
     $(this).css("position", "relative");
     $(this).html(
-      "<span class='button_add_to_collect'>添加到作品集</span><div class='float_dlg'></div>"
+      "<span class='button_add_to_collect'>添加到集</span><div class='float_dlg'></div>"
     );
   });
 
@@ -25,10 +25,13 @@ function add_to_collect_dlg_init() {
       "<button onclick=\"article_add_to_collect_ok('" +
       article_id +
       "')\">Finish</button>";
-    html += "<button onclick='article_add_to_collect_cancel()'>Cancel</button>";
+    html +=
+      "<button onclick=\"article_add_to_collect_cancel('" +
+      article_id +
+      "')\">Cancel</button>";
     html += "</div>";
     html += "</div>";
-    $(this).siblings(".float_dlg").first().append(html);
+    $(this).siblings(".float_dlg").first().html(html);
     $(this).siblings(".float_dlg").first().show();
     $.get(
       "../article/list_article_in_collect.php",
@@ -88,8 +91,21 @@ function article_add_to_collect_ok(article_id) {
     },
     function (data) {
       let result = JSON.parse(data);
+      if (result.status > 0) {
+        alert(result.message);
+      } else {
+        add_to_collect_dlg_close(result.id);
+      }
     }
   );
 }
 
-function article_add_to_collect_cancel() {}
+function article_add_to_collect_cancel(article_id) {
+  add_to_collect_dlg_close(article_id);
+}
+
+function add_to_collect_dlg_close(article_id) {
+  $("#add_to_collect_dlg_" + article_id)
+    .parent()
+    .hide();
+}

+ 4 - 4
app/article/article.js

@@ -61,12 +61,12 @@ function articel_load_collect(article_id) {
             let nextArticle = "无";
             for (let index = 0; index < article_list.length; index++) {
               const element = article_list[index];
-              if (element.aticle == _articel_id) {
+              if (element.article == _articel_id) {
                 if (index > 0) {
                   const prev = article_list[index - 1];
                   prevArticle =
                     "<a href='../article/index.php?id=" +
-                    prev.aticle +
+                    prev.article +
                     display +
                     "'>" +
                     prev.title +
@@ -76,7 +76,7 @@ function articel_load_collect(article_id) {
                   const next = article_list[index + 1];
                   nextArticle =
                     "<a href='../article/index.php?id=" +
-                    next.aticle +
+                    next.article +
                     display +
                     "'>" +
                     next.title +
@@ -90,7 +90,7 @@ function articel_load_collect(article_id) {
                 element.level +
                 "'>" +
                 "<a href='../article/index.php?id=" +
-                element.aticle +
+                element.article +
                 display +
                 "'>" +
                 element.title +

+ 15 - 3
app/article/collect_get.php

@@ -21,14 +21,26 @@ if(isset($_GET["id"])){
     }
 }
 else if(isset($_GET["article"])){
+    # 给文章编号,查文集信息
     PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
     $article=$_GET["article"];
-    $query = "select * from collect  where article_list like ".$PDO->quote('%'.$article.'%');
-    $Fetch = PDO_FetchAll($query);
+    $query = "SELECT collect_id FROM article_list  WHERE article_id = ? ";
+    $Fetch = PDO_FetchAll($query,array($article));
+    
+    /*  使用一个数组的值执行一条含有 IN 子句的预处理语句 */
+    $params = array();
+    foreach ($Fetch as $key => $value) {
+        # code...
+        $params[] = $value["collect_id"];
+    }
+    /*  创建一个填充了和params相同数量占位符的字符串 */
+    $place_holders = implode(',', array_fill(0, count($params), '?'));
+
+    $query = "SELECT * FROM collect WHERE id IN ($place_holders)";
 
+    $Fetch = PDO_FetchAll($query,$params);
         echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
         exit;
-
 }
 
 echo json_encode(array(), JSON_UNESCAPED_UNICODE);