Comment.php 894 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\home\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 comment(){
  20. $data = decode($this->request->post());
  21. $user = $data['u'];
  22. $comment = $data['c'];
  23. $content = $data['i'];
  24. $type = $data['t'];
  25. $data = ['id'=>getId(), 'user_id'=>$user, 'comment_id'=>$comment, 'content'=>$content, 'type'=>$type];
  26. $this->commentModel->add($data);
  27. return json(['error'=>0]);
  28. }
  29. }