diff --git a/application/common/Model/Task.php b/application/common/Model/Task.php index 1652f81..a392c37 100644 --- a/application/common/Model/Task.php +++ b/application/common/Model/Task.php @@ -124,6 +124,9 @@ class Task extends CommonModel $type = 'clearEndTime'; } } + if (isset($data['work_time'])) { + $type = 'setWorkTime'; + } $type && self::taskHook($member['code'], $code, $type); //TODO 任务动态 return $result; diff --git a/application/common/Model/TaskWorkTime.php b/application/common/Model/TaskWorkTime.php new file mode 100644 index 0000000..b2c2ca0 --- /dev/null +++ b/application/common/Model/TaskWorkTime.php @@ -0,0 +1,62 @@ + $taskCode, 'deleted' => 0])->field('id')->find(); + if (!$task) { + return error(2, '该任务已失效'); + } + if (!$memberCode) { + return error(3, '请指定成员'); + } + if (!$beginTime) { + return error(4, '请选择开始时间'); + } + if (!$num || !is_numeric($num)) { + return error(5, '请输入有效工时'); + } + $data = [ + 'create_time' => nowTime(), + 'code' => createUniqueCode('TaskWorkTime'), + 'task_code' => $taskCode, + 'num' => $num, + 'content' => $content, + 'begin_time' => $beginTime, + 'member_code' => $memberCode, + ]; + $result = self::create($data)->toArray(); + return $result; + } + + +} diff --git a/application/project/behavior/Task.php b/application/project/behavior/Task.php index 5088092..750ad37 100644 --- a/application/project/behavior/Task.php +++ b/application/project/behavior/Task.php @@ -156,6 +156,10 @@ class Task $icon = 'undo'; $remark = '恢复了任务 '; break; + case 'setWorkTime': + $icon = 'clock-circle'; + $remark = '更新预估工时为 ' .$task['work_time']; + break; case 'linkFile': $icon = 'link'; $remark = '关联了文件 '; diff --git a/application/project/controller/Project.php b/application/project/controller/Project.php index 82506fc..048746a 100644 --- a/application/project/controller/Project.php +++ b/application/project/controller/Project.php @@ -7,6 +7,7 @@ use app\common\Model\Member; use app\common\Model\MemberAccount; use app\common\Model\Notify; use app\common\Model\ProjectCollection; +use app\common\Model\ProjectLog; use app\common\Model\ProjectMember; use app\common\Model\SystemConfig; use controller\BasicApi; @@ -212,7 +213,7 @@ class Project extends BasicApi */ public function edit(Request $request) { - $data = $request::only('name,description,cover,private,prefix,open_prefix,schedule,open_begin_time,open_task_private,task_board_theme'); + $data = $request::only('name,description,cover,private,prefix,open_prefix,schedule,open_begin_time,open_task_private,task_board_theme,begin_time,end_time'); $code = $request::param('projectCode'); try { $result = $this->model->edit($code, $data); @@ -286,6 +287,60 @@ class Project extends BasicApi $this->success('', $list); } + /** + * 概览报表 + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function _projectStats() + { + $projectCode = Request::param('projectCode'); + if (!$projectCode) { + $this->error('项目已失效'); + } + $project = \app\common\Model\Project::where(['code' => $projectCode])->find(); + if (!$project) { + $this->error('项目已失效'); + } + $taskStats = [ + 'total' => 0, + 'unDone' => 0, + 'done' => 0, + 'overdue' => 0, + 'toBeAssign' => 0, + 'expireToday' => 0, + 'doneOverdue' => 0, + ]; + $taskList = \app\common\Model\Task::where(['project_code' => $projectCode, 'deleted' => 0])->select()->toArray(); + $taskStats['total'] = count($taskList); + if ($taskList) { + $today = date('Y-m-d 00:00', time()); + $tomorrow = date('Y-m-d 00:00', strtotime($today) + 3600 * 24); + foreach ($taskList as $item) { + !$item['assign_to'] && $taskStats['toBeAssign']++; + $item['done'] && $taskStats['done']++; + !$item['done'] && $taskStats['unDone']++; + if ($item['end_time']) { + if (!$item['done']) { + $item['end_time'] < nowTime() && $taskStats['overdue']++; + if ($item['end_time'] >= $today && $item['end_time'] < $tomorrow) { + $taskStats['doneOverdue']++; + } + } else { + $log = ProjectLog::where(['action_type' => 'task', 'source_code' => $item['code'], 'type' => 'done'])->order('id desc')->find(); + if ($log && $log['create_time'] > $item['end_time']) { + $taskStats['doneOverdue']++; + } + } + } + + } + } + + $this->success('', $taskStats); + } + /** * 上传封面 */ diff --git a/application/project/controller/Task.php b/application/project/controller/Task.php index 5deba29..1347c99 100644 --- a/application/project/controller/Task.php +++ b/application/project/controller/Task.php @@ -7,6 +7,7 @@ use app\common\Model\Member; use app\common\Model\ProjectLog; use app\common\Model\TaskTag; use app\common\Model\TaskToTag; +use app\common\Model\TaskWorkTime; use controller\BasicApi; use Exception; use think\db\exception\DataNotFoundException; @@ -287,7 +288,7 @@ class Task extends BasicApi */ public function edit(Request $request) { - $data = $request::only('name,sort,end_time,begin_time,pri,description'); + $data = $request::only('name,sort,end_time,begin_time,pri,description,work_time'); $code = $request::post('taskCode'); if (!$code) { $this->error("请选择一个任务"); @@ -463,6 +464,60 @@ class Task extends BasicApi $this->success('', $list); } + public function _taskWorkTimeList() + { + $taskCode = Request::param('taskCode'); + $workTimeList = TaskWorkTime::where(['task_code' => $taskCode])->select()->toArray(); + if ($workTimeList) { + foreach ($workTimeList as &$workTime) { + $member = Member::where(['code' => $workTime['member_code']])->field('avatar,name')->find(); + $workTime['member'] = $member; + } + } + $this->success('', $workTimeList); + } + + public function saveTaskWorkTime() + { + $param = Request::only('beginTime,num,content,taskCode'); + $result = TaskWorkTime::createData($param['taskCode'], getCurrentMember()['code'], $param['num'], $param['beginTime'], $param['content']); + if (isError($result)) { + $this->error($result['msg'], $result['errno']); + } + $this->success(); + } + + public function editTaskWorkTime() + { + $param = Request::only('beginTime,num,content'); + $code = Request::param('code'); + if ($code) { + $workTime = TaskWorkTime::where(['code' => $code])->find(); + if (!$workTime) { + return error(1, '该记录已失效'); + } + } + if (isset($param['beginTime'])) { + $param['begin_time'] = $param['beginTime']; + unset($param['beginTime']); + } + $result = TaskWorkTime::update($param, ['code' => $code]); + $this->success(); + } + + public function delTaskWorkTime() + { + $code = Request::param('code'); + if ($code) { + $workTime = TaskWorkTime::where(['code' => $code])->find(); + if (!$workTime) { + return error(1, '该记录已失效'); + } + } + $result = TaskWorkTime::destroy(['code' => $code]); + $this->success(); + } + /** * 下载导入任务模板 @@ -478,7 +533,7 @@ class Task extends BasicApi public function uploadFile() { $projectCode = Request::param('projectCode'); - $count = $this->model->uploadFile(Request::file('file'), $projectCode,getCurrentMember()['code']); + $count = $this->model->uploadFile(Request::file('file'), $projectCode, getCurrentMember()['code']); if (isError($count)) { $this->error($count['msg']); } diff --git a/route/demo.php b/route/demo.php index 931d882..e69de29 100644 --- a/route/demo.php +++ b/route/demo.php @@ -1,20 +0,0 @@ - 404, 'msg' => '演示环境禁修改菜单权限!']); -}); -Route::post('project/menu/menuEdit', function () { - return json(['code' => 404, 'msg' => '演示环境禁修改菜单权限!']); -}); -Route::post('project/menu/menuDel', function () { - return json(['code' => 404, 'msg' => '演示环境禁修改菜单权限!']); -}); -Route::post('project/index/editPassword', function () { - return json(['code' => 404, 'msg' => '演示环境禁修改密码!']); -}); -//Route::post('project/account/del', function () { -// return json(['code' => 404, 'msg' => '演示环境禁修改账号!']); -//}); -return [];