Comment.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 评论
  4. // +----------------------------------------------------------------------
  5. // | Author: yykun
  6. // +----------------------------------------------------------------------
  7. namespace app\admin\controller;
  8. use think\Request;
  9. use think\Session;
  10. use think\Hook;
  11. use app\common\controller\Common;
  12. class Comment extends Common
  13. {
  14. /**
  15. * 用于判断权限
  16. * @permission 无限制
  17. * @allow 登录用户可访问
  18. * @other 其他根据系统设置
  19. **/
  20. public function _initialize()
  21. {
  22. $action = [
  23. 'permission'=>[''], //不登录可访问
  24. 'allow'=>['save','delete'] //需要登录才能访问
  25. ];
  26. Hook::listen('check_auth',$action);
  27. $request = Request::instance();
  28. $a = strtolower($request->action());
  29. $c = strtolower($request->controller());
  30. $m = strtolower($request->module());
  31. if (!in_array($a, $action['permission'])) {
  32. parent::_initialize();
  33. }
  34. }
  35. //添加评论
  36. public function save()
  37. {
  38. $param = $this->param;
  39. $model = model('Comment');
  40. if ($param['task_id']) {
  41. $userInfo = $this->userInfo;
  42. $param['create_user_id'] = $userInfo['id'];
  43. $flag = $model->createData($param);
  44. if ($flag) {
  45. return resultArray(['data'=>$flag]);
  46. } else {
  47. return resultArray(['error'=>$workModel->getError()]);
  48. }
  49. } else {
  50. return resultArray(['error'=>'参数错误']);
  51. }
  52. }
  53. //删除评论
  54. public function delete()
  55. {
  56. $param = $this->param;
  57. $commentModel = model('Comment');
  58. if ($param['comment_id']) {
  59. $userInfo = $this->userInfo;
  60. $param['create_user_id'] = $userInfo['id'];
  61. $flag = $commentModel->delDataById($param);
  62. if ($flag) {
  63. return resultArray(['data'=>'删除成功']);
  64. } else {
  65. return resultArray(['error'=>$commentModel->getError()]);
  66. }
  67. } else {
  68. return resultArray(['error'=>'参数错误']);
  69. }
  70. }
  71. }