GeoCount.php
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* @remark :
* @name :GeoCount.php
* @author :lyh
* @method :post
* @time :2025/10/13 16:05
*/
namespace App\Console\Commands\Geo;
use App\Models\Geo\GeoQuestionLog;
use App\Models\Geo\GeoQuestionResult;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
class GeoCount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'geo_count';
public $porject_id;//记录当时执行的project_id
/**
* The console command description.
*
* @var string
*/
protected $description = 'geo统计数据';
public function handle(){
$this->output('start');
$this->_action();
$this->output('end');
return true;
}
/**
* @remark :方法
* @name :_action
* @author :lyh
* @method :post
* @time :2025/10/13 16:20
*/
public function _action()
{
//获取前一天的项目id
$date = Carbon::yesterday()->format('Y-m-d');
$start = $date.' 00:00:00';
$end = $date.' 23:59:59';
$geoLogModel = new GeoQuestionLog();
$project_id = $geoLogModel->formatQuery(['created_at' => ['between',[$start,$end]]])->distinct()->pluck('project_id');
if(empty($project_id)){
return true;
}
$geoQuestionResModel = new GeoQuestionResult();
$platforms = ['gemini','openai','deepseek','poe','perplexity','google_ai_overview','openai-not-network','claude'];
foreach ($project_id as $item){
$this->output('执行的项目ID----'.$item);
//收录总数
$total = $geoQuestionResModel->counts(['project_id' => $item,'hit'=>['!=',0],'created_at' => ['between',[$start,$end]]]);
$data = [
'project_id' => $item,
'date' => $date,
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
'updated_at' => Carbon::now()->format('Y-m-d H:i:s'),
'total'=>$total,//收录总数
];
foreach ($platforms as $platform){
$data[$platform] = $geoQuestionResModel->counts(['project_id' => $item,'hit'=>['!=',0],'platform'=>$platform,'created_at' => ['between',[$start,$end]]]);
}
//新增一条数据
$geoQuestionResModel->addReturnId($data);
}
return true;
}
/**
* 输出日志
* @param $message
* @return bool
*/
public function output($message)
{
echo date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
return true;
}
}