Comment.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\newhome\controller;
  3. use think\Controller;
  4. use app\user\model\UserComment;
  5. class Comment extends Controller {
  6. private $commentModel;
  7. public function _initialize(){
  8. parent::_initialize();
  9. $this->commentModel = new UserComment();
  10. }
  11. public function index(){
  12. $data = decode($this->request->post());
  13. $user = $data['u'];
  14. $page = $data['p'];
  15. $type = $data['t'];
  16. $info = $this->commentModel->getInfo($user, $type, $page);
  17. return json(["l"=>$info]);
  18. }
  19. public function find(){
  20. $data = decode($this->request->post());
  21. $user = $data['u'];
  22. $comment = $data['c'];
  23. $page = $data['p'];
  24. $type = $data['t'];
  25. $info = $this->commentModel->getInfoByComment($user, $comment, $type, $page);
  26. return json(["l"=>$info]);
  27. }
  28. public function comment(){
  29. $data = decode($this->request->post());
  30. $user = $data['u'];
  31. $comment = $data['c'];
  32. $content = $data['i'];
  33. $type = $data['t'];
  34. $data = ['id'=>getId(), 'user_id'=>$user, 'comment_id'=>$comment, 'content'=>$content, 'type'=>$type];
  35. $this->commentModel->add($data);
  36. return json(['error'=>0]);
  37. }
  38. }