channel.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /*
  3. 废弃
  4. */
  5. require_once "../config.php";
  6. require_once "../db/table.php";
  7. require_once "../public/function.php";
  8. class Channel extends Table
  9. {
  10. function __construct($redis=false) {
  11. parent::__construct(_FILE_DB_CHANNAL_, _TABLE_CHANNEL_, _DB_USERNAME_,_DB_PASSWORD_,$redis);
  12. }
  13. public function index(){
  14. switch ($_GET["view"]) {
  15. case 'studio':
  16. # code...
  17. break;
  18. case 'user':
  19. # code...
  20. break;
  21. default:
  22. # code...
  23. break;
  24. }
  25. $where["like_type"] = "like";
  26. $where["resource_type"] = $_GET["type"];
  27. $where["resource_id"] = explode($_GET["id"],",");
  28. echo json_encode($this->_index(["id","name","lang","status"],$where), JSON_UNESCAPED_UNICODE);
  29. }
  30. public function create($data=null){
  31. if($data===null){
  32. if(!isset($_COOKIE["userid"])){
  33. return;
  34. }
  35. $json = file_get_contents('php://input');
  36. $data = json_decode($json,true);
  37. $data["owner_uid"] = $_COOKIE["user_uid"];
  38. $data["editor_id"] = $_COOKIE["user_id"];
  39. }
  40. $isExist = $this->medoo->has($this->table,["owner_uid"=>$data["owner_uid"],"name"=>$data["name"]]);
  41. if(!$isExist){
  42. $data["id"] = $this->SnowFlake->id();
  43. $data["uid"] = UUID::v4();
  44. $data["create_time"] = mTime();
  45. $data["modify_time"] = mTime();
  46. $result = $this->_create($data,["id","uid","owner_uid",'editor_id',"lang","name","summary","status","create_time","modify_time"]);
  47. }
  48. else{
  49. $this->result["ok"]=false;
  50. $this->result["message"]="is exist";
  51. $result = $this->result;
  52. }
  53. if($data===null){
  54. echo json_encode($result, JSON_UNESCAPED_UNICODE);
  55. }else{
  56. return $result;
  57. }
  58. }
  59. public function delete(){
  60. if(!isset($_COOKIE["userid"])){
  61. return;
  62. }
  63. $where["like_type"] = $_GET["like_type"];
  64. $where["resource_type"] = $_GET["resource_type"];
  65. $where["resource_id"] = $_GET["resource_id"];
  66. $where["user_id"] = $_COOKIE["userid"];
  67. $row = $this->_delete($where);
  68. if($row["data"]>0){
  69. $this->result["data"] = $where;
  70. }else{
  71. $this->result["ok"]=false;
  72. $this->result["message"]="no delete";
  73. }
  74. echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
  75. }
  76. }
  77. ?>