table_article_collect.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. "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":
  57. $result = do_sync($input);
  58. echo json_encode($result, JSON_UNESCAPED_UNICODE);
  59. break;
  60. case "get":
  61. $result = do_sync($input);
  62. echo json_encode($result, JSON_UNESCAPED_UNICODE);
  63. break;
  64. case "insert":
  65. if (isset($_POST["data"])) {
  66. $data = $_POST["data"];
  67. $arrData = json_decode($data, true);
  68. foreach ($arrData as $key => $value) {
  69. # 设置数据同步时间
  70. $arrData[$key]["receive_time"]=mTime();
  71. }
  72. $collection=new CollectInfo(redis_connect());
  73. $result = $collection->insert($arrData);
  74. if($result==false){
  75. $output["error"]=1;
  76. $output["message"]="没有提交数据";
  77. }
  78. } else {
  79. $output["error"]=1;
  80. $output["message"]=$collection->getError();
  81. }
  82. echo json_encode($result, JSON_UNESCAPED_UNICODE);
  83. break;
  84. case "update":
  85. if (isset($_POST["data"])) {
  86. $data = $_POST["data"];
  87. $arrData = json_decode($data, true);
  88. foreach ($arrData as $key => $value) {
  89. # 设置数据同步时间
  90. $arrData[$key]["receive_time"]=mTime();
  91. }
  92. $collection=new CollectInfo(redis_connect());
  93. $result = $collection->update($arrData);
  94. if($result==false){
  95. $output["error"]=1;
  96. $output["message"]="没有提交数据";
  97. }
  98. } else {
  99. $output["error"]=1;
  100. $output["message"]=$collection->getError();
  101. }
  102. echo json_encode($result, JSON_UNESCAPED_UNICODE);
  103. break;
  104. }
  105. ?>