2
0

commit.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. require_once "../config.php";
  3. require_once "../public/_pdo.php";
  4. require_once "../public/function.php";
  5. require_once "../channal/function.php";
  6. require_once "../redis/function.php";
  7. require_once "../share/function.php";
  8. require_once "../usent/function.php";
  9. $respond['message'] = "";
  10. $respond['status'] = 0;
  11. $_data = array();
  12. if (isset($_POST["data"])) {
  13. $_data = json_decode($_POST["data"], true);
  14. } else {
  15. $respond['message'] = "缺少输入数据";
  16. $respond['status'] = 1;
  17. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  18. exit;
  19. }
  20. $channelInfo = new Channal();
  21. $srcChannelPower = $channelInfo->getPower($_data["src"]);
  22. $destChannelPower = $channelInfo->getPower($_data["dest"]);
  23. if($srcChannelPower<10){
  24. $respond['message'] = "源channel无权限";
  25. $respond['status'] = 1;
  26. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  27. exit;
  28. }
  29. if($destChannelPower<10){
  30. $respond['message'] = "channel无权限";
  31. $respond['status'] = 1;
  32. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  33. exit;
  34. }
  35. $db_trans_sent = new PDO(_FILE_DB_SENTENCE_, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
  36. $db_trans_sent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  37. $query = "SELECT uid as id,
  38. parent_uid as parent,
  39. block_uid as block_id,
  40. channel_uid as channal,
  41. book_id as book,
  42. paragraph,
  43. word_start as begin,
  44. word_end as end,
  45. author,
  46. editor_uid as editor,
  47. content as text,
  48. language,
  49. version as ver,
  50. status,
  51. strlen,
  52. modify_time,
  53. create_time FROM "._TABLE_SENTENCE_." WHERE book_id= ? AND paragraph= ? AND word_start= ? AND word_end= ? AND channel_uid = ? ";
  54. $stmt = $db_trans_sent->prepare($query);
  55. if($stmt){
  56. $updateDate=array();
  57. $insertData=array();
  58. $prData=array();
  59. $insertHistoray=array();
  60. foreach ($_data["sent"] as $key => $value) {
  61. # code...
  62. $infoSrc = explode("-",$value);
  63. $infoDest = $infoSrc;
  64. $infoSrc[]=$_data["src"];
  65. $infoDest[]=$_data["dest"];
  66. $stmt->execute($infoSrc);
  67. $fetchSrc = $stmt->fetch(PDO::FETCH_ASSOC);
  68. if ($fetchSrc) {
  69. # 有 源数据
  70. $newData = $fetchSrc;
  71. $newData["modify_time"]=mTime();
  72. $newData["channal"]=$_data["dest"];
  73. $newData["landmark"]="";
  74. $stmt->execute($infoDest);
  75. $fetchDest = $stmt->fetch(PDO::FETCH_ASSOC);
  76. if ($fetchDest) {
  77. #有目标数据,比较时间
  78. $insert=false;
  79. if(isset($_data["compare"]) && $_data["compare"]=="auto"){
  80. if($fetchSrc["modify_time"]>$fetchDest["modify_time"]){
  81. $insert = true;
  82. }
  83. }
  84. else{
  85. $insert = true;
  86. }
  87. if($insert){
  88. #新数据 更新
  89. if($destChannelPower>=20){
  90. #有权限 直接写入
  91. $newData["id"]=$fetchDest["id"];
  92. $updateDate[] = $newData;
  93. $insertHistoray[] = $newData;
  94. }
  95. else{
  96. #pr
  97. $prData[] = $newData;
  98. }
  99. }
  100. }
  101. else{
  102. #没有目标数据新增
  103. if($destChannelPower>=20){
  104. #有写入权限 直接写入
  105. $newData["id"] = UUID::v4();
  106. $insertData[] = $newData;
  107. $insertHistoray[] = $newData;
  108. }
  109. else{
  110. #pr
  111. $prData[] = $newData;
  112. }
  113. }
  114. }
  115. }
  116. #到此,所有的数据已经准备好
  117. $sentDb = new Sent_DB();
  118. if($sentDb->update($updateDate)){
  119. $respond['update'] = count($updateDate);
  120. }
  121. else{
  122. $respond['message'] = $sentDb->getError();
  123. $respond['status'] = 1;
  124. }
  125. if($sentDb->insert($insertData)){
  126. $respond['insert'] = count($insertData);
  127. }else{
  128. $respond['message'] = $sentDb->getError();
  129. $respond['status'] = 1;
  130. }
  131. if($sentDb->send_pr($prData)){
  132. $respond['pr'] = count($prData);
  133. }else{
  134. $respond['message'] = $sentDb->getError();
  135. $respond['status'] = 1;
  136. }
  137. if($sentDb->historay($insertHistoray)){
  138. $respond['historay'] = count($insertHistoray);
  139. }else{
  140. $respond['message'] = $sentDb->getError();
  141. $respond['status'] = 1;
  142. }
  143. }
  144. else{
  145. $respond['message'] = $db_trans_sent->errorInfo();
  146. $respond['status'] = 1;
  147. }
  148. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  149. ?>