正在显示
1 个修改的文件
包含
19 行增加
和
2 行删除
| @@ -64,8 +64,24 @@ class MonthProjectCount extends Command | @@ -64,8 +64,24 @@ class MonthProjectCount extends Command | ||
| 64 | ->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month')) | 64 | ->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month')) |
| 65 | ->orderBy('month', 'asc') | 65 | ->orderBy('month', 'asc') |
| 66 | ->groupBy('month')->get()->toArray(); | 66 | ->groupBy('month')->get()->toArray(); |
| 67 | - foreach ($list as $v){ | ||
| 68 | - $data[] = $v->month; | 67 | + $data = []; |
| 68 | + if (!empty($list)) { | ||
| 69 | + // 提取已有月份 | ||
| 70 | + foreach ($list as $v) { | ||
| 71 | + $data[] = $v->month; | ||
| 72 | + } | ||
| 73 | + // 生成连续月份 | ||
| 74 | + $startMonth = $data[0]; | ||
| 75 | + $endMonth = end($data); | ||
| 76 | + $fullMonths = []; | ||
| 77 | + $current = $startMonth; | ||
| 78 | + while ($current <= $endMonth) { | ||
| 79 | + $fullMonths[] = $current; | ||
| 80 | + $current = date('Y-m', strtotime($current . ' +1 month')); | ||
| 81 | + } | ||
| 82 | + $data = $fullMonths; | ||
| 83 | + } else { | ||
| 84 | + $data = []; | ||
| 69 | } | 85 | } |
| 70 | $list = $this->fillMissingMonths($data); | 86 | $list = $this->fillMissingMonths($data); |
| 71 | foreach ($list as $v){ | 87 | foreach ($list as $v){ |
| @@ -86,6 +102,7 @@ class MonthProjectCount extends Command | @@ -86,6 +102,7 @@ class MonthProjectCount extends Command | ||
| 86 | //获取上一个的count | 102 | //获取上一个的count |
| 87 | $previousMonth = date('Y-m', strtotime($v . ' -1 month')); | 103 | $previousMonth = date('Y-m', strtotime($v . ' -1 month')); |
| 88 | $previousInfo = $monthCountModel->read(['month'=>$previousMonth,'project_id'=>$project_id]); | 104 | $previousInfo = $monthCountModel->read(['month'=>$previousMonth,'project_id'=>$project_id]); |
| 105 | + | ||
| 89 | if($previousInfo === false){ | 106 | if($previousInfo === false){ |
| 90 | $arr['total'] = $arr['month_total']; | 107 | $arr['total'] = $arr['month_total']; |
| 91 | }else{ | 108 | }else{ |
-
请 注册 或 登录 后发表评论