diff --git a/app/Http/Controllers/Api/ProjectController.php b/app/Http/Controllers/Api/ProjectController.php
index 3a61680ad..a625675e3 100755
--- a/app/Http/Controllers/Api/ProjectController.php
+++ b/app/Http/Controllers/Api/ProjectController.php
@@ -642,14 +642,14 @@ class ProjectController extends AbstractController
/**
* {post} 添加任务
*
- * @apiParam {Number} project_id 项目ID
- * @apiParam {Number} [column_id] 列表ID,留空取第一个
- * @apiParam {String} name 任务描述
- * @apiParam {String} [content] 任务详情
- * @apiParam {Array} [times] 计划时间(格式:开始时间,结束时间;如:2020-01-01 00:00,2020-01-01 23:59)
- * @apiParam {Number} [owner] 负责人,留空为自己
- * @apiParam {Array} [subtasks] 子任务(格式:[{name,owner,times}])
- * @apiParam {Number} [top] 添加的任务排到列表最前面
+ * @apiParam {Number} project_id 项目ID
+ * @apiParam {mixed} [column_id] 列表ID,任意值自动创建,留空取第一个
+ * @apiParam {String} name 任务描述
+ * @apiParam {String} [content] 任务详情
+ * @apiParam {Array} [times] 计划时间(格式:开始时间,结束时间;如:2020-01-01 00:00,2020-01-01 23:59)
+ * @apiParam {mixed} [owner] 负责人,留空为自己
+ * @apiParam {Array} [subtasks] 子任务(格式:[{name,owner,times}])
+ * @apiParam {Number} [top] 添加的任务排到列表最前面
*/
public function task__add()
{
@@ -724,12 +724,14 @@ class ProjectController extends AbstractController
/**
* {post} 修改任务、子任务
*
- * @apiParam {Number} task_id 任务ID
- * @apiParam {String} [name] 任务描述
- * @apiParam {String} [color] 任务描述(子任务不支持)
- * @apiParam {String} [content] 任务详情(子任务不支持)
- * @apiParam {Array} [times] 计划时间(格式:开始时间,结束时间;如:2020-01-01 00:00,2020-01-01 23:59)
- * @apiParam {Number} [owner] 修改负责人
+ * @apiParam {Number} task_id 任务ID
+ * @apiParam {String} [name] 任务描述
+ * @apiParam {String} [color] 任务描述(子任务不支持)
+ * @apiParam {String} [content] 任务详情(子任务不支持)
+ * @apiParam {Array} [times] 计划时间(格式:开始时间,结束时间;如:2020-01-01 00:00,2020-01-01 23:59)
+ * @apiParam {mixed} [owner] 修改负责人
+ *
+ * @apiParam {String|false} [complete_at] 完成时间(如:2020-01-01 00:00,false表示未完成)
*/
public function task__update()
{
@@ -746,6 +748,7 @@ class ProjectController extends AbstractController
$content = Base::getPostValue('content');
$times = Base::getPostValue('times');
$owner = Base::getPostValue('owner');
+ $complete_at = Base::getPostValue('complete_at');
// 任务
$task = ProjectTask::whereId($task_id)->first();
if (empty($task)) {
@@ -761,15 +764,30 @@ class ProjectController extends AbstractController
return Base::retError('项目不存在或不在成员列表内');
}
//
- $result = $task->updateTask([
- 'name' => $name,
- 'color' => $color,
- 'content' => $content,
- 'times' => $times,
- 'owner' => $owner,
- ]);
+ if ($complete_at === false || $complete_at === "false") {
+ // 标记未完成
+ if (!$task->complete_at) {
+ return Base::retError('未完成任务');
+ }
+ $result = $task->completeTask(null);
+ } elseif (Base::isDate($complete_at)) {
+ // 标记已完成
+ if ($task->complete_at) {
+ return Base::retError('任务已完成');
+ }
+ $result = $task->completeTask(Carbon::now());
+ } else {
+ // 更新任务
+ $result = $task->updateTask([
+ 'name' => $name,
+ 'color' => $color,
+ 'content' => $content,
+ 'times' => $times,
+ 'owner' => $owner,
+ ]);
+ }
if (Base::isSuccess($result)) {
- $result['data'] = ProjectTask::with(['taskUser', 'taskTag'])->whereId($task->id)->first();
+ $result['data'] = $task->toArray();
}
return $result;
}
diff --git a/app/Models/ProjectTask.php b/app/Models/ProjectTask.php
index 92c5361c1..3bf53693e 100644
--- a/app/Models/ProjectTask.php
+++ b/app/Models/ProjectTask.php
@@ -310,10 +310,35 @@ class ProjectTask extends AbstractModel
});
}
+ /**
+ * 标记已完成、未完成
+ * @param Carbon|null $complete_at 完成时间
+ * @return array|bool
+ */
+ public function completeTask($complete_at)
+ {
+ return AbstractModel::transaction(function () use ($complete_at) {
+ if ($complete_at === null) {
+ // 标记未完成
+ $this->complete_at = null;
+ } else {
+ // 标记已完成
+ if ($this->parent_id == 0) {
+ if (self::whereParentId($this->id)->whereCompleteAt(null)->exists()) {
+ return Base::retError('子任务未完成');
+ }
+ }
+ $this->complete_at = $complete_at;
+ }
+ $this->save();
+ return Base::retSuccess('修改成功');
+ });
+ }
+
/**
* 修改任务
* @param $params
- * @return array|bool
+ * @return array
*/
public function updateTask($params)
{
diff --git a/app/Module/Base.php b/app/Module/Base.php
index dc9f636c6..77c41b6da 100755
--- a/app/Module/Base.php
+++ b/app/Module/Base.php
@@ -1947,15 +1947,25 @@ class Base
return $_A["__static_input_content"][$key] ?? $default;
}
+ /**
+ * @param $key
+ * @param null $default
+ * @return array|mixed|string|null
+ */
public static function getPostValue($key, $default = null)
{
- $value = self::newTrim(self::getContentValue($key, $default));
+ $value = self::getContentValue($key, $default);
if (empty($value)) {
- $value = self::newTrim(Request::post($key, $default));
+ $value = Request::post($key, $default);
}
return $value;
}
+ /**
+ * @param $key
+ * @param null $default
+ * @return int
+ */
public static function getPostInt($key, $default = null)
{
return intval(self::getPostValue($key, $default));
diff --git a/resources/assets/js/pages/manage/components/ProjectList.vue b/resources/assets/js/pages/manage/components/ProjectList.vue
index a05526bf7..757d41be9 100644
--- a/resources/assets/js/pages/manage/components/ProjectList.vue
+++ b/resources/assets/js/pages/manage/components/ProjectList.vue
@@ -133,9 +133,14 @@
@command="dropTask(item, $event)">