From 0842290991950d005fb692c5fa25e06c1f0d35e7 Mon Sep 17 00:00:00 2001 From: vilson <545522390@qq.com> Date: Thu, 24 Jan 2019 15:25:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=8C=E6=88=90=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=83=85=E6=99=AF=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: vilson <545522390@qq.com> --- application/common/Model/Task.php | 36 ++++++++++++++++++++++++- application/project/controller/Task.php | 2 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/application/common/Model/Task.php b/application/common/Model/Task.php index d70e4a6..aeaecc7 100644 --- a/application/common/Model/Task.php +++ b/application/common/Model/Task.php @@ -14,7 +14,7 @@ use think\facade\Hook; */ class Task extends CommonModel { - protected $append = ['priText', 'liked', 'stared', 'childCount', 'hasComment', 'hasSource', 'canRead']; + protected $append = ['priText', 'liked', 'stared', 'childCount', 'hasUnDone', 'parentDone', 'hasComment', 'hasSource', 'canRead']; public function read($code) { @@ -213,6 +213,9 @@ class Task extends CommonModel if ($parentTask['deleted']) { throw new \Exception('父任务在回收站中无法编辑', 6); } + if ($parentTask['done']) { + throw new \Exception('父任务已完成,无法添加新的子任务', 7); + } } if ($assignTo) { $assignMember = Member::where(['code' => $assignTo])->field('id')->find(); @@ -285,6 +288,13 @@ class Task extends CommonModel if ($task['deleted']) { throw new \Exception('任务在回收站中无法进行编辑', 3); } + if ($task['parentDone']) { + throw new \Exception('父任务已完成,无法重做子任务', 4); + } + if ($task['hasUnDone']) { + throw new \Exception('子任务尚未全部完成,无法完成父任务', 5); + } + Db::startTrans(); try { $result = self::update(['done' => $done], ['code' => $taskCode]); @@ -523,6 +533,30 @@ class Task extends CommonModel return $childTasks; } + public function getParentDoneAttr($value, $data) + { + $done = 1; + if (isset($data['code']) && isset($data['pcode']) && $data['pcode']) { + $task = self::where(['code' => $data['pcode']])->field('done')->find(); + if ($task && !$task['done']) { + $done = 0; + } + } + return $done; + } + + public function getHasUnDoneAttr($value, $data) + { + $hasUnDone = 0; + if (isset($data['code'])) { + $taskCount = self::where(['pcode' => $data['code'], 'done' => 0])->count('id'); + if ($taskCount) { + $hasUnDone = 1; + } + } + return $hasUnDone; + } + public function getHasCommentAttr($value, $data) { $comment = 0; diff --git a/application/project/controller/Task.php b/application/project/controller/Task.php index de61f49..f17d483 100644 --- a/application/project/controller/Task.php +++ b/application/project/controller/Task.php @@ -116,8 +116,8 @@ class Task extends BasicApi public function read(Request $request) { + //todo 隐私模式阅读权限 $data = $request::only('taskCode'); - try { $result = $this->model->read($data['taskCode']); } catch (\Exception $e) {