From 7a3b89624ceced061e363e2b8397306276f78a79 Mon Sep 17 00:00:00 2001 From: vilson <545522390@qq.com> Date: Fri, 21 Feb 2020 08:25:03 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=87=83=E5=B0=BD=E5=9B=BE?= 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/ProjectReport.php | 44 ++++++++++++++++++++++ application/project/controller/Project.php | 31 +++++++++++---- 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/application/common/Model/ProjectReport.php b/application/common/Model/ProjectReport.php index 46dc2e6..c902eed 100644 --- a/application/common/Model/ProjectReport.php +++ b/application/common/Model/ProjectReport.php @@ -17,6 +17,50 @@ class ProjectReport extends CommonModel protected $append = []; protected $json = ['content']; + /** + * 计算最近n天的数据 + * @param string $projectCode 项目code + * @param int $day 近n天 + * @return array + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public static function getReportByDay($projectCode, $day = 10) + { + $dateList = []; + $taskList = []; + $undoneTaskList = []; + $baseLineList = []; + $max = 0; + for ($i = $day; $i >= 1; $i--) { + $date = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") - $i, date("Y"))); + $dateFormat = date('m-d', strtotime($date)); + $dateList[] = $dateFormat; + $report = ProjectReport::where(['project_code' => $projectCode, 'date' => $date])->find(); + if ($report) { + $task = get_object_vars($report['content']); + $taskList[] = $task['task']; + $undoneTaskList[] = $task['task:undone']; + if ($task['task:undone'] > $max) { + $max = $task['task:undone']; + } + }else{ + $taskList[] = 0; + $undoneTaskList[] = 0; + } + } + if ($max) { + $each = ceil($max / ($day - 1)); + $current = $max; + for ($i = 1; $i <= $day; $i++) { + $baseLineList[] = $current; + $current -= $each; + $current < 0 && $current = 0; + } + } + return ['date' => $dateList, 'task' => $taskList, 'undoneTask' => $undoneTaskList, 'baseLineList' => $baseLineList]; + } public static function setDayilyProejctReport() { diff --git a/application/project/controller/Project.php b/application/project/controller/Project.php index 043c00a..b4cf413 100644 --- a/application/project/controller/Project.php +++ b/application/project/controller/Project.php @@ -368,13 +368,24 @@ class Project extends BasicApi echo 'success_at ' . nowTime(); } + public function _getProjectReport() + { + $projectCode = Request::param('projectCode'); + if (!$projectCode) { + $this->error('项目已失效'); + } + $data = ProjectReport::getReportByDay($projectCode, 10); + $this->success('', $data); + } + /** * 概览报表 * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ - public function _projectStats() + public + function _projectStats() { $projectCode = Request::param('projectCode'); if (!$projectCode) { @@ -425,7 +436,8 @@ class Project extends BasicApi /** * 上传封面 */ - public function uploadCover() + public + function uploadCover() { try { $file = $this->model->uploadCover(Request::file('cover')); @@ -438,7 +450,8 @@ class Project extends BasicApi /** * 放入回收站 */ - public function recycle() + public + function recycle() { try { $this->model->recycle(Request::post('projectCode')); @@ -451,7 +464,8 @@ class Project extends BasicApi /** * 恢复 */ - public function recovery() + public + function recovery() { try { $this->model->recovery(Request::post('projectCode')); @@ -465,7 +479,8 @@ class Project extends BasicApi /** * 归档 */ - public function archive() + public + function archive() { try { $this->model->archive(Request::post('projectCode')); @@ -478,7 +493,8 @@ class Project extends BasicApi /** * 恢复归档 */ - public function recoveryArchive() + public + function recoveryArchive() { try { $this->model->recoveryArchive(Request::post('projectCode')); @@ -491,7 +507,8 @@ class Project extends BasicApi /** * 退出项目 */ - public function quit() + public + function quit() { try { $this->model->quit(Request::post('projectCode'));