table_article_collect.php 2.4 KB

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