作者 lyh

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

... ... @@ -138,7 +138,7 @@ class HtmlCollect extends Command
}
$update_log = UpdateLog::where('status', UpdateLog::STATUS_COM)->where('collect_status', UpdateLog::COLLECT_STATUS_UN)->orderBy('project_id', 'asc')->first();
$update_log = UpdateLog::where('status', UpdateLog::STATUS_COM)->where('collect_status', UpdateLog::COLLECT_STATUS_UN)->orderBy('updated_at', 'asc')->first();
if (!$update_log) {
return false;
}
... ...
... ... @@ -527,7 +527,7 @@ class ProjectUpdate extends Command
return $task_id;
}
$task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('sort', 'asc')->orderBy('project_id', 'asc')->limit(20)->get();
$task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('sort', 'asc')->orderBy('updated_at', 'asc')->limit(20)->get();
if ($task_list->count() == 0) {
return false;
}
... ...
... ... @@ -18,7 +18,7 @@ class Kernel extends ConsoleKernel
// $schedule->command('inspire')->hourly();
$schedule->command('remain_day')->dailyAt('03:00')->withoutOverlapping(1); // 项目剩余服务时长
$schedule->command('rank_data_task')->everyMinute()->withoutOverlapping(1); // 排名数据更新任务
$schedule->command('rank_data')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据,每天凌晨执行一次
$schedule->command('rank_data')->dailyAt('07:00')->withoutOverlapping(1); // 排名数据,每天凌晨执行一次
$schedule->command('rank_data_speed')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据-测速数据,每周一凌晨执行一次
$schedule->command('rank_data_external_links')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据-外链,每周一凌晨执行一次
$schedule->command('rank_data_indexed_pages')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据-页面收录,每周一凌晨执行一次
... ...
... ... @@ -103,7 +103,7 @@ class QuanqiusouApi
Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取谷歌排名数据失败', $api_no, $e);
errorLog('获取谷歌排名数据失败', [$api_no], $e);
return false;
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2024/1/4
* Time: 16:25
*/
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
/**
* Class BaseController
* @package App\Http\Controllers\Api
*/
class BaseController extends Controller
{
/**
* @param array $data
* @param string $message
* @param int $status
* @return false|string
*/
protected function success($data = [], $message = 'success', $status = 200)
{
$array = compact('status', 'message', 'data');
return json_encode($array, JSON_UNESCAPED_UNICODE);
}
/**
* @param string $message
* @param int $status
* @param array $data
* @return false|string
*/
protected function error($message = 'error', $status = 400, $data = [])
{
$array = compact('status', 'message', 'data');
return json_encode($array, JSON_UNESCAPED_UNICODE);
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2024/01/04
* Time: 16:08
*/
namespace App\Http\Controllers\Api;
use App\Models\Visit\SyncSubmitTask;
use App\Models\Visit\Visit;
use Illuminate\Http\Request;
/**
* Class NoticeController
* @package App\Http\Controllers\Api
*/
class NoticeController extends BaseController
{
/**
* 网站引流
* FIXME 当前接口给内部引流用, 使用简易接口, 后期需要添加完整校验机制以及多数据接口
* @param Request $request
* @return false|string
*/
public function trafficVisit(Request $request)
{
$ip = $request->input('ip');
$url = $request->input('url');
$device_port = intval($request->input('device_port'));
$referrer_url = $request->input('referrer_url');
$user_agent = $request->input('user_agent');
if (empty($ip))
return $this->error('IP不能为空');
if (empty($url))
return $this->error('访问链接不能为空');
if (empty($user_agent))
return $this->error('请求头信息user_agent不能为空');
//
$url_array = parse_url($url);
$array = [
'ip' => $ip,
'domain' => $url_array['host'] ?? '',
'referer' => $referrer_url,
'user_agent' => $user_agent,
'data' => [
'url' => $url,
'domain' => empty($url_array['host']) ? '' : $url_array['scheme'] . '://' . $url_array['host'],
'device_port' => in_array($device_port, array_keys(Visit::deviceMap())) ? $device_port : Visit::DEVICE_PC,
'referrer_url' => $referrer_url
]
];
SyncSubmitTask::createTask($array, SyncSubmitTask::TYPE_VISIT);
return $this->success([]);
}
}
... ...
... ... @@ -12,6 +12,7 @@ namespace App\Http\Controllers\Aside\Com;
use App\Helper\Common;
use App\Http\Controllers\Bside\BaseController;
use App\Models\Com\UpdateLog;
use App\Models\Com\UpdateOldInfo;
use App\Models\Domain\DomainInfo;
use App\Models\Project\ProjectUpdateTdk;
use App\Services\ProjectServer;
... ... @@ -75,9 +76,25 @@ class UpdateController extends BaseController
$this->fail('非升级无法进行采集操作');
}
if ($this->param['test_domain']) {
$test_domain_arr = parse_url($this->param['test_domain']);
$this->param['test_domain'] = $test_domain_arr['host'] ?? '';
}
//查看项目是否已上线
$domain_info = DomainInfo::where('project_id', $this->param['project_id'])->first();
if ($domain_info && !$this->param['test_domain']) {
$this->fail('已上线项目需填写采集的测试站域名');
}
try {
DB::connection('custom_mysql')->statement("DELETE FROM `gl_collect_source` WHERE `origin` LIKE '%.css%' OR `origin` LIKE '%.js%'");
DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0 WHERE `language` = ''");
if ($domain_info) {
DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0,`domain` = '" . $this->param['test_domain'] . "' WHERE `language` = ''");
} else {
DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0 WHERE `language` = ''");
}
} catch (\Exception $e) {
errorLog('重新采集升级项目数据', $this->param, $e);
... ... @@ -87,9 +104,6 @@ class UpdateController extends BaseController
//关闭数据库
DB::disconnect('custom_mysql');
//查看项目是否已上线
$domain_info = DomainInfo::where('project_id', $this->param['project_id'])->first();
$update = ['collect_status' => 0];
if ($this->param['type'] == 2 && !$domain_info) {
$update['status'] = 0;
... ...
... ... @@ -371,7 +371,7 @@ class RankDataLogic extends BaseLogic
if (!$model || $model->updated_date != date('Y-m-d') || $force) {
$res = $api->getGoogleRank($api_no, 0, 7, $force);
if (!$res) {
throw new \Exception('接口数据获取失败');
throw new \Exception("接口数据获取失败,api_no:{$api_no}");
}
//收录数
$indexed_pages_num = $site_res[$api_no] ?? 0;
... ... @@ -384,7 +384,7 @@ class RankDataLogic extends BaseLogic
if (!$model || $model->updated_date != date('Y-m-d') || $force) {
$res = $api->getGoogleRank($api_no, 1, 7, $force);
if (!$res) {
throw new \Exception('接口数据获取失败');
throw new \Exception("接口数据获取失败,api_no:{$api_no},lang");
}
$data = [];
//不同的小语种取出来
... ...
... ... @@ -48,7 +48,7 @@ class CollectTask extends Base
];
if ($link_type > 0 && $language_list && in_array($url_arr['path'], $page_list)) {
$domain_arr = explode('.', $url_arr['host']);
$domain_arr = explode('.', $url_arr['host'] ?? $domain);
foreach ($language_list as $v_lan) {
if ($link_type == 1) {
//二级域名
... ... @@ -56,7 +56,7 @@ class CollectTask extends Base
$new_domain = implode('.', $domain_arr);
} else {
//二级目录
$new_domain = $url_arr['host'] . '/' . $v_lan;
$new_domain = $url_arr['host'] ?? $domain . '/' . $v_lan;
}
$data[] = [
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2024/1/5
* Time: 14:16
*/
namespace App\Models\Visit;
use App\Models\Base;
/**
* Class SyncSubmitTask
* @package App\Models\Visit
*/
class SyncSubmitTask extends Base
{
/**
* 表名
* @var string
*/
protected $table = 'gl_sync_submit_task';
const TYPE_INQUIRY = 'inquiry';
const TYPE_VISIT = 'visit';
/**
* @param $data
* @param string $type
* @return mixed
*/
public static function createTask($data, $type = self::TYPE_VISIT)
{
$task = new self();
$task->data = json_encode($data);
$task->type = $type;
$task->save();
return $task->id;
}
}
\ No newline at end of file
... ...
... ... @@ -20,10 +20,13 @@ class Visit extends Base
protected $connection = 'custom_mysql';
protected $appends = ['device_text'];
const DEVICE_PC = 1;
const DEVICE_MOBILE = 2;
public static function deviceMap(){
return [
1 => 'PC',
2 => '移动端'
self::DEVICE_PC => 'PC',
self::DEVICE_MOBILE => '移动端'
];
}
... ...
... ... @@ -17,3 +17,5 @@ use Illuminate\Support\Facades\Route;
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
Route::any('traffic_visit', [\App\Http\Controllers\Api\NoticeController::class, 'trafficVisit'])->name('api.traffic_visit');
\ No newline at end of file
... ...