|
...
|
...
|
@@ -18,6 +18,7 @@ use App\Models\Project\Project; |
|
|
|
use App\Models\Visit\Visit;
|
|
|
|
use App\Services\ProjectServer;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use App\Models\HomeCount\Count;
|
|
|
|
|
|
...
|
...
|
@@ -61,35 +62,40 @@ class MonthProjectCount extends Command |
|
|
|
* @time :2024/1/8 9:05
|
|
|
|
*/
|
|
|
|
public function count($project_id,$url){
|
|
|
|
$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 $k=>$v){
|
|
|
|
foreach ($list as $v){
|
|
|
|
$data[] = $v->month;
|
|
|
|
}
|
|
|
|
$list = $this->fillMissingMonths($data);
|
|
|
|
foreach ($list as $v){
|
|
|
|
$arr = [];
|
|
|
|
$v = (array)$v;
|
|
|
|
$monthCountModel = new MonthCount();
|
|
|
|
$info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]);
|
|
|
|
$info = $monthCountModel->read(['month'=>$v,'project_id'=>$project_id]);
|
|
|
|
// 获取当月开始时间
|
|
|
|
$start = date('Y-m-01', strtotime($v['month']));
|
|
|
|
$start = date('Y-m-01', strtotime($v));
|
|
|
|
// 获取当月结束时间
|
|
|
|
$end = date('Y-m-t', strtotime($v['month']));
|
|
|
|
$end = date('Y-m-t', strtotime($v));
|
|
|
|
$arr['project_id'] = $project_id;
|
|
|
|
$res = $this->inquiry($url,$v['month']);
|
|
|
|
$res = $this->inquiry($url,$v);
|
|
|
|
echo date('Y-m-d H:i:s') . '月份:'.$v. PHP_EOL;
|
|
|
|
$arr['total'] = $arr['month_total'] = 0;
|
|
|
|
if(isset($res['data']['count'])){
|
|
|
|
echo date('Y-m-d H:i:s') . '数据:'.$res['data']['count'] . PHP_EOL;
|
|
|
|
$arr['month_total'] = $res['data']['count'];
|
|
|
|
//获取上一个的count
|
|
|
|
$previousMonth = date('Y-m', strtotime($v['month'] . ' -1 month'));
|
|
|
|
$previousInfo = $monthCountModel->read(['month'=>$previousMonth,'project_id'=>$project_id]);
|
|
|
|
if($previousInfo === false){
|
|
|
|
$arr['total'] = $arr['month_total'];
|
|
|
|
}else{
|
|
|
|
$arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0);
|
|
|
|
}
|
|
|
|
$arr['month_total'] = $res['data']['count'] + InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']);
|
|
|
|
}
|
|
|
|
//获取当月的其他询盘
|
|
|
|
$arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']);
|
|
|
|
//获取上一个的count
|
|
|
|
$previousMonth = date('Y-m', strtotime($v . ' -1 month'));
|
|
|
|
$previousInfo = $monthCountModel->read(['month'=>$previousMonth,'project_id'=>$project_id]);
|
|
|
|
if($previousInfo === false){
|
|
|
|
$arr['total'] = $arr['month_total'];
|
|
|
|
}else{
|
|
|
|
$arr['total'] = $arr['month_total'] + ($previousInfo['total'] ?? 0);
|
|
|
|
}
|
|
|
|
echo date('Y-m-d H:i:s') . '加上其他询盘:'.$arr['total'] . PHP_EOL;
|
|
|
|
$country = [];
|
|
|
|
if(isset($res['data']['data'])){
|
|
|
|
$country = $res['data']['data'];
|
|
...
|
...
|
@@ -103,7 +109,7 @@ class MonthProjectCount extends Command |
|
|
|
}
|
|
|
|
}
|
|
|
|
$arr['country'] = json_encode($country);
|
|
|
|
$arr['month'] = $v['month'];
|
|
|
|
$arr['month'] = $v;
|
|
|
|
$arr = $this->pv_ip($arr,$start,$end,$project_id);
|
|
|
|
$arr = $this->sourceCount($arr,$start,$end);
|
|
|
|
if($info === false){
|
|
...
|
...
|
@@ -191,4 +197,37 @@ class MonthProjectCount extends Command |
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|