table_article_collect.php 2.4 KB

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