Document.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\project\controller;
  15. use app\base\BaseController;
  16. use app\project\model\ProjectDocument;
  17. use app\project\validate\DocumentCheck;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Document extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new ProjectDocument();
  31. }
  32. public function datalist()
  33. {
  34. if (request()->isAjax()) {
  35. $param = get_params();
  36. $where = array();
  37. $whereOr = array();
  38. if (!empty($param['keywords'])) {
  39. $where[] = ['title|content', 'like', '%' . $param['keywords'] . '%'];
  40. }
  41. if (!empty($param['project_id'])) {
  42. $where[] = ['project_id', '=', $param['project_id']];
  43. } else {
  44. $project_ids = Db::name('ProjectUser')->where(['uid' => $this->uid, 'delete_time' => 0])->column('project_id');
  45. $whereOr[] = ['admin_id', '=', $this->uid];
  46. $whereOr[] = ['project_id', 'in', $project_ids];
  47. }
  48. $where[] = ['delete_time', '=', 0];
  49. $list = $this->model->datalist($param,$where,$whereOr);
  50. return table_assign(0, '', $list);
  51. } else {
  52. return view();
  53. }
  54. }
  55. //添加
  56. public function add()
  57. {
  58. $param = get_params();
  59. if (request()->isPost()) {
  60. if (!empty($param['id']) && $param['id'] > 0) {
  61. $detail = $this->model->detail($param['id']);
  62. try {
  63. validate(DocumentCheck::class)->scene('edit')->check($param);
  64. } catch (ValidateException $e) {
  65. // 验证失败 输出错误信息
  66. return to_assign(1, $e->getError());
  67. }
  68. $param['update_time'] = time();
  69. $res = ProjectDocument::where('id', $param['id'])->strict(false)->field(true)->update($param);
  70. if ($res) {
  71. add_log('edit', $param['id'], $param);
  72. }
  73. return to_assign();
  74. } else {
  75. try {
  76. validate(DocumentCheck::class)->scene('add')->check($param);
  77. } catch (ValidateException $e) {
  78. // 验证失败 输出错误信息
  79. return to_assign(1, $e->getError());
  80. }
  81. $param['create_time'] = time();
  82. $param['admin_id'] = $this->uid;
  83. $sid = ProjectDocument::strict(false)->field(true)->insertGetId($param);
  84. if ($sid) {
  85. add_log('add', $sid, $param);
  86. }
  87. return to_assign();
  88. }
  89. } else {
  90. $id = isset($param['id']) ? $param['id'] : 0;
  91. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  92. if($id>0){
  93. $detail = $this->model->detail($id);
  94. if($detail['file_ids'] !=''){
  95. $file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  96. $detail['file_array'] = $file_array;
  97. }
  98. View::assign('detail', $detail);
  99. }
  100. if($project_id>0){
  101. $project_name = Db::name('Project')->where(['id' => $project_id])->value('name');
  102. View::assign('project_name', $project_name);
  103. }
  104. View::assign('project_id', $project_id);
  105. View::assign('id', $id);
  106. return view();
  107. }
  108. }
  109. //查看
  110. public function view()
  111. {
  112. $param = get_params();
  113. $id = isset($param['id']) ? $param['id'] : 0;
  114. $detail = $this->model->detail($id);
  115. if (empty($detail)) {
  116. if (empty($detail)) {
  117. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';exit;
  118. }
  119. } else {
  120. $project_ids = Db::name('ProjectUser')->where(['uid' => $this->uid, 'delete_time' => 0])->column('project_id');
  121. if (in_array($detail['project_id'], $project_ids) || ($this->uid = $detail['admin_id'])) {
  122. if($detail['file_ids'] !=''){
  123. $file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  124. $detail['file_array'] = $file_array;
  125. }
  126. View::assign('detail', $detail);
  127. if(is_mobile()){
  128. return view('qiye@/project/document_view');
  129. }
  130. return view();
  131. }
  132. else{
  133. echo '<div style="text-align:center;color:red;margin-top:20%;">您没权限查看该文档</div>';exit;
  134. }
  135. }
  136. }
  137. //删除
  138. public function delete()
  139. {
  140. if (request()->isDelete()) {
  141. $id = get_params("id");
  142. $detail = Db::name('ProjectDocument')->where('id', $id)->find();
  143. if ($detail['admin_id'] != $this->uid) {
  144. return to_assign(1, "你不是该文档的创建人,无权限删除");
  145. }
  146. if (Db::name('ProjectDocument')->where('id', $id)->update(['delete_time' => time()]) !== false) {
  147. return to_assign(0, "删除成功");
  148. } else {
  149. return to_assign(0, "删除失败");
  150. }
  151. } else {
  152. return to_assign(1, "错误的请求");
  153. }
  154. }
  155. }