作者 lyh

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

... ... @@ -5,6 +5,7 @@ namespace App\Console\Commands;
use App\Http\Controllers\File\FileController;
use App\Models\ProjectAssociation\ProjectAssociation;
use App\Models\File\DataFile;
use App\Services\CosService;
use Dompdf\Dompdf;
use Dompdf\Options;
use Illuminate\Console\Command;
... ... @@ -36,6 +37,8 @@ class ProjectFilePDF extends Command
protected $fileController;
protected $CosService;
// 最大支持5个进程
public $maxRunNumber = 50;
... ... @@ -50,6 +53,7 @@ class ProjectFilePDF extends Command
$this->DataFile = new DataFile();
$this->time = date("Y-m");
$this->fileController = new FileController();
$this->CosService = new CosService();
parent::__construct();
}
... ... @@ -86,83 +90,28 @@ class ProjectFilePDF extends Command
$this->debug_echo('pdf生成失败!');
return 0;
}
$file_path = json_encode($file_path['data']);
$isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
$isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
if (!$isRes) {
if ($count == 2) {
$lists->is_pdf = 2;
$lists->save();
$this->debug_echo('项目文件数据保存失败! - 其他原因 - ' . $key);
} else {
redis_add($key, $count + 1);
redis_set($key, $count + 1);
$this->debug_echo('项目文件数据保存失败! - ' . $key);
}
}
$lists->is_pdf = 1;
$lists->save();
$this->debug_echo('项目文件数据保存成功!');
$this->info('项目文件数据保存成功!');
return 0;
}
/**
* Execute the console command.
*
* @return int
*/
// public function handle()
// {
// # 0 - 未生成
// # 1 - 已生成
// # 2 - 其它问题
// $is_pdf = 0;
// $lists = $this->ProjectAssociation::query()->where('is_pdf', $is_pdf)
// ->where('project_id', '!=', 0)
// ->where('friend_id', '!=', 0)
// ->where('user_id', '!=', 0)
// ->where('created_at', 'like', $this->time . '%')->first();
//
// if (is_null($lists)) {
// $this->error('没有任务,等待中');
// sleep(60);
// return 0;
// }
// $key = $this->signature . '-' . $lists->id;
// $count = redis_get($key);
// $project_id = $lists->project_id;
// $user_id = $lists->user_id;
// $friend_id = $lists->friend_id;
// // todo 根据项目查询数据
// $project_data = [];
// $html = $this->html($project_data);
// $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
//
// $file_path = $this->savePDF($html, $filename);
// if (empty($file_path)) {
// $this->debug_echo('pdf生成失败!');
// return 0;
// }
// $file_path = $file_path['data'];
// $isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
// if (!$isRes) {
// if ($count == 2) {
// $lists->status = 2;
// $lists->save();
// $this->error('项目文件数据保存失败! - 其他原因 - ' . $key);
// } else {
// redis_add($key, $count + 1);
// $this->error('项目文件数据保存失败! - ' . $key);
// }
// }
// $lists->status = 1;
// $lists->save();
// $this->info('项目文件数据保存成功!');
// return 0;
// }
/**
* @param $html
* @param $filename
* @return array
* @return string
*/
public function savePDF($html, $filename)
{
... ... @@ -192,14 +141,14 @@ class ProjectFilePDF extends Command
$dompdf->render();
// 获取PDF内容
$pdfContent = $dompdf->output();
$this->fileController->path = '/V6/PDF';
$pdfContent = $dompdf->output();
$path = '/V6/PDF/' . $this->time;
// 将PDF内容保存到文件
@file_put_contents($savePath, $pdfContent);
// 创建一个文件实例
$file = new File($savePath);
return $this->fileController->api_upload_single($file);
return $this->CosService->uploadFile($file, $path, $filename . '.pdf');
}
/**
... ...
... ... @@ -243,10 +243,12 @@ class HtmlCollect extends Command
$path = $arr['path'] ?? '';
$query = $arr['query'] ?? '';
$path_arr = explode('.', $path);
if (
(empty($host) || $host == $web_url_domain || $host == $home_url)
&& $path
&& (strpos($path, '.') !== false)
&& (end($path_arr) != 'html')
) {
$source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first();
if (!$source) {
... ...
... ... @@ -250,10 +250,12 @@ class HtmlLanguageCollect extends Command
$path = $arr['path'] ?? '';
$query = $arr['query'] ?? '';
$path_arr = explode('.', $path);
if (
(empty($host) || $host == $web_url_domain || $host == $home_url)
&& $path
&& (strpos($path, '.') !== false)
&& (end($path_arr) != 'html')
) {
$source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first();
if (!$source) {
... ...
... ... @@ -39,47 +39,6 @@ class WebsiteData extends Command
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
// public function handle()
// {
// # 0 - 未推送
// # 1 - 已推送
// # 2 - 其他问题
// $status = 0;
// $lists = DataFile::query()->where('status', $status)
// ->where('created_at', 'like', $this->time . '%')->first();
// if (is_null($lists)) {
// $this->error('没有任务,等待中');
// sleep(30);
// return 0;
// }
//
// $key = $this->signature . '-' . $lists->id;
// $count = redis_get($key);
// $data = $lists;
//
// $url = env('AICC_URL');
// $msg = http_post($url, json_encode(compact('data')));
// $status_code = $msg['status'];
// if ($status_code != 200) {
// if ($count == 2) {
// $lists->status = 2;
// $lists->save();
// $this->error('项目文件数据保存失败! - 其他原因 - ' . $key);
// } else {
// redis_add($key, $count + 1);
// $this->error('项目文件数据保存失败! - ' . $key);
// }
// }
// $lists->status = 1;
// $lists->save();
// return 0;
// }
public function start(): int
{
# 0 - 未推送
... ... @@ -99,14 +58,17 @@ class WebsiteData extends Command
$data = $lists;
$url = env('AICC_URL');
$msg = http_post($url, json_encode(compact('data')));
$status_code = $msg['status'];
$status_code = 0;
if ($msg) {
$status_code = (int)$msg['status'];
}
if ($status_code != 200) {
if ($count == 2) {
$lists->status = 2;
$lists->save();
$this->debug_echo('项目文件数据保存失败! - 其他原因 - ' . $key);
} else {
redis_add($key, $count + 1);
redis_set($key, $count + 1);
$this->debug_echo('项目文件数据保存失败! - ' . $key);
}
}
... ... @@ -116,30 +78,6 @@ class WebsiteData extends Command
return 0;
}
/**
* Execute the console command.
*
* @return int
*/
// public function handle()
// {
// $DataFile = new DataFile();
// $data = $DataFile->allData();
// # 详细数据
// $items = $data['items'];
// # 总分页
// $totalPage = $data['totalPage'];
// $this->post_data($items);
// if ($totalPage > 1) {
// for ($page = 2; $page <= $totalPage; $page++) {
// $da = $DataFile->allData($page);
// $this->post_data($da['items']);
// }
// }
// $this->info('项目文件数据推送完成!');
// return 0;
// }
public function post_data($data)
{
$url = env('AICC_URL');
... ...
... ... @@ -38,8 +38,8 @@ class Kernel extends ConsoleKernel
$schedule->command('last_inquiry')->dailyAt('04:00')->withoutOverlapping(1);// 最近一次询盘信息
$schedule->command('update_progress')->everyThirtyMinutes()->withoutOverlapping(1);//监控更新
$schedule->command('update_seo_tdk_crontab')->dailyAt('00:00')->withoutOverlapping(1); //更新上线项目TDK
$schedule->command('website_data')->everyMinute()->withoutOverlapping(1); // 向AICC推送数据
$schedule->command('project_file_pdf')->everyMinute()->withoutOverlapping(1); // 网站项目数据,生成PDF文件
$schedule->command('website_data')->dailyAt('01:00')->withoutOverlapping(1); // 向AICC推送数据
$schedule->command('project_file_pdf')->dailyAt('00:00')->withoutOverlapping(1); // 网站项目数据,生成PDF文件
}
/**
... ...
... ... @@ -11,6 +11,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\Project\ProjectUpdateTdk;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
... ... @@ -41,4 +42,20 @@ class UpdateController extends BaseController
ProjectUpdateTdk::add_task($this->param['project_id']);
$this->response('任务添加成功');
}
/**
* 采集项目所有内容
* @author Akun
* @date 2023/11/24 11:33
*/
public function dataCollect(){
$this->request->validate([
'project_id'=>'required',
],[
'project_id.required' => 'project_id不能为空',
]);
UpdateLog::updateLog($this->param['project_id']);
$this->response('任务添加成功');
}
}
... ...
... ... @@ -33,10 +33,32 @@ class UpdateLog extends Model
$log->project_id = $project_id;
$log->api_type = $type;
$log->api_url = $url;
$log->sort = $type == 'category' ? 0 :1;
$log->sort = $type == 'category' ? 0 : 1;
$log->collect_status = ($type == 'category' || $type == 'website_info') ? 1 : 0;
return $log->save();
}
return true;
}
/**
* 重置更新日志
* @param $project_id
* @return bool
* @author Akun
* @date 2023/11/24 11:43
*/
public static function updateLog($project_id)
{
$logs = self::where('project_id', $project_id)->get();
foreach ($logs as $log) {
$log->status = 0;
if (!in_array($log->api_type, ['website_info', 'category'])) {
$log->collect_status = 0;
}
$log->save();
}
return true;
}
}
... ...
... ... @@ -182,6 +182,8 @@ Route::middleware(['aloginauth'])->group(function () {
});
//更新项目tdk
Route::any('/updateSeoTdk', [Aside\Com\UpdateController::class, 'updateSeoTdk'])->name('admin.project_updateSeoTdk');
//项目内容采集
Route::any('/dataCollect', [Aside\Com\UpdateController::class, 'dataCollect'])->name('admin.project_dataCollect');
});
//续费
... ...