作者 lyh

gxdemo脚本

@@ -98,15 +98,6 @@ class MonthAllCount extends Command @@ -98,15 +98,6 @@ class MonthAllCount extends Command
98 }else{ 98 }else{
99 $arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0); 99 $arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0);
100 } 100 }
101 - }else{  
102 - //获取上一个的count  
103 - $previousMonth = date('Y-m', strtotime($v['month'] . ' -1 month'));  
104 - $previousInfo = $monthCountModel->read(['month'=>$previousMonth,'project_id'=>$project_id]);  
105 - if($previousInfo === false){  
106 - $arr['total'] = $arr['month_total'];  
107 - }else{  
108 - $arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0);  
109 - }  
110 } 101 }
111 //获取当月的其他询盘 102 //获取当月的其他询盘
112 $arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']); 103 $arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']);
@@ -121,15 +121,6 @@ class MonthCount extends Command @@ -121,15 +121,6 @@ class MonthCount extends Command
121 }else{ 121 }else{
122 $arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0); 122 $arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0);
123 } 123 }
124 - }else{  
125 - //获取上一个的count  
126 - $previousMonth = date('Y-m', strtotime($v['month'] . ' -1 month'));  
127 - $previousInfo = $monthCountModel->read(['month'=>$previousMonth,'project_id'=>$project_id]);  
128 - if($previousInfo === false){  
129 - $arr['total'] = $arr['month_total'];  
130 - }else{  
131 - $arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0);  
132 - }  
133 } 124 }
134 //获取当月的其他询盘 125 //获取当月的其他询盘
135 $arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']); 126 $arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']);
@@ -64,6 +64,8 @@ class MonthProjectCount extends Command @@ -64,6 +64,8 @@ class MonthProjectCount extends Command
64 $list = DB::connection('custom_mysql')->table('gl_customer_visit') 64 $list = DB::connection('custom_mysql')->table('gl_customer_visit')
65 ->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month')) 65 ->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
66 ->groupBy('month')->get()->toArray(); 66 ->groupBy('month')->get()->toArray();
  67 + var_dump($list);
  68 + die();
67 foreach ($list as $k=>$v){ 69 foreach ($list as $k=>$v){
68 $arr = []; 70 $arr = [];
69 $v = (array)$v; 71 $v = (array)$v;
@@ -88,13 +90,6 @@ class MonthProjectCount extends Command @@ -88,13 +90,6 @@ class MonthProjectCount extends Command
88 }else{ 90 }else{
89 $arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0); 91 $arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0);
90 } 92 }
91 - }else{  
92 - //获取上一个的count  
93 - $previousMonth = date('Y-m', strtotime($v['month'] . ' -1 month'));  
94 - $previousInfo = $monthCountModel->read(['month'=>$previousMonth,'project_id'=>$project_id]);  
95 - if($previousInfo !== false){  
96 - $arr['total'] = $previousInfo['total'];  
97 - }  
98 } 93 }
99 //获取当月的其他询盘 94 //获取当月的其他询盘
100 $arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']); 95 $arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']);
@@ -199,5 +194,30 @@ class MonthProjectCount extends Command @@ -199,5 +194,30 @@ class MonthProjectCount extends Command
199 echo date('Y-m-d H:i:s') . '数据:'.json_encode($res) . PHP_EOL; 194 echo date('Y-m-d H:i:s') . '数据:'.json_encode($res) . PHP_EOL;
200 return $res; 195 return $res;
201 } 196 }
202 - 197 + public function fillMissingMonths($dates) {
  198 + // 将字符串日期转换为 Carbon 对象
  199 + $carbonDates = array_map(function($date) {
  200 + return Carbon::createFromFormat('Y-m', $date);
  201 + }, $dates);
  202 + // 排序日期,确保列表按时间顺序排列
  203 + usort($carbonDates, function($a, $b) {
  204 + return $a->gt($b);
  205 + });
  206 + // 用于存储完整日期的数组
  207 + $completeDates = [];
  208 + // 遍历日期列表,补齐中间缺失的月份
  209 + for ($i = 0; $i < count($carbonDates) - 1; $i++) {
  210 + $current = $carbonDates[$i];
  211 + $next = $carbonDates[$i + 1];
  212 + // 将当前月份加入完整日期数组
  213 + array_push($completeDates, $current->format('Y-m'));
  214 + // 循环补齐中间缺失的月份
  215 + while ($current->addMonth()->lt($next)) {
  216 + array_push($completeDates, $current->format('Y-m'));
  217 + }
  218 + }
  219 + // 加入最后一个月份
  220 + array_push($completeDates, $carbonDates[count($carbonDates) - 1]->format('Y-m'));
  221 + return $completeDates;
  222 + }
203 } 223 }