|
...
|
...
|
@@ -59,15 +59,30 @@ class MonthProjectCount extends Command |
|
|
|
* @time :2024/1/8 9:05
|
|
|
|
*/
|
|
|
|
public function count($project_id,$url,$is_upgrade = 0){
|
|
|
|
$data = [];
|
|
|
|
$list = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
|
|
->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
|
|
|
|
->orderBy('month', 'asc')
|
|
|
|
->groupBy('month')->get()->toArray();
|
|
|
|
foreach ($list as $v){
|
|
|
|
$data[] = $v->month;
|
|
|
|
$data = [];
|
|
|
|
if (!empty($list)) {
|
|
|
|
// 提取已有月份
|
|
|
|
foreach ($list as $v) {
|
|
|
|
$data[] = $v->month;
|
|
|
|
}
|
|
|
|
// 生成连续月份
|
|
|
|
$startMonth = $data[0];
|
|
|
|
$endMonth = end($data);
|
|
|
|
$fullMonths = [];
|
|
|
|
$current = $startMonth;
|
|
|
|
while ($current <= $endMonth) {
|
|
|
|
$fullMonths[] = $current;
|
|
|
|
$current = date('Y-m', strtotime($current . ' +1 month'));
|
|
|
|
}
|
|
|
|
$data = $fullMonths;
|
|
|
|
} else {
|
|
|
|
$data = [];
|
|
|
|
}
|
|
|
|
$list = $this->fillMissingMonths($data);
|
|
|
|
$list = $data;
|
|
|
|
foreach ($list as $v){
|
|
|
|
$arr = [];
|
|
|
|
$monthCountModel = new MonthCount();
|
|
...
|
...
|
@@ -179,38 +194,4 @@ class MonthProjectCount extends Command |
|
|
|
$arr['referrer_port'] = json_encode($referrer_port);
|
|
|
|
return $arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :补齐月份
|
|
|
|
* @name :fillMissingMonths
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/8/14 11:11
|
|
|
|
*/
|
|
|
|
public function fillMissingMonths($dates) {
|
|
|
|
// 将字符串日期转换为 Carbon 对象
|
|
|
|
$carbonDates = array_map(function($date) {
|
|
|
|
return Carbon::createFromFormat('Y-m', $date);
|
|
|
|
}, $dates);
|
|
|
|
// 排序日期,确保列表按时间顺序排列
|
|
|
|
usort($carbonDates, function($a, $b) {
|
|
|
|
return $a->gt($b);
|
|
|
|
});
|
|
|
|
// 用于存储完整日期的数组
|
|
|
|
$completeDates = [];
|
|
|
|
// 遍历日期列表,补齐中间缺失的月份
|
|
|
|
for ($i = 0; $i < count($carbonDates) - 1; $i++) {
|
|
|
|
$current = $carbonDates[$i];
|
|
|
|
$next = $carbonDates[$i + 1];
|
|
|
|
// 将当前月份加入完整日期数组
|
|
|
|
array_push($completeDates, $current->format('Y-m'));
|
|
|
|
// 循环补齐中间缺失的月份
|
|
|
|
while ($current->addMonth()->lt($next)) {
|
|
|
|
array_push($completeDates, $current->format('Y-m'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 加入最后一个月份
|
|
|
|
array_push($completeDates, $carbonDates[count($carbonDates) - 1]->format('Y-m'));
|
|
|
|
return $completeDates;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|