table_article_collect.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. //header('Content-type: application/json; charset=utf8');
  3. require_once "../config.php";
  4. require_once "../public/function.php";
  5. require_once "../sync/function.php";
  6. require_once "../collect/function.php";
  7. require_once "../redis/function.php";
  8. $input = (object) [
  9. "database" => _FILE_DB_USER_ARTICLE_,
  10. "table" => "collect",
  11. "uuid" => "id",
  12. "sync_id" => ["id"],
  13. "where"=>"",
  14. "modify_time" => "modify_time",
  15. "receive_time" => "receive_time",
  16. "insert" => [
  17. 'id',
  18. 'title',
  19. 'subtitle',
  20. 'summary',
  21. 'article_list',
  22. 'status',
  23. 'owner',
  24. 'lang',
  25. 'create_time',
  26. 'modify_time',
  27. 'tag'
  28. ],
  29. "update" => [
  30. 'title',
  31. 'subtitle',
  32. 'summary',
  33. 'article_list',
  34. 'status',
  35. 'owner',
  36. 'lang',
  37. 'create_time',
  38. 'modify_time',
  39. 'tag'
  40. ]
  41. ];
  42. $output=array();
  43. $output["error"]=0;
  44. $output["message"]="";
  45. if (isset($_GET["op"])) {
  46. $op = $_GET["op"];
  47. } else if (isset($_POST["op"])) {
  48. $op = $_POST["op"];
  49. } else {
  50. $output["error"]=1;
  51. $output["message"]="无操作码";
  52. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  53. exit;
  54. }
  55. switch ($op) {
  56. case "sync_count":
  57. $result = do_sync($input);
  58. echo json_encode($result, JSON_UNESCAPED_UNICODE);
  59. break;
  60. case "sync":
  61. $result = do_sync($input);
  62. echo json_encode($result, JSON_UNESCAPED_UNICODE);
  63. break;
  64. case "get":
  65. $result = do_sync($input);
  66. echo json_encode($result, JSON_UNESCAPED_UNICODE);
  67. break;
  68. case "insert":
  69. if (isset($_POST["data"])) {
  70. $data = $_POST["data"];
  71. $arrData = json_decode($data, true);
  72. foreach ($arrData as $key => $value) {
  73. # 设置数据同步时间
  74. $arrData[$key]["receive_time"]=mTime();
  75. }
  76. $collection=new CollectInfo(redis_connect());
  77. $result = $collection->insert($arrData);
  78. if($result==false){
  79. $output["error"]=1;
  80. $output["message"]="没有提交数据";
  81. }
  82. } else {
  83. $output["error"]=1;
  84. $output["message"]=$collection->getError();
  85. }
  86. echo json_encode($result, JSON_UNESCAPED_UNICODE);
  87. break;
  88. case "update":
  89. if (isset($_POST["data"])) {
  90. $data = $_POST["data"];
  91. $arrData = json_decode($data, true);
  92. foreach ($arrData as $key => $value) {
  93. # 设置数据同步时间
  94. $arrData[$key]["receive_time"]=mTime();
  95. }
  96. $collection=new CollectInfo(redis_connect());
  97. $result = $collection->update($arrData);
  98. if($result==false){
  99. $output["error"]=1;
  100. $output["message"]="没有提交数据";
  101. }
  102. } else {
  103. $output["error"]=1;
  104. $output["message"]=$collection->getError();
  105. }
  106. echo json_encode($result, JSON_UNESCAPED_UNICODE);
  107. break;
  108. default:
  109. $output["error"]=1;
  110. $output["message"]="错误的操作码";
  111. echo json_encode($result, JSON_UNESCAPED_UNICODE);
  112. break;
  113. }
  114. ?>