channel.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. require_once "../config.php";
  3. require_once "../db/table.php";
  4. require_once "../public/function.php";
  5. /*
  6. CREATE TABLE likes (
  7. id INTEGER PRIMARY KEY AUTOINCREMENT,
  8. like_type VARCHAR (16) NOT NULL,
  9. resource_type VARCHAR (32) NOT NULL,
  10. resource_id CHAR (36) NOT NULL,
  11. user_id INTEGER NOT NULL,
  12. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL //只做初始化,更新时不自动更新
  13. );
  14. */
  15. class Channel extends Table
  16. {
  17. function __construct($redis=false) {
  18. parent::__construct(_FILE_DB_CHANNAL_, "channal", "", "",$redis);
  19. }
  20. public function index(){
  21. switch ($_GET["view"]) {
  22. case 'studio':
  23. # code...
  24. break;
  25. case 'user':
  26. # code...
  27. break;
  28. default:
  29. # code...
  30. break;
  31. }
  32. $where["like_type"] = "like";
  33. $where["resource_type"] = $_GET["type"];
  34. $where["resource_id"] = explode($_GET["id"],",");
  35. echo json_encode($this->_index(["id","name","lang","status"],$where), JSON_UNESCAPED_UNICODE);
  36. }
  37. public function create($data=null){
  38. if($data===null){
  39. if(!isset($_COOKIE["userid"])){
  40. return;
  41. }
  42. $json = file_get_contents('php://input');
  43. $data = json_decode($json,true);
  44. $data["owner"] = $_COOKIE["userid"];
  45. }
  46. $isExist = $this->medoo->has($this->table,["owner"=>$data["owner"],"name"=>$data["name"]]);
  47. if(!$isExist){
  48. $data["id"] = UUID::v4();
  49. $data["create_time"] = mTime();
  50. $data["modify_time"] = mTime();
  51. $result = $this->_create($data,["id","owner","lang","name","summary","status","create_time","modify_time"]);
  52. }
  53. else{
  54. $this->result["ok"]=false;
  55. $this->result["message"]="is exist";
  56. $result = $this->result;
  57. }
  58. if($data===null){
  59. echo json_encode($result, JSON_UNESCAPED_UNICODE);
  60. }else{
  61. return $result;
  62. }
  63. }
  64. public function delete(){
  65. if(!isset($_COOKIE["userid"])){
  66. return;
  67. }
  68. $where["like_type"] = $_GET["like_type"];
  69. $where["resource_type"] = $_GET["resource_type"];
  70. $where["resource_id"] = $_GET["resource_id"];
  71. $where["user_id"] = $_COOKIE["userid"];
  72. $row = $this->_delete($where);
  73. if($row["data"]>0){
  74. $this->result["data"] = $where;
  75. }else{
  76. $this->result["ok"]=false;
  77. $this->result["message"]="no delete";
  78. }
  79. echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
  80. }
  81. }
  82. ?>