Selaa lähdekoodia

:construction: 加入雪花id

Bhikkhu-Kosalla 4 vuotta sitten
vanhempi
sitoutus
f16f0a6f25
3 muutettua tiedostoa jossa 130 lisäystä ja 90 poistoa
  1. 32 9
      public/app/usent/function.php
  2. 73 62
      public/app/usent/sent_post.php
  3. 25 19
      public/app/usent/update.php

+ 32 - 9
public/app/usent/function.php

@@ -3,14 +3,26 @@ require_once "../config.php";
 require_once "../share/function.php";
 require_once "../channal/function.php";
 require_once "../db/table.php";
+require_once __DIR__."/../public/snowflakeid.php";
+
 
 function update_historay($sent_id, $user_id, $text, $landmark)
 {
     # 更新historay
-    PDO_Connect("" . _FILE_DB_USER_SENTENCE_HISTORAY_);
-    $query = "INSERT INTO "._TABLE_SENTENCE_HISTORAY_." (sent_uid,  user_uid,  content,  date, landmark) VALUES (? , ? , ? , ? , ? )";
+    $snowflake = new SnowFlakeId();
+    PDO_Connect(_FILE_DB_USER_SENTENCE_HISTORAY_);
+    $query = "INSERT INTO "._TABLE_SENTENCE_HISTORAY_." 
+    (
+        id,
+        sent_uid,  
+        user_uid,  
+        content,  
+        create_time, 
+        landmark) VALUES (? , ? , ? , ? , ? , ? )";
     $stmt = PDO_Execute($query,
-        array($sent_id,
+        array(
+            $snowflake->id(),
+            $sent_id,
             $user_id,
             $text,
             mTime(),
@@ -373,17 +385,28 @@ class Sent_DB
 			$this->errorMsg = "";
 			return true;
 		}
+        $snowflake = new SnowFlakeId();
 		$this->dbh_his->beginTransaction();
 		# 更新historay
-		$query = "INSERT INTO "._TABLE_SENTENCE_HISTORAY_." (sent_uid,  user_uid,  content,  date, landmark) VALUES (? , ? , ? , ? , ? )";
+		$query = "INSERT INTO "._TABLE_SENTENCE_HISTORAY_." 
+        (
+            id,
+            sent_uid,  
+            user_uid,  
+            content,  
+            create_time, 
+            landmark
+            ) VALUES (? , ? , ? , ? , ? , ? )";
 		$stmt = $this->dbh_his->prepare($query);
 
 		foreach ($arrData as $data) {
-			$stmt->execute(array($data["id"],
-							$data["editor"],
-							$data["text"],
-							mTime(),
-							$data["landmark"]));
+			$stmt->execute(
+                $snowflake->id(),
+                array($data["id"],
+                $data["editor"],
+                $data["text"],
+                mTime(),
+                $data["landmark"]));
 		}
 		$this->dbh_his->commit();
 		if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {

+ 73 - 62
public/app/usent/sent_post.php

@@ -7,6 +7,8 @@ require_once "../public/function.php";
 require_once "../usent/function.php";
 require_once "../ucenter/active.php";
 require_once "../share/function.php";
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
 
 #检查是否登陆
 if (!isset($_COOKIE["userid"])) {
@@ -89,26 +91,30 @@ if ($_id == false) {
     # 没有id新建
     if ($cooperation >=20) {
         #有写入权限
-        $query = "INSERT INTO "._TABLE_SENTENCE_." (uid,
-		parent_uid,
-		book_id,
-                                        paragraph,
-                                        word_start,
-                                        word_end,
-                                        channel_uid,
-                                        author,
-                                        editor_uid,
-                                        content,
-                                        language,
-                                        status,
-                                        strlen,
-                                        modify_time,
-                                        create_time
-                                        )
-										VALUES (?, ?, ?, ?,  ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
+        $query = "INSERT INTO "._TABLE_SENTENCE_." (
+            id,
+            uid,
+            parent_uid,
+            book_id,
+            paragraph,
+            word_start,
+            word_end,
+            channel_uid,
+            author,
+            editor_uid,
+            content,
+            language,
+            status,
+            strlen,
+            modify_time,
+            create_time
+            )
+            VALUES (? , ?, ?, ?, ?,  ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
         $stmt = $PDO->prepare($query);
         $newId = UUID::v4();
-        $stmt->execute(array($newId,
+        $stmt->execute(array(
+            $snowflake->id(),
+            $newId,
             "",
             $_POST["book"],
             $_POST["para"],
@@ -145,38 +151,41 @@ if ($_id == false) {
         }
     } else {
 		#没写入权限 插入pr数据
-		$query = "INSERT INTO "._TABLE_SENTENCE_PR_." (
-										book_id,
-										paragraph,
-										word_start,
-										word_end,
-										channel_uid,
-										author,
-										editor_uid,
-										content,
-										language,
-										status,
-										strlen,
-										modify_time,
-										create_time
-										)
-										VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
+		$query = "INSERT INTO "._TABLE_SENTENCE_PR_." 
+        (
+            id,
+            book_id,
+            paragraph,
+            word_start,
+            word_end,
+            channel_uid,
+            author,
+            editor_uid,
+            content,
+            language,
+            status,
+            strlen,
+            modify_time,
+            create_time
+            )
+            VALUES ( ? , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
 		$stmt = $PDO->prepare($query);
 		# 初始状态 1 未处理
 		$stmt->execute(array(
-							$_POST["book"],
-							$_POST["para"],
-							$_POST["begin"],
-							$_POST["end"],
-							$_POST["channal"],
-							"",
-							$_COOKIE["userid"],
-							$_POST["text"],
-							$text_lang,
-							1,
-							mb_strlen($_POST["text"], "UTF-8"),
-							mTime(),
-							mTime()
+            $snowflake->id(),
+            $_POST["book"],
+            $_POST["para"],
+            $_POST["begin"],
+            $_POST["end"],
+            $_POST["channal"],
+            "",
+            $_COOKIE["userid"],
+            $_POST["text"],
+            $text_lang,
+            1,
+            mb_strlen($_POST["text"], "UTF-8"),
+            mTime(),
+            mTime()
 							));
 		if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
 			/*  识别错误  */
@@ -225,6 +234,7 @@ if ($_id == false) {
         #TO DO没权限 插入pr数据
 		#没写入权限 插入pr数据
 		$query = "INSERT INTO "._TABLE_SENTENCE_PR_." (
+            id,
 			book_id,
 			paragraph,
 			word_start,
@@ -239,24 +249,25 @@ if ($_id == false) {
 			modify_time,
 			create_time
 			)
-			VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
+			VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
 		$stmt = $PDO->prepare($query);
 		# 初始状态 1 未处理
 		$stmt->execute(array(
-							$_POST["book"],
-							$_POST["para"],
-							$_POST["begin"],
-							$_POST["end"],
-							$_POST["channal"],
-							"",
-							$_COOKIE["userid"],
-							$_POST["text"],
-							$text_lang,
-							1,
-							mb_strlen($_POST["text"], "UTF-8"),
-							mTime(),
-							mTime()
-							));
+            $snowflake->id(),
+            $_POST["book"],
+            $_POST["para"],
+            $_POST["begin"],
+            $_POST["end"],
+            $_POST["channal"],
+            "",
+            $_COOKIE["userid"],
+            $_POST["text"],
+            $text_lang,
+            1,
+            mb_strlen($_POST["text"], "UTF-8"),
+            mTime(),
+            mTime()
+            ));
 		if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
 			/*  识别错误  */
 			$error = PDO_ErrorInfo();

+ 25 - 19
public/app/usent/update.php

@@ -9,6 +9,8 @@ require_once "../public/function.php";
 require_once "../usent/function.php";
 require_once "../channal/function.php";
 require_once "../ucenter/active.php";
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
 
 #检查是否登陆
 if (!isset($_COOKIE["userid"])) {
@@ -106,24 +108,26 @@ if (count($oldList) > 0) {
 if (count($newList) > 0) {
     add_edit_event(_SENT_NEW_, "{$newList[0]["book"]}-{$newList[0]["paragraph"]}-{$newList[0]["begin"]}-{$newList[0]["end"]}@{$newList[0]["channal"]}");
     $PDO->beginTransaction();
-    $query = "INSERT INTO "._TABLE_SENTENCE_." (uid,
-									parent_uid,
-									book_id,
-									paragraph,
-									word_start,
-									word_end,
-									channel_uid,
-									author,
-									editor_uid,
-									content,
-									language,
-									version,
-									status,
-									strlen,
-									modify_time,
-									create_time
-									)
-						VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
+    $query = "INSERT INTO "._TABLE_SENTENCE_." (
+        id,
+        uid,
+        parent_uid,
+        book_id,
+        paragraph,
+        word_start,
+        word_end,
+        channel_uid,
+        author,
+        editor_uid,
+        content,
+        language,
+        version,
+        status,
+        strlen,
+        modify_time,
+        create_time
+        )
+		VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,? )";
     $sth = $PDO->prepare($query);
 
     $channel_info = new Channal();
@@ -144,7 +148,9 @@ if (count($newList) > 0) {
             $lang = $queryChannel["lang"];
             $status = $queryChannel["status"];
         }
-        $sth->execute(array($uuid,
+        $sth->execute(array(
+            $snowflake->id(),
+            $uuid,
             $parent,
             $data["book"],
             $data["paragraph"],