Task.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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\ProjectTask;
  17. use app\api\model\Comment;
  18. use app\oa\model\Schedule;
  19. use app\api\model\EditLog;
  20. use app\project\validate\TaskCheck;
  21. use think\exception\ValidateException;
  22. use think\facade\Db;
  23. use think\facade\View;
  24. class Task extends BaseController
  25. {
  26. /**
  27. * 构造函数
  28. */
  29. protected $model;
  30. public function __construct()
  31. {
  32. parent::__construct(); // 调用父类构造函数
  33. $this->model = new ProjectTask();
  34. }
  35. /**
  36. * 数据列表
  37. */
  38. public function datalist()
  39. {
  40. $param = get_params();
  41. $uid = $this->uid;
  42. $auth = isAuth($uid,'project_admin','conf_1');
  43. if (request()->isAjax()) {
  44. $tab = isset($param['tab']) ? $param['tab'] : 0;
  45. $time = time();
  46. $time = time();
  47. $dalay_time = time()+7*86400;
  48. $where = [];
  49. $whereOr = [];
  50. $where[] = ['delete_time', '=', 0];
  51. if (!empty($param['status'])) {
  52. $where[] = ['status', '=', $param['status']];
  53. }
  54. if (!empty($param['priority'])) {
  55. $where[] = ['priority', '=', $param['priority']];
  56. }
  57. if (!empty($param['work_id'])) {
  58. $where[] = ['work_id', '=', $param['work_id']];
  59. }
  60. if (!empty($param['keywords'])) {
  61. $where[] = ['title|content', 'like', '%' . $param['keywords'] . '%'];
  62. }
  63. if(!empty($param['project_id'])){
  64. $where[] = ['project_id', '=', $param['project_id']];
  65. }
  66. if (!empty($param['director_uid'])) {
  67. $where[] = ['director_uid', 'in', $param['director_uid']];
  68. }
  69. else{
  70. if($auth == 0){
  71. $whereOr[] = ['admin_id', '=', $uid];
  72. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',assist_admin_ids)")];
  73. $dids_a = get_leader_departments($uid);
  74. $dids_b = get_role_departments($uid);
  75. $dids = array_merge($dids_a, $dids_b);
  76. if(!empty($dids)){
  77. $whereOr[] = ['did','in',$dids];
  78. }
  79. if (empty($param['director_uid'])) {
  80. $whereOr[] = ['director_uid', '=', $uid];
  81. }
  82. }
  83. }
  84. if($tab==1){
  85. //进行中
  86. $where[] = ['status', '<', 3];
  87. }
  88. if($tab==2){
  89. //即将逾期
  90. $where[] = ['status', '<', 3];
  91. $where[] = ['end_time','between',[$time,$dalay_time]];
  92. }
  93. if($tab==3){
  94. //已逾期
  95. $where[] = ['status', '<', 3];
  96. $where[] = ['end_time','<',$time];
  97. }
  98. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  99. $order = empty($param['order']) ? 'status asc,id desc' : $param['order'];
  100. $list = $this->model->datalist($param,$where,$whereOr);
  101. return table_assign(0, '', $list);
  102. }
  103. else{
  104. View::assign('auth', $auth);
  105. return view();
  106. }
  107. }
  108. //添加
  109. public function add()
  110. {
  111. $param = get_params();
  112. if (request()->isPost()) {
  113. if (isset($param['end_time'])) {
  114. $param['end_time'] = strtotime(urldecode($param['end_time']));
  115. }
  116. if (isset($param['status'])) {
  117. if ($param['status'] == 3) {
  118. $param['over_time'] = time();
  119. $param['done_ratio'] = 100;
  120. } else {
  121. $param['over_time'] = 0;
  122. $param['done_ratio'] = 10;
  123. }
  124. }
  125. if (!empty($param['id']) && $param['id'] > 0) {
  126. $old = $this->model->detail($param['id']);
  127. try {
  128. validate(TaskCheck::class)->scene('edit')->check($param);
  129. } catch (ValidateException $e) {
  130. // 验证失败 输出错误信息
  131. return to_assign(1, $e->getError());
  132. }
  133. $param['update_time'] = time();
  134. if(!empty($param['director_uid'])){
  135. $param['did'] = Db::name('Admin')->where(['id' => $param['director_uid']])->value('did');
  136. }
  137. $res = ProjectTask::where('id', $param['id'])->strict(false)->field(true)->update($param);
  138. if ($res) {
  139. add_log('edit', $param['id'], $param);
  140. $log=new EditLog();
  141. $log->edit('Task',$param['id'],$param,$old);
  142. }
  143. return to_assign();
  144. } else {
  145. try {
  146. validate(TaskCheck::class)->scene('add')->check($param);
  147. } catch (ValidateException $e) {
  148. // 验证失败 输出错误信息
  149. return to_assign(1, $e->getError());
  150. }
  151. $param['create_time'] = time();
  152. $param['admin_id'] = $this->uid;
  153. if(empty($param['director_uid'])){
  154. $param['did'] = $this->did;
  155. }
  156. else{
  157. $param['did'] = Db::name('Admin')->where(['id' => $param['director_uid']])->value('did');
  158. }
  159. $insertId = ProjectTask::strict(false)->field(true)->insertGetId($param);
  160. if ($insertId) {
  161. add_log('add', $insertId, $param);
  162. $log=new EditLog();
  163. $log->add('Task',$insertId);
  164. //发消息
  165. //event('SendMessage',$msg);
  166. }
  167. return to_assign();
  168. }
  169. } else {
  170. if (isset($param['project_id'])) {
  171. View::assign('project_id', $param['project_id']);
  172. }
  173. return view();
  174. }
  175. }
  176. //查看
  177. public function view()
  178. {
  179. $param = get_params();
  180. $id = isset($param['id']) ? $param['id'] : 0;
  181. $detail = (new ProjectTask())->detail($id);
  182. $role_uid = [$detail['admin_id'], $detail['director_uid']];
  183. $role_edit = 'view';
  184. if (in_array($this->uid, $role_uid)) {
  185. $role_edit = 'edit';
  186. }
  187. $project_ids = Db::name('ProjectUser')->where(['uid' => $this->uid, 'delete_time' => 0])->column('project_id');
  188. $auth = isAuth($this->uid,'project_admin','conf_1');
  189. if (in_array($detail['project_id'], $project_ids) || in_array($this->uid, $role_uid) || in_array($this->uid, explode(",",$detail['assist_admin_ids'])) || $auth==1) {
  190. $file_array = Db::name('ProjectFile')
  191. ->field('mf.id,mf.topic_id,mf.admin_id,mf.file_id,f.name,f.filesize,f.filepath,f.fileext,f.create_time,f.admin_id,a.name as admin_name')
  192. ->alias('mf')
  193. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  194. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  195. ->order('mf.create_time desc')
  196. ->where(array('mf.topic_id' => $id, 'mf.module' => 'task'))
  197. ->select()->toArray();
  198. View::assign('detail', $detail);
  199. View::assign('file_array', $file_array);
  200. View::assign('role_edit', $role_edit);
  201. View::assign('id', $id);
  202. if(is_mobile()){
  203. return view('qiye@/project/task_view');
  204. }
  205. return view();
  206. }
  207. else{
  208. return view(EEEOR_REPORTING,['code'=>405,'warning'=>'无权限访问']);
  209. }
  210. }
  211. //删除
  212. public function del()
  213. {
  214. if (request()->isDelete()) {
  215. $id = get_params("id");
  216. $auth = isAuth($this->uid,'project_admin','conf_1');
  217. $detail = Db::name('ProjectTask')->where('id', $id)->find();
  218. if ($detail['admin_id'] != $this->uid && $auth==0) {
  219. return to_assign(1, "你不是该任务的创建人,无权限删除");
  220. }
  221. $hour = Db::name('Schedule')->where(['tid' => $id,'delete_time' => 0])->count();
  222. if($hour>0){
  223. return to_assign(1, "已有工作日志的任务不支持删除");
  224. }
  225. if (Db::name('ProjectTask')->where('id', $id)->update(['delete_time' => time()]) !== false) {
  226. return to_assign(0, "删除成功");
  227. } else {
  228. return to_assign(0, "删除失败");
  229. }
  230. } else {
  231. return to_assign(1, "错误的请求");
  232. }
  233. }
  234. public function hour() {
  235. if (request()->isAjax()) {
  236. $param = get_params();
  237. $uid = $this->uid;
  238. $auth = isAuth($uid,'project_admin','conf_1');
  239. $tid = isset($param['tid']) ? $param['tid'] : 0;
  240. $where = [];
  241. $whereOr = [];
  242. //按时间检索
  243. if (!empty($param['range_time'])) {
  244. $range_time =explode('至', $param['range_time']);
  245. $where[] = ['a.start_time', 'between',[strtotime($range_time[0]),strtotime($range_time[1])]];
  246. }
  247. if ($tid>0) {
  248. $task_ids = Db::name('ProjectTask')->where(['delete_time' => 0, 'project_id' => $param['tid']])->column('id');
  249. $where[] = ['a.tid', 'in', $task_ids];
  250. }
  251. else{
  252. $where[] = ['a.tid', '>', 0];
  253. if (!empty($param['keywords'])) {
  254. $where[] = ['a.title', 'like', '%' . trim($param['keywords']) . '%'];
  255. }
  256. if($auth == 0){
  257. if (!empty($param['uid'])) {
  258. $where[] = ['a.admin_id', '=', $param['uid']];
  259. } else {
  260. $whereOr[] = ['a.admin_id', '=', $uid];
  261. $dids_a = get_leader_departments($uid);
  262. $dids_b = get_role_departments($uid);
  263. $dids = array_merge($dids_a, $dids_b);
  264. if(!empty($dids)){
  265. $whereOr[] = ['a.did','in',$dids];
  266. }
  267. }
  268. }
  269. }
  270. $where[] = ['a.delete_time', '=', 0];
  271. $model = new Schedule();
  272. $list = $model->datalist($param,$where,$whereOr);
  273. return table_assign(0, '', $list);
  274. } else {
  275. View::assign('is_leader', isLeader($this->uid));
  276. View::assign('role_auth', isAuth($this->uid,'office_admin','conf_1'));
  277. View::assign('hour_auth', valueAuth('office_admin','conf_2'));
  278. return view();
  279. }
  280. }
  281. public function comment() {
  282. if (request()->isAjax()) {
  283. $param = get_params();
  284. $param['admin_id'] = $this->uid;
  285. if (!empty($param['uid'])) {
  286. $where[] = ['admin_id', '=', $param['uid']];
  287. }
  288. if (!empty($param['keywords'])) {
  289. $where[] = ['content', 'like', '%' . trim($param['keywords']) . '%'];
  290. }
  291. if (!empty($param['module'])) {
  292. $where[] = ['module', '=', $param['module']];
  293. }
  294. if (!empty($param['topic_id'])) {
  295. $where['topic_id'] = $param['topic_id'];
  296. }
  297. $where[] = ['delete_time', '=', 0];
  298. $model = new Comment();
  299. $list = $model->datalist($param,$where);
  300. return table_assign(0, '', $list);
  301. } else {
  302. return view();
  303. }
  304. }
  305. }