作者 lyh

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

... ... @@ -28,16 +28,16 @@ class ProjectFilePDF extends Command
*/
protected $description = '网站项目数据,生成PDF文件';
protected ProjectAssociation $AiccWechat;
protected $ProjectAssociation;
protected DataFile $DataFile;
protected $DataFile;
protected $time;
// 最大支持5个进程
public int $maxRunNumber = 50;
protected $fileController;
public FileController $fileController;
// 最大支持5个进程
public $maxRunNumber = 50;
/**
* Create a new command instance.
... ... @@ -46,7 +46,7 @@ class ProjectFilePDF extends Command
*/
public function __construct()
{
$this->AiccWechat = new ProjectAssociation();
$this->ProjectAssociation = new ProjectAssociation();
$this->DataFile = new DataFile();
$this->time = date("Y-m");
$this->fileController = new FileController();
... ... @@ -55,33 +55,38 @@ class ProjectFilePDF extends Command
public function start(): int
{
$status = 1; # 1 - 正常, 0 - 禁用
$is_pdf = 0; # 0 - 未生成 1 - 已生成 2 - 其它问题
$lists = $this->DataFile::query()->where('status', $status)
# 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('is_pdf', $is_pdf)->where('created_at', 'like', $this->time . '%')->first();
->where('created_at', 'like', $this->time . '%')->first();
if (is_null($lists)) {
$this->debug_echo('没有任务,等待中');
sleep(60);
sleep(30);
return 0;
}
$key = $this->signature . '-' . $lists->id;
$count = redis_get($key);
$item = $lists->getOriginal();
$project_id = $item->project_id;
$user_id = $item->user_id;
$friend_id = $item->friend_id;
$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 = json_encode($file_path['data']);
$isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
if (!$isRes) {
if ($count == 2) {
... ... @@ -99,6 +104,66 @@ class ProjectFilePDF extends Command
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
*/
public function savePDF($html, $filename)
{
... ... @@ -128,14 +193,13 @@ class ProjectFilePDF extends Command
// 获取PDF内容
$pdfContent = $dompdf->output();
$this->fileController->path = '/V6/PDF';
// 将PDF内容保存到文件
@file_put_contents($savePath, $pdfContent);
// 创建一个文件实例
$file = new File($savePath);
return $this->fileController->single($file);
return $this->fileController->api_upload_single($file);
}
/**
... ... @@ -148,7 +212,7 @@ class ProjectFilePDF extends Command
$html = '<html>';
$html .= '<body style="font-family:arial">';
$html .= '<h1>Hello, World!</h1>';
$html .= '<p>中文内容</p>';
$html .= '<p>中文内容ffffff</p>';
$html .= '</body>';
$html .= '</html>';
return $html;
... ...
... ... @@ -244,7 +244,7 @@ class ProjectUpdate extends Command
for ($i = 0; $i < count($item['category']); $i++) {
$return = $this->get_category_name_arr($item['category'], $pid);
if ($return) {
$category_arr[] = $return['name'];
$category_arr[] = $this->special2str($return['name']);
$pid = $return['id'];
}
}
... ...
<?php
namespace App\Console\Commands\Update;
use App\Helper\Arr;
use App\Http\Logic\Bside\Product\CategoryLogic;
use App\Models\Blog\Blog;
use App\Models\Collect\CollectTask;
use App\Models\Com\UpdateLog;
use App\Models\News\News;
use App\Models\Product\Category;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BCustomTemplate;
use App\Models\WebSetting\WebSettingReceiving;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
/**
* 4.0,5.0升级到6.0,内容同步
* Class ProjectImport
* @package App\Console\Commands
* @author Akun
* @date 2023/10/9 15:04
*/
class Temp extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'project_update_temp';
/**
* The console command description.
*
* @var string
*/
protected $description = '执行项目升级任务';
public function handle()
{
$this->start_update();
}
protected function start_update()
{
// $data = UpdateLog::where('project_id','<=',530)->where('api_type','category')->get();
$data = UpdateLog::where('project_id', '=', 298)->where('api_type', 'category')->get();
foreach ($data as $task) {
$project_id = $task->project_id;
$api_type = $task->api_type;
$api_url_arr = explode('?', $task->api_url);
$api_url = $api_url_arr[0];
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update start' . PHP_EOL;
//设置数据库
$project = ProjectServer::useProject($project_id);
if ($project) {
//分类
$url = $api_url . '?' . http_build_query(['w' => 'category']);
$data = curl_c($url);
if (isset($data['code']) && $data['code'] == 200) {
$items = $data['data'] ?? [];
$this->category_insert($project_id, $items, 0);
} else {
continue;
}
}
//关闭数据库
DB::disconnect('custom_mysql');
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL;
}
}
//获取地址路由
protected function get_url_route($url)
{
$arr = parse_url($url);
if (empty($arr['path'])) {
return '';
}
$path = $arr['path'];
if (strpos($path, '.') !== false) {
$path = substr($path, 0, strpos($path, '.'));
}
$path_arr = explode('/', $path);
return end($path_arr) ? end($path_arr) : $path_arr[count($path_arr) - 2];
}
//多级分类入库
protected function category_insert($project_id, $items, $pid = 0)
{
$model = new Category();
foreach ($items as $item) {
if ($item['name'] ?? '') {
$parent = $model->read(['pid' => $pid, 'title' => $item['name']], 'id');
if (!$parent) {
try {
$item['name'] = $this->special2str($item['name']);
$parent_id = $model->addReturnId([
'project_id' => $project_id,
'title' => $item['name'],
'pid' => $pid,
'keywords' => $item['keywords'] ?? '',
'describe' => $item['description'] ?? '',
'route' => $this->get_url_route($item['url'])
]);
$this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL;
continue;
}
} else {
$parent_id = $parent['id'];
}
if (!empty($item['children'])) {
$this->category_insert($project_id, $item['children'], $parent_id);
}
}
}
}
//获取分类名称数组
protected function get_category_name_arr($category, $pid = 0)
{
foreach ($category as $k => $v) {
if ($v['parent'] == $pid) {
return $v;
}
}
return [];
}
//特殊字符转换
protected function special2str($str)
{
if (strpos($str, ';') === false) {
return $str;
}
$list = [
'&lt;' => '<',
'&gt;' => '>',
'&amp;' => '&',
'&acute;' => '´',
'&quot;' => '“',
'&nbsp;' => ' '
];
foreach ($list as $k => $v) {
$str = str_replace($k, $v, $str);
}
return $str;
}
//路由入库
protected function set_map($route, $source, $source_id, $project_id)
{
if ($route) {
$route_map = RouteMap::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->first();
if (!$route_map) {
$route_map = new RouteMap();
$route_map->project_id = $project_id;
$route_map->source = $source;
$route_map->source_id = $source_id;
$route_map->route = $route;
if ($source == RouteMap::SOURCE_NEWS) {
$route_map->path = RouteMap::SOURCE_NEWS;
} elseif ($source == RouteMap::SOURCE_BLOG) {
$route_map->path = RouteMap::SOURCE_BLOG;
}
$route_map->save();
}
}
}
}
... ... @@ -69,7 +69,7 @@ class UpdateProgress extends Command
if(!empty($info)){
$info = (array)$info;
//超时时间
$time = date("Y-m-d H:i:s",strtotime($info['created_at']) + $info['total_num'] * 60);
$time = date("Y-m-d H:i:s",strtotime($info['created_at']) + $info['total_num'] * 30);
if($time > date("Y-m-d H:i:s")){
DB::connection('custom_mysql')->table('gl_update_progress')->where('id',$info['id'])->update(['current_num'=>$info['total_num']]);
//获取当前项目的用户
... ...
... ... @@ -24,12 +24,10 @@ class WebsiteData extends Command
protected $description = '向AICC推送数据';
// 最大支持5个进程
public int $maxRunNumber = 50;
public $maxRunNumber = 50;
protected $time;
protected $url;
/**
* Create a new command instance.
*
... ... @@ -38,10 +36,49 @@ class WebsiteData extends Command
public function __construct()
{
$this->time = date('Y-m');
$this->url = env('AICC_URL');
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
{
... ... @@ -53,26 +90,61 @@ class WebsiteData extends Command
->where('created_at', 'like', $this->time . '%')->first();
if (is_null($lists)) {
$this->debug_echo('没有任务,等待中');
sleep(60);
sleep(30);
return 0;
}
$key = $this->signature . '-' . $lists->id;
$count = redis_get($key);
$isRes = http_post($this->url, json_encode(['data' => $lists->getOriginal()]));
if (!$isRes) {
$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->is_pdf = 2;
$lists->status = 2;
$lists->save();
$this->debug_echo('项目文件数据推送失败! - 其他原因 - ' . $key);
$this->debug_echo('项目文件数据保存失败! - 其他原因 - ' . $key);
} else {
redis_add($key, $count + 1);
$this->debug_echo('项目文件数据推送失败! - ' . $key);
$this->debug_echo('项目文件数据保存失败! - ' . $key);
}
}
$lists->status = 1;
$lists->save();
$this->debug_echo('项目文件数据保存成功!');
$this->info('项目文件数据保存成功!');
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');
$msg = http_post($url, json_encode(compact('data')));
print_r($msg);
}
}
... ...
... ... @@ -107,8 +107,7 @@ class FileController
*/
public function single(&$files){
$hash = hash_file('md5', $files->getPathname());
// $name = $files->getClientOriginalName();
$name = $files->getFilename();
$name = $files->getClientOriginalName();
//查看文件是否存在
$fileModel = new File();
//查看图片是否已上传
... ... @@ -121,8 +120,7 @@ class FileController
return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path'], $name));
}
$url = $this->config['root'].$this->path;
// $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
$fileName = uniqid().rand(10000,99999).'.'.$files->getExtension();
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
//同步数据到cos
if($this->upload_location == 1){
$cosService = new CosService();
... ... @@ -138,6 +136,53 @@ class FileController
}
/**
* 接口上传单文件
* @param $files
* @return array
*/
public function api_upload_single(&$files)
{
$hash = hash_file('md5', $files->getPathname());
$name = $files->getFilename();
//查看文件是否存在
$fileModel = new File();
//查看图片是否已上传
$param = ['hash' => $hash, 'refer' => $this->param['refer'] ?? 0];
if (isset($this->cache['project_id']) && !empty($this->cache['project_id'])) {
$param['project_id'] = $this->cache['project_id'];
}
$file_hash = $fileModel->read($param);
if ($file_hash !== false) {
return [
'message' => '资源',
'code' => Code::SUCCESS,
'data' => $this->responseData($file_hash['path'], $name)
];
}
$url = $this->config['root'] . $this->path;
$fileName = uniqid() . rand(10000, 99999) . '.' . $files->getExtension();
//同步数据到cos
if ($this->upload_location == 1) {
$cosService = new CosService();
$cosService->uploadFile($files, $this->path, $fileName);
} else {
$res = $files->move($url, $fileName);
if ($res === false) {
return [
'message' => $files->getError(),
'code' => Code::USER_ERROR
];
}
}
$this->saveMysql($fileModel, $files->getSize(), $files->getExtension(), $fileName, $hash, $this->upload_location, $files->getMimeType(), $name);
return [
'message' => '资源',
'code' => Code::SUCCESS,
'data' => $this->responseData($this->path . '/' . $fileName, $name)
];
}
/**
* @remark :保存数据库
* @name :saveMysql
* @author :lyh
... ...
... ... @@ -16,13 +16,13 @@ class DataFile extends Base
if (!$isRes) {
$isRes = new self();
$isRes->project_id = $project_id;
}
# AICC用户ID
$isRes->user_id = $data['user_id'];
# 第三方朋友ID
$isRes->friend_id = $data['friend_id'];
# 生成文件路径
$isRes->file_path = $data['file_path'];
}
return $isRes->save();
}
... ...
... ... @@ -109,6 +109,13 @@ class RouteMap extends Base
}
try {
$route_map = self::where('project_id', $project_id)->where('source_id', $source_id)->where('source', $source)->first();
//上线项目 不能修改链接了
// if($route_map){
// $project = ProjectLogic::instance()->getInfo($project_id);
// if($project['type'] !== Project::STATUS_ONE){
// return $route_map->route;
// }
// }
if(!$route_map){
$route_map = new self();
$route_map->source = $source;
... ...
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
... ...