作者 lyh

gxdemo脚本

@@ -71,26 +71,23 @@ class MonthProjectCount extends Command @@ -71,26 +71,23 @@ class MonthProjectCount extends Command
71 $data[] = $v->month; 71 $data[] = $v->month;
72 } 72 }
73 $list = $this->fillMissingMonths($data); 73 $list = $this->fillMissingMonths($data);
74 - var_dump($list);  
75 - die();  
76 - foreach ($list as $k=>$v){ 74 + foreach ($list as $v){
77 $arr = []; 75 $arr = [];
78 - $v = (array)$v;  
79 $monthCountModel = new MonthCount(); 76 $monthCountModel = new MonthCount();
80 - $info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]); 77 + $info = $monthCountModel->read(['month'=>$v,'project_id'=>$project_id]);
81 // 获取当月开始时间 78 // 获取当月开始时间
82 - $start = date('Y-m-01', strtotime($v['month'])); 79 + $start = date('Y-m-01', strtotime($v));
83 // 获取当月结束时间 80 // 获取当月结束时间
84 - $end = date('Y-m-t', strtotime($v['month'])); 81 + $end = date('Y-m-t', strtotime($v));
85 $arr['project_id'] = $project_id; 82 $arr['project_id'] = $project_id;
86 - $res = $this->inquiry($url,$v['month']);  
87 - echo date('Y-m-d H:i:s') . '月份:'.$v['month']. PHP_EOL; 83 + $res = $this->inquiry($url,$v);
  84 + echo date('Y-m-d H:i:s') . '月份:'.$v. PHP_EOL;
88 $arr['total'] = $arr['month_total'] = 0; 85 $arr['total'] = $arr['month_total'] = 0;
89 if(isset($res['data']['count'])){ 86 if(isset($res['data']['count'])){
90 echo date('Y-m-d H:i:s') . '数据:'.$res['data']['count'] . PHP_EOL; 87 echo date('Y-m-d H:i:s') . '数据:'.$res['data']['count'] . PHP_EOL;
91 $arr['month_total'] = $res['data']['count']; 88 $arr['month_total'] = $res['data']['count'];
92 //获取上一个的count 89 //获取上一个的count
93 - $previousMonth = date('Y-m', strtotime($v['month'] . ' -1 month')); 90 + $previousMonth = date('Y-m', strtotime($v . ' -1 month'));
94 $previousInfo = $monthCountModel->read(['month'=>$previousMonth,'project_id'=>$project_id]); 91 $previousInfo = $monthCountModel->read(['month'=>$previousMonth,'project_id'=>$project_id]);
95 if($previousInfo === false){ 92 if($previousInfo === false){
96 $arr['total'] = $arr['month_total']; 93 $arr['total'] = $arr['month_total'];
@@ -114,7 +111,7 @@ class MonthProjectCount extends Command @@ -114,7 +111,7 @@ class MonthProjectCount extends Command
114 } 111 }
115 } 112 }
116 $arr['country'] = json_encode($country); 113 $arr['country'] = json_encode($country);
117 - $arr['month'] = $v['month']; 114 + $arr['month'] = $v;
118 $arr = $this->pv_ip($arr,$start,$end,$project_id); 115 $arr = $this->pv_ip($arr,$start,$end,$project_id);
119 $arr = $this->sourceCount($arr,$start,$end); 116 $arr = $this->sourceCount($arr,$start,$end);
120 if($info === false){ 117 if($info === false){
@@ -201,6 +198,8 @@ class MonthProjectCount extends Command @@ -201,6 +198,8 @@ class MonthProjectCount extends Command
201 echo date('Y-m-d H:i:s') . '数据:'.json_encode($res) . PHP_EOL; 198 echo date('Y-m-d H:i:s') . '数据:'.json_encode($res) . PHP_EOL;
202 return $res; 199 return $res;
203 } 200 }
  201 +
  202 +
204 public function fillMissingMonths($dates) { 203 public function fillMissingMonths($dates) {
205 // 将字符串日期转换为 Carbon 对象 204 // 将字符串日期转换为 Carbon 对象
206 $carbonDates = array_map(function($date) { 205 $carbonDates = array_map(function($date) {