Переглянути джерело

:construction: 文章,文集使用雪花id

Bhikkhu-Kosalla 4 роки тому
батько
коміт
3714f2b514

+ 17 - 2
public/app/article/add_article_to_collect.php

@@ -7,6 +7,8 @@ require_once "../config.php";
 require_once "../public/_pdo.php";
 require_once '../public/function.php';
 require_once '../ucenter/function.php';
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
 
 $output  = array();
 $respond = array();
@@ -32,10 +34,23 @@ if(isset($_POST["id"])){
      if(count($data)>0){
         /* 开始一个事务,关闭自动提交 */
         $PDO->beginTransaction();
-        $query = "INSERT INTO "._TABLE_ARTICLE_COLLECTION_." (collect_id, article_id,level,title) VALUES (?, ?, ? , ?)";
+        $query = "INSERT INTO "._TABLE_ARTICLE_COLLECTION_." 
+                    (
+                        id,
+                        collect_id, 
+                        article_id,
+                        level,
+                        title
+                    ) VALUES (? , ?, ?, ? , ?)";
         $sth = $PDO->prepare($query);
         foreach ($data as $row) {
-            $sth->execute(array($row,$article_id,1,$title));
+            $sth->execute(array(
+                        $snowflake->id() , 
+                        $row,
+                        $article_id,
+                        1,
+                        $title
+                        ));
         }
         $PDO->commit();
         if (!$sth || ($sth && $sth->errorCode() != 0)) {

+ 9 - 2
public/app/article/function.php

@@ -158,10 +158,17 @@ class ArticleList extends Table
 		if(count($articleList)>0){
 			/* 开始一个事务,关闭自动提交 */
 			$this->dbh->beginTransaction();
-			$query = "INSERT INTO ".$this->table." (collect_id, article_id,level,title) VALUES ( ?, ?, ? , ? )";
+			$query = "INSERT INTO ".$this->table." (id, collect_id, article_id,level,title) VALUES (?, ?, ?, ? , ? )";
 			$sth = $this->dbh->prepare($query);
 			foreach ($articleList as $row) {
-				$sth->execute(array($collectionId,$row["article"],$row["level"],$row["title"]));
+				$sth->execute(
+                    array(
+                        $this->SnowFlake->id(),
+                        $collectionId,
+                        $row["article"],
+                        $row["level"],
+                        $row["title"]
+                        ));
 				if($this->redis){
 					#删除article权限缓存
 					$this->redis->del("power://article/".$row["article"]);

+ 1 - 0
public/app/article/my_article_post.php

@@ -8,6 +8,7 @@ require_once "../article/function.php";
 require_once "../redis/function.php";
 require_once "../db/custom_book.php";
 
+
 add_edit_event(_ARTICLE_EDIT_,$_POST["id"]);
 
 $respond=array("status"=>0,"message"=>"");

+ 21 - 3
public/app/article/my_article_put.php

@@ -7,6 +7,8 @@ require_once "../public/_pdo.php";
 require_once '../public/function.php';
 require_once '../hostsetting/function.php';
 require_once "../ucenter/active.php";
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
 
 $respond=array("ok"=>true,"message"=>"");
 if(!isset($_COOKIE["userid"])){
@@ -31,7 +33,9 @@ else{
 }
 PDO_Connect(_FILE_DB_USER_ARTICLE_,_DB_USERNAME_,_DB_PASSWORD_);
 
-$query="INSERT INTO "._TABLE_ARTICLE_." ( 
+$query="INSERT INTO "._TABLE_ARTICLE_." 
+        ( 
+            id,
 			uid,  
 			title  , 
 			subtitle  , 
@@ -44,13 +48,27 @@ $query="INSERT INTO "._TABLE_ARTICLE_." (
 			status  , 
 			create_time , 
 			modify_time    
-			)  VALUES  (  ? ,  ? , ? , ? , ? , ? , ? , ? ,? ,?, ? , ? ) ";
+			)  VALUES  ( ? , ? ,  ? , ? , ? , ? , ? , ? , ? ,? ,?, ? , ? ) ";
 $sth = $PDO->prepare($query);
 $uuid = UUID::v4();
 //写入日志
 add_edit_event(_ARTICLE_NEW_,$uuid);
 #新建文章默认私有
-$sth->execute(array($uuid , $_POST["title"] , "" ,"", $content  , $_COOKIE["user_uid"] , $_COOKIE["user_id"] , $_COOKIE["user_id"] , "{}" , 10 , mTime() ,  mTime()  ));
+$sth->execute(array(
+                $snowflake->id() , 
+                $uuid , 
+                $_POST["title"] , 
+                "" ,
+                "", 
+                $content  , 
+                $_COOKIE["user_uid"] , 
+                $_COOKIE["user_id"] , 
+                $_COOKIE["user_id"] , 
+                "{}" , 
+                10 , 
+                mTime() ,  
+                mTime()  
+                ));
 
 if (!$sth || ($sth && $sth->errorCode() != 0)) {
 	$error = PDO_ErrorInfo();

+ 18 - 3
public/app/article/my_collect_post.php

@@ -5,7 +5,8 @@ require_once '../public/function.php';
 require_once '../collect/function.php';
 require_once "../ucenter/active.php";
 require_once "../redis/function.php";
-
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
 
 $respond=array("status"=>0,"message"=>"");
 if(!isset($_COOKIE["userid"])){
@@ -52,10 +53,24 @@ else{
     if(count($arrList)>0){
         /* 开始一个事务,关闭自动提交 */
         $PDO->beginTransaction();
-        $query = "INSERT INTO "._TABLE_ARTICLE_COLLECTION_." (collect_id, article_id,level,title,children) VALUES ( ? , ?, ?, ? , ? )";
+        $query = "INSERT INTO "._TABLE_ARTICLE_COLLECTION_." (
+                            id,
+                            collect_id, 
+                            article_id,
+                            level,
+                            title,
+                            children
+                            ) VALUES (?, ? , ?, ?, ? , ? )";
         $sth = $PDO->prepare($query);
         foreach ($arrList as $row) {
-            $sth->execute(array($_POST["id"],$row->article,$row->level,$row->title,$row->children));
+            $sth->execute(array(
+                            $snowflake->id(),
+                            $_POST["id"],
+                            $row->article,
+                            $row->level,
+                            $row->title,
+                            $row->children
+                            ));
 			if($redis){
 				#删除article权限缓存
 				$redis->del("power://article/".$row->article);

+ 19 - 2
public/app/article/my_collect_put.php

@@ -4,6 +4,8 @@ require_once "../public/_pdo.php";
 require_once '../public/function.php';
 require_once '../hostsetting/function.php';
 require_once "../ucenter/active.php";
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
 
 $respond=array("status"=>0,"message"=>"");
 if(!isset($_COOKIE["userid"])){
@@ -27,6 +29,7 @@ add_edit_event(_COLLECTION_NEW_,$uuid);
 
 PDO_Connect(_FILE_DB_USER_ARTICLE_,_DB_USERNAME_,_DB_PASSWORD_);
 $query="INSERT INTO "._TABLE_COLLECTION_." ( 
+        id,
 		uid ,  
 		title  , 
 		subtitle  , 
@@ -39,9 +42,23 @@ $query="INSERT INTO "._TABLE_COLLECTION_." (
 		status  , 
 		create_time , 
 		modify_time    
-		)  VALUES  (  ? , ? , ?  , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ";
+		)  VALUES  ( ? , ? , ? , ?  , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ";
 $sth = $PDO->prepare($query);
-$sth->execute(array($uuid , $_POST["title"] , "" ,"", "[]" ,  $_COOKIE["user_uid"] ,  $_COOKIE["user_id"],  $_COOKIE["user_id"], "" , $_POST["status"] , mTime() ,  mTime() ));
+$sth->execute(array(
+                $snowflake->id() , 
+                $uuid , 
+                $_POST["title"] , 
+                "" ,
+                "",
+                 "[]" ,  
+                 $_COOKIE["user_uid"] ,  
+                 $_COOKIE["user_id"],  
+                 $_COOKIE["user_id"], 
+                 "" , 
+                 $_POST["status"] , 
+                 mTime() ,  
+                 mTime() 
+                 ));
 $respond=array("status"=>0,"message"=>"");
 if (!$sth || ($sth && $sth->errorCode() != 0)) {
 	$error = PDO_ErrorInfo();