项目燃尽图

Signed-off-by: vilson <545522390@qq.com>
This commit is contained in:
vilson 2020-02-21 08:25:03 +08:00
parent a97c74717f
commit 7a3b89624c
2 changed files with 68 additions and 7 deletions

View File

@ -17,6 +17,50 @@ class ProjectReport extends CommonModel
protected $append = []; protected $append = [];
protected $json = ['content']; 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() public static function setDayilyProejctReport()
{ {

View File

@ -368,13 +368,24 @@ class Project extends BasicApi
echo 'success_at ' . nowTime(); 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 DataNotFoundException
* @throws DbException * @throws DbException
* @throws ModelNotFoundException * @throws ModelNotFoundException
*/ */
public function _projectStats() public
function _projectStats()
{ {
$projectCode = Request::param('projectCode'); $projectCode = Request::param('projectCode');
if (!$projectCode) { if (!$projectCode) {
@ -425,7 +436,8 @@ class Project extends BasicApi
/** /**
* 上传封面 * 上传封面
*/ */
public function uploadCover() public
function uploadCover()
{ {
try { try {
$file = $this->model->uploadCover(Request::file('cover')); $file = $this->model->uploadCover(Request::file('cover'));
@ -438,7 +450,8 @@ class Project extends BasicApi
/** /**
* 放入回收站 * 放入回收站
*/ */
public function recycle() public
function recycle()
{ {
try { try {
$this->model->recycle(Request::post('projectCode')); $this->model->recycle(Request::post('projectCode'));
@ -451,7 +464,8 @@ class Project extends BasicApi
/** /**
* 恢复 * 恢复
*/ */
public function recovery() public
function recovery()
{ {
try { try {
$this->model->recovery(Request::post('projectCode')); $this->model->recovery(Request::post('projectCode'));
@ -465,7 +479,8 @@ class Project extends BasicApi
/** /**
* 归档 * 归档
*/ */
public function archive() public
function archive()
{ {
try { try {
$this->model->archive(Request::post('projectCode')); $this->model->archive(Request::post('projectCode'));
@ -478,7 +493,8 @@ class Project extends BasicApi
/** /**
* 恢复归档 * 恢复归档
*/ */
public function recoveryArchive() public
function recoveryArchive()
{ {
try { try {
$this->model->recoveryArchive(Request::post('projectCode')); $this->model->recoveryArchive(Request::post('projectCode'));
@ -491,7 +507,8 @@ class Project extends BasicApi
/** /**
* 退出项目 * 退出项目
*/ */
public function quit() public
function quit()
{ {
try { try {
$this->model->quit(Request::post('projectCode')); $this->model->quit(Request::post('projectCode'));