|
@@ -18,6 +18,7 @@ use App\Models\Project\Project; |
|
@@ -18,6 +18,7 @@ use App\Models\Project\Project; |
|
18
|
use App\Models\Visit\Visit;
|
18
|
use App\Models\Visit\Visit;
|
|
19
|
use App\Services\ProjectServer;
|
19
|
use App\Services\ProjectServer;
|
|
20
|
use Illuminate\Console\Command;
|
20
|
use Illuminate\Console\Command;
|
|
|
|
21
|
+use Illuminate\Support\Carbon;
|
|
21
|
use Illuminate\Support\Facades\DB;
|
22
|
use Illuminate\Support\Facades\DB;
|
|
22
|
use App\Models\HomeCount\Count;
|
23
|
use App\Models\HomeCount\Count;
|
|
23
|
|
24
|
|
|
@@ -61,35 +62,40 @@ class MonthProjectCount extends Command |
|
@@ -61,35 +62,40 @@ class MonthProjectCount extends Command |
|
61
|
* @time :2024/1/8 9:05
|
62
|
* @time :2024/1/8 9:05
|
|
62
|
*/
|
63
|
*/
|
|
63
|
public function count($project_id,$url){
|
64
|
public function count($project_id,$url){
|
|
|
|
65
|
+ $data = [];
|
|
64
|
$list = DB::connection('custom_mysql')->table('gl_customer_visit')
|
66
|
$list = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
65
|
->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
|
67
|
->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
|
|
|
|
68
|
+ ->orderBy('month', 'asc')
|
|
66
|
->groupBy('month')->get()->toArray();
|
69
|
->groupBy('month')->get()->toArray();
|
|
67
|
- foreach ($list as $k=>$v){
|
70
|
+ foreach ($list as $v){
|
|
|
|
71
|
+ $data[] = $v->month;
|
|
|
|
72
|
+ }
|
|
|
|
73
|
+ $list = $this->fillMissingMonths($data);
|
|
|
|
74
|
+ foreach ($list as $v){
|
|
68
|
$arr = [];
|
75
|
$arr = [];
|
|
69
|
- $v = (array)$v;
|
|
|
|
70
|
$monthCountModel = new MonthCount();
|
76
|
$monthCountModel = new MonthCount();
|
|
71
|
- $info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]);
|
77
|
+ $info = $monthCountModel->read(['month'=>$v,'project_id'=>$project_id]);
|
|
72
|
// 获取当月开始时间
|
78
|
// 获取当月开始时间
|
|
73
|
- $start = date('Y-m-01', strtotime($v['month']));
|
79
|
+ $start = date('Y-m-01', strtotime($v));
|
|
74
|
// 获取当月结束时间
|
80
|
// 获取当月结束时间
|
|
75
|
- $end = date('Y-m-t', strtotime($v['month']));
|
81
|
+ $end = date('Y-m-t', strtotime($v));
|
|
76
|
$arr['project_id'] = $project_id;
|
82
|
$arr['project_id'] = $project_id;
|
|
77
|
- $res = $this->inquiry($url,$v['month']);
|
83
|
+ $res = $this->inquiry($url,$v);
|
|
|
|
84
|
+ echo date('Y-m-d H:i:s') . '月份:'.$v. PHP_EOL;
|
|
78
|
$arr['total'] = $arr['month_total'] = 0;
|
85
|
$arr['total'] = $arr['month_total'] = 0;
|
|
79
|
if(isset($res['data']['count'])){
|
86
|
if(isset($res['data']['count'])){
|
|
80
|
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;
|
|
81
|
- $arr['month_total'] = $res['data']['count'];
|
88
|
+ $arr['month_total'] = $res['data']['count'] + InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']);
|
|
|
|
89
|
+ }
|
|
82
|
//获取上一个的count
|
90
|
//获取上一个的count
|
|
83
|
- $previousMonth = date('Y-m', strtotime($v['month'] . ' -1 month'));
|
91
|
+ $previousMonth = date('Y-m', strtotime($v . ' -1 month'));
|
|
84
|
$previousInfo = $monthCountModel->read(['month'=>$previousMonth,'project_id'=>$project_id]);
|
92
|
$previousInfo = $monthCountModel->read(['month'=>$previousMonth,'project_id'=>$project_id]);
|
|
85
|
if($previousInfo === false){
|
93
|
if($previousInfo === false){
|
|
86
|
$arr['total'] = $arr['month_total'];
|
94
|
$arr['total'] = $arr['month_total'];
|
|
87
|
}else{
|
95
|
}else{
|
|
88
|
- $arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0);
|
|
|
|
89
|
- }
|
96
|
+ $arr['total'] = $arr['month_total'] + ($previousInfo['total'] ?? 0);
|
|
90
|
}
|
97
|
}
|
|
91
|
- //获取当月的其他询盘
|
|
|
|
92
|
- $arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']);
|
98
|
+ echo date('Y-m-d H:i:s') . '加上其他询盘:'.$arr['total'] . PHP_EOL;
|
|
93
|
$country = [];
|
99
|
$country = [];
|
|
94
|
if(isset($res['data']['data'])){
|
100
|
if(isset($res['data']['data'])){
|
|
95
|
$country = $res['data']['data'];
|
101
|
$country = $res['data']['data'];
|
|
@@ -103,7 +109,7 @@ class MonthProjectCount extends Command |
|
@@ -103,7 +109,7 @@ class MonthProjectCount extends Command |
|
103
|
}
|
109
|
}
|
|
104
|
}
|
110
|
}
|
|
105
|
$arr['country'] = json_encode($country);
|
111
|
$arr['country'] = json_encode($country);
|
|
106
|
- $arr['month'] = $v['month'];
|
112
|
+ $arr['month'] = $v;
|
|
107
|
$arr = $this->pv_ip($arr,$start,$end,$project_id);
|
113
|
$arr = $this->pv_ip($arr,$start,$end,$project_id);
|
|
108
|
$arr = $this->sourceCount($arr,$start,$end);
|
114
|
$arr = $this->sourceCount($arr,$start,$end);
|
|
109
|
if($info === false){
|
115
|
if($info === false){
|
|
@@ -191,4 +197,37 @@ class MonthProjectCount extends Command |
|
@@ -191,4 +197,37 @@ class MonthProjectCount extends Command |
|
191
|
return $res;
|
197
|
return $res;
|
|
192
|
}
|
198
|
}
|
|
193
|
|
199
|
|
|
|
|
200
|
+ /**
|
|
|
|
201
|
+ * @remark :补齐月份
|
|
|
|
202
|
+ * @name :fillMissingMonths
|
|
|
|
203
|
+ * @author :lyh
|
|
|
|
204
|
+ * @method :post
|
|
|
|
205
|
+ * @time :2024/8/14 11:11
|
|
|
|
206
|
+ */
|
|
|
|
207
|
+ public function fillMissingMonths($dates) {
|
|
|
|
208
|
+ // 将字符串日期转换为 Carbon 对象
|
|
|
|
209
|
+ $carbonDates = array_map(function($date) {
|
|
|
|
210
|
+ return Carbon::createFromFormat('Y-m', $date);
|
|
|
|
211
|
+ }, $dates);
|
|
|
|
212
|
+ // 排序日期,确保列表按时间顺序排列
|
|
|
|
213
|
+ usort($carbonDates, function($a, $b) {
|
|
|
|
214
|
+ return $a->gt($b);
|
|
|
|
215
|
+ });
|
|
|
|
216
|
+ // 用于存储完整日期的数组
|
|
|
|
217
|
+ $completeDates = [];
|
|
|
|
218
|
+ // 遍历日期列表,补齐中间缺失的月份
|
|
|
|
219
|
+ for ($i = 0; $i < count($carbonDates) - 1; $i++) {
|
|
|
|
220
|
+ $current = $carbonDates[$i];
|
|
|
|
221
|
+ $next = $carbonDates[$i + 1];
|
|
|
|
222
|
+ // 将当前月份加入完整日期数组
|
|
|
|
223
|
+ array_push($completeDates, $current->format('Y-m'));
|
|
|
|
224
|
+ // 循环补齐中间缺失的月份
|
|
|
|
225
|
+ while ($current->addMonth()->lt($next)) {
|
|
|
|
226
|
+ array_push($completeDates, $current->format('Y-m'));
|
|
|
|
227
|
+ }
|
|
|
|
228
|
+ }
|
|
|
|
229
|
+ // 加入最后一个月份
|
|
|
|
230
|
+ array_push($completeDates, $carbonDates[count($carbonDates) - 1]->format('Y-m'));
|
|
|
|
231
|
+ return $completeDates;
|
|
|
|
232
|
+ }
|
|
194
|
} |
233
|
} |