commit.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. require_once "../path.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_, "", "", array(PDO::ATTR_PERSISTENT => true));
  36. $db_trans_sent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  37. $query = "SELECT * FROM sentence WHERE book= ? AND paragraph= ? AND begin= ? AND end= ? AND channal = ? ";
  38. $stmt = $db_trans_sent->prepare($query);
  39. if($stmt){
  40. $updateDate=array();
  41. $insertData=array();
  42. $prData=array();
  43. $insertHistoray=array();
  44. foreach ($_data["sent"] as $key => $value) {
  45. # code...
  46. $infoSrc = explode("-",$value);
  47. $infoDest = $infoSrc;
  48. $infoSrc[]=$_data["src"];
  49. $infoDest[]=$_data["dest"];
  50. $stmt->execute($infoSrc);
  51. $fetchSrc = $stmt->fetch(PDO::FETCH_ASSOC);
  52. if ($fetchSrc) {
  53. # 有 源数据
  54. $newData = $fetchSrc;
  55. $newData["modify_time"]=mTime();
  56. $newData["channal"]=$_data["dest"];
  57. $newData["landmark"]="";
  58. $stmt->execute($infoDest);
  59. $fetchDest = $stmt->fetch(PDO::FETCH_ASSOC);
  60. if ($fetchDest) {
  61. #有目标数据,比较时间
  62. $insert=false;
  63. if(isset($_data["compare"]) && $_data["compare"]=="auto"){
  64. if($fetchSrc["modify_time"]>$fetchDest["modify_time"]){
  65. $insert = true;
  66. }
  67. }
  68. else{
  69. $insert = true;
  70. }
  71. if($insert){
  72. #新数据 更新
  73. if($destChannelPower>=20){
  74. #有权限 直接写入
  75. $newData["id"]=$fetchDest["id"];
  76. $updateDate[] = $newData;
  77. $insertHistoray[] = $newData;
  78. }
  79. else{
  80. #pr
  81. $prData[] = $newData;
  82. }
  83. }
  84. }
  85. else{
  86. #没有目标数据新增
  87. if($destChannelPower>=20){
  88. #有写入权限 直接写入
  89. $newData["id"] = UUID::v4();
  90. $insertData[] = $newData;
  91. $insertHistoray[] = $newData;
  92. }
  93. else{
  94. #pr
  95. $prData[] = $newData;
  96. }
  97. }
  98. }
  99. }
  100. #到此,所有的数据已经准备好
  101. $sentDb = new Sent_DB();
  102. if($sentDb->update($updateDate)){
  103. $respond['update'] = count($updateDate);
  104. }
  105. else{
  106. $respond['message'] = $sentDb->getError();
  107. $respond['status'] = 1;
  108. }
  109. if($sentDb->insert($insertData)){
  110. $respond['insert'] = count($insertData);
  111. }else{
  112. $respond['message'] = $sentDb->getError();
  113. $respond['status'] = 1;
  114. }
  115. if($sentDb->send_pr($prData)){
  116. $respond['pr'] = count($prData);
  117. }else{
  118. $respond['message'] = $sentDb->getError();
  119. $respond['status'] = 1;
  120. }
  121. if($sentDb->historay($insertHistoray)){
  122. $respond['historay'] = count($insertHistoray);
  123. }else{
  124. $respond['message'] = $sentDb->getError();
  125. $respond['status'] = 1;
  126. }
  127. }
  128. else{
  129. $respond['message'] = $db_trans_sent->errorInfo();
  130. $respond['status'] = 1;
  131. }
  132. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  133. ?>