|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @remark :
|
|
|
|
* @name :HandleNewsText.php
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/11/8 9:14
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Console\Commands\Test;
|
|
|
|
|
|
|
|
use App\Services\CosService;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Models\Template\BTemplateCom;
|
|
|
|
use App\Services\ProjectServer;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class HandleNewsText extends Command
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'news_text';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'news_text';
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$projectModel = new Project();
|
|
|
|
$list = $projectModel->list(['delete_status'=>0,'type'=>['!=',0]]);
|
|
|
|
$data = [];
|
|
|
|
foreach ($list as $v){
|
|
|
|
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
|
|
|
|
ProjectServer::useProject($v['id']);
|
|
|
|
DB::statement('CREATE TABLE gl_news_copy AS SELECT * FROM gl_news');
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
}
|
|
|
|
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :处理text
|
|
|
|
* @name :handleText
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/11/7 17:20
|
|
|
|
*/
|
|
|
|
public function handleText($text){
|
|
|
|
$pattern = '/<img\s+[^>]*src=["\']([^"\']+)["\']/i';
|
|
|
|
$matches = [];
|
|
|
|
preg_match_all($pattern, $text, $matches);
|
|
|
|
$text = $this->saveBase64Images($matches[1],$text);
|
|
|
|
return $this->success($text);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :解码图片
|
|
|
|
* @name :saveBase64Images
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/11/7 16:52
|
|
|
|
*/
|
|
|
|
public function saveBase64Images($imageSources,&$text)
|
|
|
|
{
|
|
|
|
foreach ($imageSources as $src) {
|
|
|
|
if (preg_match('/^data:image\/(png|jpg|jpeg|gif);base64,/', $src, $match)) {
|
|
|
|
$imageType = $match[1]; // Image type (png, jpg, etc.)
|
|
|
|
$imageUrl = $this->manager_uploads($src,$imageType);
|
|
|
|
$text = str_replace($src, $imageUrl, $text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success($text);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @remark :自调用
|
|
|
|
* @name :manager_uploads
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/11/7 11:00
|
|
|
|
*/
|
|
|
|
public function manager_uploads($files,$type = 'png'){
|
|
|
|
$this->uploads = config('upload.default_image');
|
|
|
|
$path = $this->uploads['path_b'].'/'.($this->user['project_id'] ?? 1618).'/image_news/'.date('Y-m');
|
|
|
|
$cosService = new CosService();
|
|
|
|
$fileName = md5(uniqid() . '_' . time() . '.' . ($this->user['project_id'] ?? 1618).rand(1,10000)) . '.' .$type;
|
|
|
|
return getImageUrl($cosService->uploadFile($files,$path,$fileName));
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|