作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
/**
* TODO:: 如果想要在终止 任务时不让数据丢失或者异常,请使用此类
* @author:dc
* @time 2023/8/21 11:03
* Class CmdSignal
* @package App\Console\Commands
*/
trait CmdSignal
{
/**
* 是否停止
* @var bool
*/
public $isStop = false;
/**
* 超时未退出,强制退出 暂时未实现
* @var int
*/
public $stopTimeOut = 30;
public $debugLogFile = null;
/**
* 调试输出
* @param $msg
* @author:dc
* @time 2023/8/21 11:22
*/
public function debug_echo($msg){
if($this->debugLogFile){
@file_put_contents($this->debugLogFile,date('Y-m-d H:i:s')." ===> ".print_r($msg,1).PHP_EOL,FILE_APPEND);
}else{
echo date('Y-m-d H:i:s')." ===> ".print_r($msg,1).PHP_EOL;
}
}
/**
* @return bool
*/
public function handle()
{
if($this->isRunning()){
$this->debug_echo('脚本已运行,请无重复运行');
return 1;
}
$this->debug_echo('已启动脚本');
// 启动时
if(method_exists($this,'init')){
$this->init();
}
// 注册信号处理程序
// SIGHUP:终端控制进程时终止或挂起进程
//SIGINT:中断进程(通常由CTRL+C发出)
//SIGQUIT:退出进程并生成核心转储
//SIGILL:非法指令
//SIGABRT:由调试程序触发的异常终止信号
//SIGFPE:浮点异常
//SIGKILL:无条件终止进程
//SIGSEGV:无效的内存引用
//SIGPIPE:写入已关闭的FIFO或套接字时产生的信号
//SIGTERM:要求终止进程的信号
//SIGUSR1:用户定义的信号1
//SIGUSR2:用户定义的信号2
$handler = function ($signal){
// 可以处理其他程序
$this->isStop = true;
};
pcntl_signal(SIGTERM, $handler);
pcntl_signal(SIGINT, $handler);
// pcntl_signal(SIGHUP, $handler);
// 检查是否接收到信号
pcntl_signal_dispatch();
$tryNum = 0;
// 无限循环,模拟进程运行
while (true) {
// 做一些工作... 异常超过5次就重启下进程
if($this->isStop || $tryNum>5){
break;
}
try {
$this->start();
}catch (\Throwable $e){
$tryNum++;
// 保证此程序正常
$this->debug_echo('异常消息:'.$e->getMessage());
$this->debug_echo('异常文件:'.$e->getFile().':'.$e->getLine());
$this->debug_echo($e->getTraceAsString());
}
}
$this->debug_echo('已退出程序');
return Command::SUCCESS;
}
/**
* 获取进程启动名称
* @return mixed
* @throws \Exception
* @author:dc
* @time 2023/8/21 11:43
*/
public function getSignature(){
if(empty($this->signature)){
throw new \Exception('无法获取到启动命令');
}
return $this->signature;
}
/**
* 是否已运行
* @param int $max 最大运行多少进程
* @return bool
* @throws \Exception
* @author:dc
* @time 2023/8/21 11:54
*/
public function isRunning($max=1):bool {
$ps = "ps -ef | grep \"artisan ".$this->getSignature()."\" | grep -v grep | wc -l";
$num = exec($ps);
if(property_exists($this,'maxRunNumber')){
$max = $this->maxRunNumber;
}
if($num>$max){
return true;
}
return false;
}
}
... ...
... ... @@ -2,14 +2,19 @@
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;
use Illuminate\Http\File;
class ProjectFilePDF extends Command
{
use CmdSignal;
/**
* The name and signature of the console command.
*
... ... @@ -24,12 +29,19 @@ class ProjectFilePDF extends Command
*/
protected $description = '网站项目数据,生成PDF文件';
protected $AiccWechat;
protected $ProjectAssociation;
protected $DataFile;
protected $time;
protected $fileController;
protected $CosService;
// 最大支持5个进程
public $maxRunNumber = 50;
/**
* Create a new command instance.
*
... ... @@ -37,81 +49,90 @@ class ProjectFilePDF extends Command
*/
public function __construct()
{
$this->AiccWechat = new ProjectAssociation();
$this->ProjectAssociation = new ProjectAssociation();
$this->DataFile = new DataFile();
$this->time = date("Y-m-d");
$this->time = date("Y-m");
$this->fileController = new FileController();
$this->CosService = new CosService();
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
public function start(): int
{
$data = $this->get_data();
# 详细数据
$items = $data['items'];
# 总分页
$totalPage = $data['totalPage'];
$this->dataPush($items);
if ($totalPage > 1) {
for ($page = 2; $page <= $totalPage; $page++) {
$da = $this->get_data();
$this->dataPush($da['items']);
}
}
$this->info('生成pdf完成');
# 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->debug_echo('没有任务,等待中');
sleep(30);
return 0;
}
$key = $this->signature . '-' . $lists->id;
$count = redis_get($key);
/**
* 数据生成并保存
* @param array $items
* @return void
*/
public function dataPush(array $items)
{
foreach ($items as $item) {
$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);
$this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
if (empty($file_path)) {
$this->debug_echo('pdf生成失败!');
return 0;
}
$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_set($key, $count + 1);
$this->debug_echo('项目文件数据保存失败! - ' . $key);
}
public function get_data($page = 1, $perPage = 20)
{
$data = $this->AiccWechat->allData($page, $perPage);
# 总条数
$total = $data['total'];
if (empty($total)) {
$this->error('暂无绑定AICC微信数据');
return 0;
}
# 详细数据
$items = $data['items'];
# 总分页
$totalPage = $data['totalPage'];
# 当前页
$currentPage = $data['currentPage'];
return compact('total', 'items', 'totalPage', 'currentPage');
$lists->is_pdf = 1;
$lists->save();
$this->info('项目文件数据保存成功!');
return 0;
}
/**
* @param $html
* @param $filename
* @return string
*/
public function savePDF($html, $filename)
{
$pdf_path = public_path('PDF/');
if (!file_exists($pdf_path)) {
mkdir($pdf_path, 0777, true);
}
// 指定保存路径和文件名
$savePath = $pdf_path . $filename . '.pdf';
if (file_exists($savePath)) {
echo '文件已经存在';
// return 0;
}
// todo 生成中文有问题
# 实例化并使用dompdf类
$options = new Options();
$options->setDefaultFont('arial');
$dompdf = new Dompdf($options);
// $options = new Options();
// $options->setDefaultFont('arial');
// $dompdf = new Dompdf($options);
$dompdf = new Dompdf();
$dompdf->loadHtml($html);
#(可选)设置纸张大小和方向
$dompdf->setPaper('A4', 'landscape');
... ... @@ -121,15 +142,13 @@ class ProjectFilePDF extends Command
// 获取PDF内容
$pdfContent = $dompdf->output();
// 指定保存路径和文件名
$savePath = public_path('PDF/' . $filename . '.pdf');
$path = '/V6/PDF/' . $this->time;
// 将PDF内容保存到文件
file_put_contents($savePath, $pdfContent);
// 输出保存成功消息
return $savePath;
@file_put_contents($savePath, $pdfContent);
// 创建一个文件实例
$file = new File($savePath);
return $this->CosService->uploadFile($file, $path, $filename . '.pdf');
}
/**
... ... @@ -142,7 +161,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;
... ...
... ... @@ -7,6 +7,8 @@ use Illuminate\Console\Command;
class WebsiteData extends Command
{
use CmdSignal;
/**
* The name and signature of the console command.
*
... ... @@ -21,6 +23,11 @@ class WebsiteData extends Command
*/
protected $description = '向AICC推送数据';
// 最大支持5个进程
public $maxRunNumber = 50;
protected $time;
/**
* Create a new command instance.
*
... ... @@ -28,37 +35,53 @@ class WebsiteData extends Command
*/
public function __construct()
{
$this->time = date('Y-m');
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
public function start(): int
{
$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']);
# 0 - 未推送
# 1 - 已推送
# 2 - 其他问题
$status = 0;
$lists = DataFile::query()->where('status', $status)
->where('created_at', 'like', $this->time . '%')->first();
if (is_null($lists)) {
$this->debug_echo('没有任务,等待中');
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 = 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_set($key, $count + 1);
$this->debug_echo('项目文件数据保存失败! - ' . $key);
}
}
$this->info('项目文件数据推送完成!');
$lists->status = 1;
$lists->save();
$this->info('项目文件数据保存成功!');
return 0;
}
public function post_data($data)
{
$url = env('AICC_URL');
$msg = http_post("{$url}/api/save_file_data", json_encode(compact('data')));
$msg = http_post($url, json_encode(compact('data')));
print_r($msg);
}
... ...
... ... @@ -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文件
}
/**
... ...
... ... @@ -9,6 +9,7 @@ use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Carbon;
use App\Models\File\File;
use Illuminate\Support\Facades\Redis;
define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/');
/**
... ... @@ -616,3 +617,29 @@ function getRouteMap($source,$source_id){
}
return $route;
}
function redis_get($key){
return Redis::connection()->client()->get($key);
}
function redis_del(...$key){
return Redis::connection()->client()->del(...$key);
}
function redis_set($key,$val,$ttl=3600){
return Redis::connection()->client()->set($key,$val,$ttl);
}
/**
* 添加缓存,存在则失败
* @param $key
* @param $val
* @param int $ttl
* @return mixed
* @author:dc
* @time 2023/10/25 9:48
*/
function redis_add($key,$val,$ttl=3600){
return Redis::connection()->client()->eval(
"return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])", [$key, $val, $ttl], 1
);
}
... ...
... ... @@ -25,6 +25,9 @@ class KeywordPrefixController extends BaseController
*/
public function getKeywordPrefix(){
$keywordPrefixModel = new KeywordPrefix();
if(isset($this->map['project_id']) && !empty($this->map['project_id'])){
$this->map['project_id'] = ['in',[0,$this->map['project_id']]];
}
$list = $keywordPrefixModel->list($this->map);
$this->response('success',Code::SUCCESS,$list);
}
... ...
... ... @@ -33,9 +33,21 @@ class CNoticeController extends BaseController
/**
* 更新通知C端
* @param Request $request
* @param WebSettingLogic $webSettingLogic
* @return \Illuminate\Http\JsonResponse
*/
public function sendNotify(){
public function sendNotify(Request $request)
{
$url = $this->user['domain'].'api/update_page/';
$param = [
'project_id' => $this->user['project_id'],
'type' => intval($request->input('type', 1)),
'route' => intval($request->input('page', 1)),
'url' => $request->input('url', []),
'language'=> $request->input('language', []),
];
$result = http_post($url, json_encode($param));
return $this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!');
$updateProgressModel = new UpdateProgress();
$progressInfo = $updateProgressModel->formatQuery(['project_id'=>$this->user['project_id'],'type'=>$this->param['type']])->orderBy('id','desc')->first();
if((!empty($progressInfo))){
... ...
... ... @@ -24,7 +24,7 @@ class BlogController extends BaseController
* @time :2023/9/14 10:45
*/
public function lists(BlogModel $blogModel){
$filed = ['id','category_id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url','release_at'];
$filed = ['id','category_id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url','release_at','is_upgrade'];
$this->order = 'sort';
$query = $blogModel->orderBy($this->order ,'desc')->orderBy('id','desc');
$query = $this->searchParam($query);
... ...
... ... @@ -24,7 +24,7 @@ class NewsController extends BaseController
* @method
*/
public function lists(NewsModel $news){
$filed = ['id','category_id','operator_id','status','created_at','image','updated_at','name','sort','url', 'release_at'];
$filed = ['id','category_id','operator_id','status','created_at','image','updated_at','name','sort','url', 'release_at','is_upgrade'];
$this->order = 'sort';
$query = $news->orderBy($this->order ,'desc')->orderBy('id','desc');
$query = $this->searchParam($query);
... ... @@ -36,6 +36,7 @@ class NewsController extends BaseController
$user = new User();
foreach ($lists['list'] as $k => $v){
$v['category_name'] = $this->categoryName($v['category_id'],$data);
$v['seo_mate'] =
$v['url'] = $this->user['domain'].getRouteMap(RouteMap::SOURCE_NEWS,$v['id']);
$v['image_link'] = getImageUrl($v['image']);
$v['operator_name'] = $user->getName($v['operator_id']);
... ...
... ... @@ -43,7 +43,7 @@ class ProductController extends BaseController
public function index(Product $product)
{
$filed = ['id', 'project_id', 'title', 'sort' ,'thumb', 'gallery' ,'product_type' , 'route' ,
'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at'];
'category_id', 'keyword_id', 'status', 'created_uid', 'is_upgrade' ,'created_at', 'updated_at'];
$this->order = 'sort';
$query = $product->orderBy($this->order ,'desc')->orderBy('id','desc');
$query = $this->searchParam($query);
... ...
... ... @@ -3,8 +3,12 @@
namespace App\Http\Controllers\Bside\Setting;
use App\Enums\Common\Code;
use App\Helper\Translate;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Setting\ProofreadingLogic;
use App\Models\WebSetting\Proofreading;
use App\Models\WebSetting\WebSettingCountry;
use Illuminate\Support\Facades\DB;
class ProofreadingController extends BaseController
{
... ... @@ -16,18 +20,125 @@ class ProofreadingController extends BaseController
* @method :post
* @time :2023/6/12 10:52
*/
public function lists(ProofreadingLogic $proofreadingLogic){
//默认显示语言为英语
if(!isset($this->map['language_id']) || empty($this->map['language_id'])){
$this->map['language_id'] = $this::LANGUAGE_ID;
public function lists(){
//获取语种信息
$webSettingCountryModel = new WebSettingCountry();
$countryInfo = $webSettingCountryModel->read(['id'=>$this->param['language_id']]);
//获取当前链接和语种的校队列表
$proofreadingModel = new Proofreading();
$list = $proofreadingModel->list(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>1],'created_at',['text','translate']);
//获取当前URl的所有文本内容
$new_list = $this->getUrlRead($this->param['url']);
if(empty($list)){
$data = [];
$translate_list = Translate::tran($new_list, $countryInfo['alias']);
foreach ($new_list as $k=>$v){
$data[] = [
'text'=>trim($v),
'translate'=>$translate_list[$k],
];
}
$lists = $proofreadingLogic->proofreadingList($this->map,$this->page,$this->row);
if(!empty($lists['list']) && ($this->param['type'] == $this::TYPE_IMAGE)){
foreach ($lists['list'] as $k => $v){
$lists['list'][$k]['image_link'] = getImageUrl($v['translate']);
return $this->response('success',Code::SUCCESS,$data);
}
$data = [];//返回数据
$old_list = [];
foreach ($list as $v){
$old_list[] = $v['text'];
$data[] = [
'text'=>$v['text'],
'translate'=>$v['translate'],
];
}
$this->response('success',Code::SUCCESS,$lists);
$arr2 = array_values(array_diff($new_list, $old_list));
if(!empty($arr2)){
$translate_list = Translate::tran($arr2, $countryInfo['alias']);
foreach ($arr2 as $k1=>$v1){
$data[] = [
'text'=>$v1,
'translate'=>$translate_list[$k1]
];
}
}
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :获取图片列表
* @name :imageList
* @author :lyh
* @method :post
* @time :2023/11/23 17:29
*/
public function imageList(){
$proofreadingModel = new Proofreading();
$list = $proofreadingModel->list(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>2],'created_at',['text','translate']);
if(empty($list)){
$new_list = $this->getUrlImageRead($this->param['url']);
foreach ($new_list as $k=>$v){
$data[] = [
'text'=>$v,
'translate'=>$v,
];
}
return $this->response('success',Code::SUCCESS,$data);
}
$new_list = $this->getUrlImageRead($this->param['url']);
$data = [];//返回数据
$old_list = [];
foreach ($list as $v){
$old_list[] = $v['text'];
$data[] = [
'text'=>$v['text'],
'translate'=>$v['translate'],
];
}
$arr2 = array_values(array_diff($new_list, $old_list));
if(!empty($arr2)){
foreach ($arr2 as $v1){
$data[] = [
'text'=>$v1,
'translate'=>$v1
];
}
}
$this->response('success',Code::SUCCESS,$data);
}
/**
* @name :(新增/更新多语言)save
* @author :lyh
* @method :post
* @time :2023/6/12 10:52
*/
public function save(){
//清除以前的翻译校队数据,重新添加
$param = [
'type'=>1,
'project_id'=>$this->user['project_id'],
'url'=>$this->param['url'],
'language_id'=>$this->param['language_id'],
'alias'=>$this->param['alias'],
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
$proofreadingModel = new Proofreading();
DB::beginTransaction();
try {
$proofreadingModel->del(['language_id'=>$this->param['language_id'],'url'=>$this->param['url'],'type'=>1]);
//删除成功后,重新添加
$save_data = [];
foreach ($this->param['data'] as $k => $v){
$param['text'] = $v['text'];
$param['translate'] = $v['translate'];
$save_data[] = $param;
}
$proofreadingModel->insert($save_data);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('系统错误请联系管理员');
}
$this->response('success');
}
/**
... ... @@ -36,8 +147,34 @@ class ProofreadingController extends BaseController
* @method :post
* @time :2023/6/12 10:52
*/
public function save(ProofreadingLogic $proofreadingLogic){
$proofreadingLogic->proofreadingSave();
public function saveImage(){
//清除以前的翻译校队数据,重新添加
$param = [
'type'=>2,
'project_id'=>$this->user['project_id'],
'url'=>$this->param['url'],
'language_id'=>$this->param['language_id'],
'alias'=>$this->param['alias'],
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
$proofreadingModel = new Proofreading();
DB::beginTransaction();
try {
$proofreadingModel->del(['language_id'=>$this->param['language_id'],'url'=>$this->param['url'],'type'=>2]);
//删除成功后,重新添加
$save_data = [];
foreach ($this->param['data'] as $k => $v){
$param['text'] = $v['text'];
$param['translate'] = $v['translate'];
$save_data[] = $param;
}
$proofreadingModel->insert($save_data);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('系统错误请联系管理员');
}
$this->response('success');
}
... ... @@ -60,8 +197,68 @@ class ProofreadingController extends BaseController
* @time :2023/11/22 10:02
*/
public function getUrlRead($url){
$sourceCode = file_get_contents($url);
$strippedContent = strip_tags($sourceCode); // 删除所有HTML标签
var_dump($strippedContent);
$contextOptions = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
];
$context = stream_context_create($contextOptions);
$sourceCode = file_get_contents($url, false, $context);
$pattern = '/<style\b[^>]*>(.*?)<\/style>/s'; // 定义匹配`<style>`标签及其内容的正则表达式
$strippedContent = preg_replace($pattern, '', $sourceCode); // 删除`<style>`标签及其内容
$pattern = '/<script\b[^>]*>(.*?)<\/script>/s'; // 定义匹配`<script>`标签及其内容的正则表达式
$strippedContent = preg_replace($pattern, '', $strippedContent); // 删除`<script>`标签及其内容
$pattern = '/<link\b[^>]*>/'; // 定义匹配 `<link>` 标签的正则表达式
$strippedContent = preg_replace($pattern, '', $strippedContent); // 删除 `<link>` 标签
$pattern = '/<footer\b[^>]*>(.*?)<\/footer>/s'; // 定义匹配`<script>`标签及其内容的正则表达式
$strippedContent = preg_replace($pattern, '', $strippedContent); // 删除`<script>`标签及其内容
$pattern = '/>([^<]+)</'; // 定义匹配中间内容不是标签的正则表达式
$matches = array();
preg_match_all($pattern, $strippedContent, $matches);
$textContentArray = array_filter($matches[1], function($item) {
return !empty(trim($item));
});
$data = [];
foreach ($textContentArray as $v){
$content = trim($v);
$trimmedString = preg_replace('/\s+/', ' ', $content);
$data[] = $trimmedString;
}
$data = array_values($data);
$uniqueArray = array_unique($data);
$data = array_values($uniqueArray);
return $data;
}
/**
* @remark :获取Url内容
* @name :getUrlRead
* @author :lyh
* @method :post
* @time :2023/11/22 10:02
*/
public function getUrlImageRead($url){
$contextOptions = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
];
$pattern = '/<img.*?src="(.*?)".*?>/i';
$matches = array();
$context = stream_context_create($contextOptions);
$sourceCode = file_get_contents($url, false, $context);
preg_match_all($pattern, $sourceCode, $matches);
$textContentArray = $matches[1];
$data = [];
foreach ($textContentArray as $v){
if(!empty($v)){
$data[] = $v;
}
}
$uniqueArray = array_unique($data);
$data = array_values($uniqueArray);
return $data;
}
}
... ...
... ... @@ -12,7 +12,6 @@ namespace App\Http\Controllers\Bside\Template;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\BTemplate\VisualizationLogic;
use App\Models\Visualization\Visualization;
/**
* @remark :定制项目处理
... ...
... ... @@ -132,7 +132,54 @@ class FileController
}
}
$this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType(),$name);
return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
$this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
}
/**
* 接口上传单文件
* @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)
];
}
/**
... ...
... ... @@ -380,12 +380,12 @@ class ImageController extends Controller
if(is_array($files)){
foreach ($files as $file){
if ($file->getSize() > $max) {
return $this->response('图片最大为500K',Code::SYSTEM_ERROR);
$this->response('图片最大为500K',Code::SYSTEM_ERROR);
}
}
}else{
if ($files->getSize() > $max) {
return $this->response('图片最大为500K',Code::SYSTEM_ERROR);
$this->response('图片最大为500K',Code::SYSTEM_ERROR);
}
}
if(!isset($this->param['upload_method'])){
... ...
... ... @@ -402,16 +402,16 @@ class VisualizationLogic extends BaseLogic
'template_id' => $template_id,
'project_id' => $this->user['project_id']
];
if ($source == 2) {//产品页
if ($source == BTemplate::SOURCE_PRODUCT) {//产品页
if($source_id != 0){$data['type'] = 2;if ($pageInfo['product_details'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}
else {$data['type'] = 3;if ($pageInfo['product_list'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}}
if ($source == 3) {//博客页
if ($source == BTemplate::SOURCE_BLOG) {//博客页
if ($source_id != 0) {$data['type'] = 4;if ($pageInfo['blog_details'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}
else {$data['type'] = 5;if ($pageInfo['blog_list'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}}
if ($source == 4) {//新闻页
if ($source == BTemplate::SOURCE_NEWS) {//新闻页
if ($source_id != 0) {$data['type'] = 6;if ($pageInfo['news_details'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}
else {$data['type'] = 7;if ($pageInfo['news_list'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}}
if ($source == 5) {//聚合页
if ($source == BTemplate::SOURCE_KEYWORD) {//聚合页
$data['type'] = 8;if ($pageInfo['polymerization'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}
}
}
... ...
... ... @@ -218,6 +218,8 @@ class ProductLogic extends BaseLogic
$param['icon'][$k1] = str_replace_url($v1);
}
$param['icon'] = Arr::a2s($param['icon'] ?? []);
}else{
$param['icon'] = Arr::a2s([]);
}
$param['created_uid'] = $this->user['id'];
return $param;
... ...
... ... @@ -19,18 +19,6 @@ class ProofreadingLogic extends BaseLogic
}
/**
* @name :(校队列表)proofreadingList
* @author :lyh
* @method :post
* @time :2023/6/12 11:06
*/
public function proofreadingList($map,$p,$row,$order = 'created_at',$filed = ['*']){
$map['project_id'] = $this->user['project_id'];
$list = $this->model->lists($map,$p,$row,$order,$filed);
return $this->success($list);
}
/**
* @name :(保存翻译校队)proofreadingSave
* @author :lyh
* @method :post
... ...
... ... @@ -200,6 +200,7 @@ class UserLoginLogic
$info['is_upload_manage'] = $project['is_upload_manage'];
$info['upload_config'] = $project['upload_config'];
$info['image_max'] = $project['image_max'];
$info['is_update_language'] = $project['is_update_language'];
$info['configuration'] = $project['deploy_build']['configuration'];
$info['type'] = $project['type'];
if($info['is_customized'] == 1){
... ...
... ... @@ -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();
}
... ...
... ... @@ -55,9 +55,9 @@ class ProjectAssociation extends Model
{
$status = 1; # 1 - 正常, 0 - 禁用
$lists = self::query()->where('status', $status)
->whereNotNull('project_id')
->whereNotNull('friend_id')
->whereNotNull('user_id')
->where('project_id', '!=', 0)
->where('friend_id', '!=', 0)
->where('user_id', '!=', 0)
->paginate($perPage, ['project_id', 'friend_id', 'user_id'], 'page', $page);
$items = $lists->Items();
$totalPage = $lists->lastPage();
... ...
... ... @@ -19,14 +19,14 @@ class BTemplate extends Base
const SOURCE_KEYWORD = 5;//聚合页
const STATUS = 0;
const TYPE_ONE = 0;
const TYPE_TWO = 0;
const TYPE_THREE = 0;
const TYPE_FOUR = 0;
const TYPE_FIVE = 0;
const TYPE_SIX = 0;
const TYPE_SEVEN = 0;
const TYPE_ = 0;
const TYPE_ONE = 1;
const TYPE_TWO = 2;
const TYPE_THREE = 3;
const TYPE_FOUR = 4;
const TYPE_FIVE = 5;
const TYPE_SIX = 6;
const TYPE_SEVEN = 7;
const TYPE_EIGHT = 8;
protected $table = 'gl_web_template';
//连接数据库
... ...
... ... @@ -19,7 +19,8 @@
"mongodb/mongodb": "^1.6",
"mrgoon/aliyun-sms": "^2.0",
"phpoffice/phpspreadsheet": "^1.28",
"swooletw/laravel-swoole": "^2.13"
"swooletw/laravel-swoole": "^2.13",
"qcloud/cos-sdk-v5": "^v2.6.6"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.13",
... ...
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]
... ...
... ... @@ -167,7 +167,9 @@ Route::middleware(['bloginauth'])->group(function () {
//翻译校队
Route::prefix('proofreading')->group(function () {//languageList
Route::any('/', [\App\Http\Controllers\Bside\Setting\ProofreadingController::class, 'lists'])->name('web_proofreading_lists');
Route::any('/imageList', [\App\Http\Controllers\Bside\Setting\ProofreadingController::class, 'imageList'])->name('web_proofreading_imageList');
Route::any('/save', [\App\Http\Controllers\Bside\Setting\ProofreadingController::class, 'save'])->name('web_proofreading_save');
Route::any('/saveImage', [\App\Http\Controllers\Bside\Setting\ProofreadingController::class, 'saveImage'])->name('web_proofreading_saveImage');
Route::any('/languageList', [\App\Http\Controllers\Bside\Setting\ProofreadingController::class, 'languageList'])->name('web_proofreading_languageList');
});
... ...