|
...
|
...
|
@@ -11,6 +11,7 @@ namespace App\Console\Commands\MonthlyCount; |
|
|
|
|
|
|
|
use App\Models\Com\UpdateOldInfo;
|
|
|
|
use App\Models\Domain\DomainInfo;
|
|
|
|
use App\Models\Inquiry\InquiryFormData;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Services\ProjectServer;
|
|
|
|
use Illuminate\Console\Command;
|
|
...
|
...
|
@@ -98,44 +99,56 @@ class MonthCount extends Command |
|
|
|
* @time :2024/1/8 9:05
|
|
|
|
*/
|
|
|
|
public function count($project_id,$url){
|
|
|
|
$v = ['month'=>date('Y-m')];
|
|
|
|
$monthCountModel = new MonthCountModel();
|
|
|
|
$info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]);
|
|
|
|
// 获取当月开始时间
|
|
|
|
$start = date('Y-m-01', strtotime($v['month']));
|
|
|
|
// 获取当月结束时间
|
|
|
|
$end = date('Y-m-t', strtotime($v['month']));
|
|
|
|
$arr['project_id'] = $project_id;
|
|
|
|
$res = $this->inquiry($url,$v['month']);
|
|
|
|
$v = ['month'=>date('Y-m')];
|
|
|
|
$monthCountModel = new MonthCountModel();
|
|
|
|
$info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]);
|
|
|
|
// 获取当月开始时间
|
|
|
|
$start = date('Y-m-01', strtotime($v['month']));
|
|
|
|
// 获取当月结束时间
|
|
|
|
$end = date('Y-m-t', strtotime($v['month']));
|
|
|
|
$arr['project_id'] = $project_id;
|
|
|
|
$res = $this->inquiry($url,$v['month']);
|
|
|
|
// $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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isset($res['data']['data'])){
|
|
|
|
$arr['country'] = json_encode($res['data']['data']);
|
|
|
|
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'] = $v['month'];
|
|
|
|
$arr = $this->pv_ip($arr,$start,$end,$project_id);
|
|
|
|
$arr = $this->sourceCount($arr,$start,$end);
|
|
|
|
if($info === false){
|
|
|
|
$selectedDate = $start;
|
|
|
|
$firstDayOfNextMonth = date('Y-m-01 01:00:00', strtotime("$selectedDate +1 month"));
|
|
|
|
$arr['created_at'] = $firstDayOfNextMonth;
|
|
|
|
$arr['updated_at'] = $firstDayOfNextMonth;
|
|
|
|
// echo date('Y-m-d H:i:s') . '数据:'.json_encode($arr) . PHP_EOL;
|
|
|
|
$monthCountModel->insert($arr);
|
|
|
|
}
|
|
|
|
//获取当月的其他询盘
|
|
|
|
$arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']);
|
|
|
|
$country = [];
|
|
|
|
if(isset($res['data']['data'])){
|
|
|
|
$country = $res['data']['data'];
|
|
|
|
}
|
|
|
|
$countryData = InquiryFormData::getCountryCount([$start.' 00:00:00',$end.' 00:00:00']);
|
|
|
|
foreach ($countryData as $v1){
|
|
|
|
if(isset($country[$v1['country']])){
|
|
|
|
$country[$v1['country']] += $v1['count'];
|
|
|
|
}else{
|
|
|
|
$monthCountModel->edit($arr,['id'=>$info['id']]);
|
|
|
|
$country[$v1['country']] = $v1['count'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$arr['country'] = json_encode($country);
|
|
|
|
$arr['month'] = $v['month'];
|
|
|
|
$arr = $this->pv_ip($arr,$start,$end,$project_id);
|
|
|
|
$arr = $this->sourceCount($arr,$start,$end);
|
|
|
|
if($info === false){
|
|
|
|
$selectedDate = $start;
|
|
|
|
$firstDayOfNextMonth = date('Y-m-01 01:00:00', strtotime("$selectedDate +1 month"));
|
|
|
|
$arr['created_at'] = $firstDayOfNextMonth;
|
|
|
|
$arr['updated_at'] = $firstDayOfNextMonth;
|
|
|
|
// echo date('Y-m-d H:i:s') . '数据:'.json_encode($arr) . PHP_EOL;
|
|
|
|
$monthCountModel->insert($arr);
|
|
|
|
}else{
|
|
|
|
$monthCountModel->edit($arr,['id'=>$info['id']]);
|
|
|
|
}
|
|
|
|
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|