作者 赵彬吉
@@ -75,7 +75,7 @@ class GeoCount extends Command @@ -75,7 +75,7 @@ class GeoCount extends Command
75 'total'=>$total,//收录总数 75 'total'=>$total,//收录总数
76 ]; 76 ];
77 foreach ($platforms as $platform){ 77 foreach ($platforms as $platform){
78 - if($item == 'openai-not-network'){ 78 + if($platform == 'openai-not-network'){
79 $data['openai_not_network'] = $geoQuestionResModel->counts(['project_id' => $item,'hit'=>['!=',0],'platform'=>$platform,'created_at' => ['between',[$start,$end]]]); 79 $data['openai_not_network'] = $geoQuestionResModel->counts(['project_id' => $item,'hit'=>['!=',0],'platform'=>$platform,'created_at' => ['between',[$start,$end]]]);
80 }else{ 80 }else{
81 $data[$platform] = $geoQuestionResModel->counts(['project_id' => $item,'hit'=>['!=',0],'platform'=>$platform,'created_at' => ['between',[$start,$end]]]); 81 $data[$platform] = $geoQuestionResModel->counts(['project_id' => $item,'hit'=>['!=',0],'platform'=>$platform,'created_at' => ['between',[$start,$end]]]);
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :GeoCount.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/10/13 16:05
  8 + */
  9 +
  10 +namespace App\Console\Commands\Geo;
  11 +
  12 +use App\Models\Geo\GeoQuestionLog;
  13 +use App\Models\Geo\GeoQuestionResult;
  14 +use Illuminate\Console\Command;
  15 +use Illuminate\Support\Carbon;
  16 +use App\Models\Geo\GeoCount as GeoCountModel;
  17 +
  18 +class GeoCountAll extends Command
  19 +{
  20 + /**
  21 + * The name and signature of the console command.
  22 + *
  23 + * @var string
  24 + */
  25 + protected $signature = 'geo_count_all';
  26 +
  27 + public $porject_id;//记录当时执行的project_id
  28 +
  29 + /**
  30 + * The console command description.
  31 + *
  32 + * @var string
  33 + */
  34 + protected $description = 'geo统计数据';
  35 +
  36 +
  37 +
  38 + public function handle(){
  39 + $this->output('start');
  40 + $this->_action();
  41 + $this->output('end');
  42 + return true;
  43 + }
  44 +
  45 + /**
  46 + * @remark :方法
  47 + * @name :_action
  48 + * @author :lyh
  49 + * @method :post
  50 + * @time :2025/10/13 16:20
  51 + */
  52 + public function _action()
  53 + {
  54 + $geoCountModel = new GeoCountModel();
  55 + //获取前一天的项目id
  56 + $dates = [];
  57 + for ($i = 0; $i < 100; $i++) {
  58 + $dates[] = date('Y-m-d', strtotime("-{$i} days"));
  59 + }
  60 + foreach ($dates as $date) {
  61 + $start = $date.' 00:00:00';
  62 + $end = $date.' 23:59:59';
  63 + $geoLogModel = new GeoQuestionLog();
  64 + $project_id = $geoLogModel->formatQuery(['created_at' => ['between',[$start,$end]]])->distinct()->pluck('project_id');
  65 + if(empty($project_id)){
  66 + return true;
  67 + }
  68 + $geoQuestionResModel = new GeoQuestionLog();
  69 + $platforms = ['gemini','openai','deepseek','poe','perplexity','google_ai_overview','openai-not-network','claude'];
  70 + foreach ($project_id as $item){
  71 + $this->output('执行的项目ID----'.$item);
  72 + //收录总数
  73 + $total = $geoQuestionResModel->counts(['project_id' => $item,'hit'=>['!=',0],'created_at' => ['between',[$start,$end]]]);
  74 + $data = [
  75 + 'project_id' => $item,
  76 + 'date' => $date,
  77 + 'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
  78 + 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'),
  79 + 'total'=>$total,//收录总数
  80 + ];
  81 + foreach ($platforms as $platform){
  82 + if($platform == 'openai-not-network'){
  83 + $data['openai_not_network'] = $geoQuestionResModel->counts(['project_id' => $item,'hit'=>['!=',0],'platform'=>$platform,'created_at' => ['between',[$start,$end]]]);
  84 + }else{
  85 + $data[$platform] = $geoQuestionResModel->counts(['project_id' => $item,'hit'=>['!=',0],'platform'=>$platform,'created_at' => ['between',[$start,$end]]]);
  86 + }
  87 + }
  88 + $info = $geoCountModel->read(['project_id' => $item,'date'=>$date]);
  89 + if($info === false){
  90 + //新增一条数据
  91 + $geoCountModel->addReturnId($data);
  92 + }else{
  93 + $geoCountModel->edit($data,['id'=>$info['id']]);
  94 + }
  95 + }
  96 + }
  97 +
  98 + return true;
  99 + }
  100 +
  101 + /**
  102 + * 输出日志
  103 + * @param $message
  104 + * @return bool
  105 + */
  106 + public function output($message)
  107 + {
  108 + echo date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
  109 + return true;
  110 + }
  111 +}
@@ -129,4 +129,16 @@ class GeoQuestionResController extends BaseController @@ -129,4 +129,16 @@ class GeoQuestionResController extends BaseController
129 $data = $this->logic->getLabelData(); 129 $data = $this->logic->getLabelData();
130 $this->response('success',Code::SUCCESS,$data); 130 $this->response('success',Code::SUCCESS,$data);
131 } 131 }
  132 +
  133 + /**
  134 + * @remark :根据项目获取
  135 + * @name :getPlatformCount
  136 + * @author :lyh
  137 + * @method :post
  138 + * @time :2025/10/14 10:43
  139 + */
  140 + public function getPlatformCount(){
  141 + $data = $this->logic->getPlatformCount();
  142 + $this->response('success',Code::SUCCESS,$data);
  143 + }
132 } 144 }
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 namespace App\Http\Logic\Bside\Geo; 10 namespace App\Http\Logic\Bside\Geo;
11 11
12 use App\Http\Logic\Bside\BaseLogic; 12 use App\Http\Logic\Bside\BaseLogic;
  13 +use App\Models\Geo\GeoCount;
13 use App\Models\Geo\GeoPlatform; 14 use App\Models\Geo\GeoPlatform;
14 use App\Models\Geo\GeoQuestion; 15 use App\Models\Geo\GeoQuestion;
15 use App\Models\Geo\GeoQuestionLog; 16 use App\Models\Geo\GeoQuestionLog;
@@ -200,4 +201,18 @@ class GeoQuestionResLogic extends BaseLogic @@ -200,4 +201,18 @@ class GeoQuestionResLogic extends BaseLogic
200 } 201 }
201 return $this->success($data); 202 return $this->success($data);
202 } 203 }
  204 +
  205 + /**
  206 + * @remark :获取图标数据
  207 + * @name :getPlatformCount
  208 + * @author :lyh
  209 + * @method :post
  210 + * @time :2025/10/14 10:45
  211 + */
  212 + public function getPlatformCount()
  213 + {
  214 + $geoCountModel = new GeoCount();
  215 + $lists = $geoCountModel->list(['project_id'=>$this->user['project_id']],'date',['*'],'desc',30);
  216 + return $this->success($lists);
  217 + }
203 } 218 }
@@ -766,6 +766,7 @@ Route::middleware(['bloginauth'])->group(function () { @@ -766,6 +766,7 @@ Route::middleware(['bloginauth'])->group(function () {
766 Route::any('/getCount', [\App\Http\Controllers\Bside\Geo\GeoQuestionResController::class, 'getCount'])->name('geo_result_getCount');//geo设置类型统计数量 766 Route::any('/getCount', [\App\Http\Controllers\Bside\Geo\GeoQuestionResController::class, 'getCount'])->name('geo_result_getCount');//geo设置类型统计数量
767 Route::any('/countQuantity', [\App\Http\Controllers\Bside\Geo\GeoQuestionResController::class, 'countQuantity'])->name('geo_result_countQuantity');//geo统计 767 Route::any('/countQuantity', [\App\Http\Controllers\Bside\Geo\GeoQuestionResController::class, 'countQuantity'])->name('geo_result_countQuantity');//geo统计
768 Route::any('/getSearchDate', [\App\Http\Controllers\Bside\Geo\GeoQuestionResController::class, 'getSearchDate'])->name('geo_result_getSearchDate');//搜索记录时间 768 Route::any('/getSearchDate', [\App\Http\Controllers\Bside\Geo\GeoQuestionResController::class, 'getSearchDate'])->name('geo_result_getSearchDate');//搜索记录时间
  769 + Route::any('/getPlatformCount', [\App\Http\Controllers\Bside\Geo\GeoQuestionResController::class, 'getPlatformCount'])->name('geo_result_getPlatformCount');//搜索记录时间
769 }); 770 });
770 }); 771 });
771 //无需登录验证的路由组 772 //无需登录验证的路由组