|
@@ -59,7 +59,6 @@ class MonthProjectCount extends Command |
|
@@ -59,7 +59,6 @@ class MonthProjectCount extends Command |
|
59
|
* @time :2024/1/8 9:05
|
59
|
* @time :2024/1/8 9:05
|
|
60
|
*/
|
60
|
*/
|
|
61
|
public function count($project_id,$url,$is_upgrade = 0){
|
61
|
public function count($project_id,$url,$is_upgrade = 0){
|
|
62
|
- $data = [];
|
|
|
|
63
|
$list = DB::connection('custom_mysql')->table('gl_customer_visit')
|
62
|
$list = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
64
|
->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
|
63
|
->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
|
|
65
|
->orderBy('month', 'asc')
|
64
|
->orderBy('month', 'asc')
|
|
@@ -83,7 +82,7 @@ class MonthProjectCount extends Command |
|
@@ -83,7 +82,7 @@ class MonthProjectCount extends Command |
|
83
|
} else {
|
82
|
} else {
|
|
84
|
$data = [];
|
83
|
$data = [];
|
|
85
|
}
|
84
|
}
|
|
86
|
- $list = $this->fillMissingMonths($data);
|
85
|
+ $list = $data;
|
|
87
|
foreach ($list as $v){
|
86
|
foreach ($list as $v){
|
|
88
|
$arr = [];
|
87
|
$arr = [];
|
|
89
|
$monthCountModel = new MonthCount();
|
88
|
$monthCountModel = new MonthCount();
|
|
@@ -195,38 +194,4 @@ class MonthProjectCount extends Command |
|
@@ -195,38 +194,4 @@ class MonthProjectCount extends Command |
|
195
|
$arr['referrer_port'] = json_encode($referrer_port);
|
194
|
$arr['referrer_port'] = json_encode($referrer_port);
|
|
196
|
return $arr;
|
195
|
return $arr;
|
|
197
|
}
|
196
|
}
|
|
198
|
-
|
|
|
|
199
|
- /**
|
|
|
|
200
|
- * @remark :补齐月份
|
|
|
|
201
|
- * @name :fillMissingMonths
|
|
|
|
202
|
- * @author :lyh
|
|
|
|
203
|
- * @method :post
|
|
|
|
204
|
- * @time :2024/8/14 11:11
|
|
|
|
205
|
- */
|
|
|
|
206
|
- public function fillMissingMonths($dates) {
|
|
|
|
207
|
- // 将字符串日期转换为 Carbon 对象
|
|
|
|
208
|
- $carbonDates = array_map(function($date) {
|
|
|
|
209
|
- return Carbon::createFromFormat('Y-m', $date);
|
|
|
|
210
|
- }, $dates);
|
|
|
|
211
|
- // 排序日期,确保列表按时间顺序排列
|
|
|
|
212
|
- usort($carbonDates, function($a, $b) {
|
|
|
|
213
|
- return $a->gt($b);
|
|
|
|
214
|
- });
|
|
|
|
215
|
- // 用于存储完整日期的数组
|
|
|
|
216
|
- $completeDates = [];
|
|
|
|
217
|
- // 遍历日期列表,补齐中间缺失的月份
|
|
|
|
218
|
- for ($i = 0; $i < count($carbonDates) - 1; $i++) {
|
|
|
|
219
|
- $current = $carbonDates[$i];
|
|
|
|
220
|
- $next = $carbonDates[$i + 1];
|
|
|
|
221
|
- // 将当前月份加入完整日期数组
|
|
|
|
222
|
- array_push($completeDates, $current->format('Y-m'));
|
|
|
|
223
|
- // 循环补齐中间缺失的月份
|
|
|
|
224
|
- while ($current->addMonth()->lt($next)) {
|
|
|
|
225
|
- array_push($completeDates, $current->format('Y-m'));
|
|
|
|
226
|
- }
|
|
|
|
227
|
- }
|
|
|
|
228
|
- // 加入最后一个月份
|
|
|
|
229
|
- array_push($completeDates, $carbonDates[count($carbonDates) - 1]->format('Y-m'));
|
|
|
|
230
|
- return $completeDates;
|
|
|
|
231
|
- }
|
|
|
|
232
|
} |
197
|
} |