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