|
...
|
...
|
@@ -9,6 +9,17 @@ |
|
|
|
|
|
|
|
namespace App\Console\Commands\ReplaceHtml;
|
|
|
|
|
|
|
|
use App\Models\Blog\Blog;
|
|
|
|
use App\Models\Blog\BlogCategory;
|
|
|
|
use App\Models\CustomModule\CustomModule;
|
|
|
|
use App\Models\CustomModule\CustomModuleCategory;
|
|
|
|
use App\Models\CustomModule\CustomModuleContent;
|
|
|
|
use App\Models\News\News;
|
|
|
|
use App\Models\News\NewsCategory;
|
|
|
|
use App\Models\Product\Category;
|
|
|
|
use App\Models\Product\Product;
|
|
|
|
use App\Models\RouteMap\RouteMap;
|
|
|
|
use App\Models\Template\BCustomTemplate;
|
|
|
|
use App\Models\Template\BTemplate;
|
|
|
|
use App\Models\Template\TemplateReplaceHtmlLog;
|
|
|
|
use App\Services\ProjectServer;
|
|
...
|
...
|
@@ -52,12 +63,16 @@ class ReplaceHtml extends Command |
|
|
|
$replaceHtmlModel = new TemplateReplaceHtml();
|
|
|
|
$replaceHtmlList = $replaceHtmlModel->list(['status'=>$replaceHtmlModel::STATUS]);
|
|
|
|
if(!empty($replaceHtmlList)){
|
|
|
|
foreach ($replaceHtmlList as $k => $v){
|
|
|
|
foreach ($replaceHtmlList as $v){
|
|
|
|
ProjectServer::useProject($v['project_id']);
|
|
|
|
echo '开始,任务id:'.$v['id'].PHP_EOL;
|
|
|
|
$this->createReplaceHtmlLog($v);
|
|
|
|
if($v['source'] == 9){//单页面
|
|
|
|
$count = $this->createReplacePageHtmlLog($v);
|
|
|
|
}else{
|
|
|
|
$count = $this->createReplaceHtmlLog($v);
|
|
|
|
}
|
|
|
|
//修改当前主任务状态为待执行
|
|
|
|
$replaceHtmlModel->edit(['status'=>$replaceHtmlModel::STATUS_START],['id'=>$v['id']]);
|
|
|
|
$replaceHtmlModel->edit(['status'=>$replaceHtmlModel::STATUS_START,'total_num'=>$count],['id'=>$v['id']]);
|
|
|
|
echo '结束'.PHP_EOL;
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
}
|
|
...
|
...
|
@@ -68,31 +83,28 @@ class ReplaceHtml extends Command |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :生成子任务
|
|
|
|
* @name :createReplaceHtmlLog
|
|
|
|
* @remark :生成单页面记录
|
|
|
|
* @name :createReplacePageHtmlLog
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/5/10 17:26
|
|
|
|
* @time :2024/5/13 11:40
|
|
|
|
*/
|
|
|
|
public function createReplaceHtmlLog($info){
|
|
|
|
//获取当前页面所有数据
|
|
|
|
public function createReplacePageHtmlLog($info){
|
|
|
|
$saveData = [];
|
|
|
|
$bTemplateModel = new BTemplate();
|
|
|
|
$condition = ['source'=>$info['source'],'template_id'=>$info['template_id'],'is_custom'=>$info['is_custom'],'is_list'=>$info['is_list']];
|
|
|
|
$bTemplateList = $bTemplateModel->list($condition,'id',['id','source_id']);
|
|
|
|
foreach ($bTemplateList as $v){
|
|
|
|
$customTemplateModel = new BCustomTemplate();
|
|
|
|
$list = $customTemplateModel->list(['status'=>BCustomTemplate::STATUS_ACTIVE]);
|
|
|
|
foreach ($list as $v){
|
|
|
|
$saveData[] = [
|
|
|
|
'replace_id'=>$info['id'],
|
|
|
|
'project_id'=>$info['project_id'],
|
|
|
|
'status'=>0,
|
|
|
|
'old_html'=>$info['old_html'],
|
|
|
|
'html'=>$info['html'],
|
|
|
|
'source'=>$info['source'],
|
|
|
|
'source_id'=>$info['source'] == 1 ? 0 : $v['source_id'],
|
|
|
|
'is_custom'=>$info['is_custom'],
|
|
|
|
'is_list'=>$info['is_list'],
|
|
|
|
'source'=>9,
|
|
|
|
'source_id'=>$v['id'],
|
|
|
|
'is_rollback'=>$info['is_rollback'],
|
|
|
|
'template_id'=>$info['template_id'],
|
|
|
|
'name'=>$v['name'],
|
|
|
|
'created_at'=>date('Y-m-d H:i:s'),
|
|
|
|
'updated_at'=>date('Y-m-d H:i:s')
|
|
|
|
];
|
|
...
|
...
|
@@ -101,8 +113,214 @@ class ReplaceHtml extends Command |
|
|
|
$templateHtmlLogModel = new TemplateReplaceHtmlLog();
|
|
|
|
$templateHtmlLogModel->insert($saveData);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return count($saveData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :生成子任务
|
|
|
|
* @name :createReplaceHtmlLog
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/5/10 17:26
|
|
|
|
*/
|
|
|
|
public function createReplaceHtmlLog($info){
|
|
|
|
$bTemplateModel = new BTemplate();
|
|
|
|
$condition = ['is_custom'=>$info['is_custom'], 'is_list'=>$info['is_list'], 'template_id'=>$info['template_id']];
|
|
|
|
if($info['source'] != 0){
|
|
|
|
$condition['source'] = $info['source'];
|
|
|
|
}
|
|
|
|
if($info['template_id'] != 0){
|
|
|
|
$condition['main_html'] = ['like','%'.trim($info['old_html']).'%'];
|
|
|
|
}else{
|
|
|
|
$condition['html'] = ['like','%'.trim($info['old_html']).'%'];
|
|
|
|
}
|
|
|
|
$bTemplateList = $bTemplateModel->list($condition);
|
|
|
|
$saveData = [];
|
|
|
|
foreach ($bTemplateList as $v){
|
|
|
|
$source_id = $v['source'] == 1 ? 0 : $v['source_id'];
|
|
|
|
$name = $this->getSourceName($v['source'],$source_id,$v['is_list'],$v['is_custom']);
|
|
|
|
$saveData[] = $this->saveData($info,$v,$source_id,$name);
|
|
|
|
}
|
|
|
|
if(!empty($saveData)){
|
|
|
|
$templateHtmlLogModel = new TemplateReplaceHtmlLog();
|
|
|
|
$templateHtmlLogModel->insert($saveData);
|
|
|
|
}
|
|
|
|
return count($saveData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :组装数据
|
|
|
|
* @name :saveData
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/5/13 11:29
|
|
|
|
*/
|
|
|
|
public function saveData($info,$v,$source_id,$name){
|
|
|
|
return [
|
|
|
|
'replace_id'=>$info['id'],
|
|
|
|
'project_id'=>$info['project_id'],
|
|
|
|
'status'=>0,
|
|
|
|
'old_html'=>$info['old_html'],
|
|
|
|
'html'=>$info['html'],
|
|
|
|
'source'=>$v['source'],
|
|
|
|
'source_id'=>$source_id,
|
|
|
|
'is_custom'=>$v['is_custom'],
|
|
|
|
'is_list'=>$v['is_list'],
|
|
|
|
'is_rollback'=>$info['is_rollback'],
|
|
|
|
'template_id'=>$info['template_id'],
|
|
|
|
'source_name'=>$name,
|
|
|
|
'created_at'=>date('Y-m-d H:i:s'),
|
|
|
|
'updated_at'=>date('Y-m-d H:i:s')
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :生成子任务获取对应数据id名称
|
|
|
|
* @name :getSourceName
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/5/13 10:47
|
|
|
|
*/
|
|
|
|
public function getSourceName($source,$source_id,$is_list,$is_custom){
|
|
|
|
if($is_custom == 1){//扩展模块
|
|
|
|
return $this->getCustomName($source,$source_id,$is_list);
|
|
|
|
}
|
|
|
|
if($source == BTemplate::SOURCE_HOME){
|
|
|
|
return '';
|
|
|
|
}elseif ($source == BTemplate::SOURCE_PRODUCT){
|
|
|
|
return $this->getProductName($source_id,$is_list);
|
|
|
|
}elseif ($source == BTemplate::SOURCE_BLOG){
|
|
|
|
return $this->getBlogName($source_id,$is_list);
|
|
|
|
}elseif ($source == BTemplate::SOURCE_NEWS){
|
|
|
|
return $this->getNewsName($source_id,$is_list);
|
|
|
|
}else {//单页面管理
|
|
|
|
return $this->getPageName($source_id);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取单页面名称
|
|
|
|
* @name :getPageName
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/5/13 11:10
|
|
|
|
*/
|
|
|
|
public function getPageName($source_id){
|
|
|
|
$customTemplateModel = new BCustomTemplate();
|
|
|
|
$info = $customTemplateModel->read(['id'=>$source_id]);
|
|
|
|
if($info === false){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return $info['name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取新闻名称
|
|
|
|
* @name :getNewsName
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/5/13 11:07
|
|
|
|
*/
|
|
|
|
public function getNewsName($source_id,$is_list){
|
|
|
|
if($is_list == BTemplate::IS_LIST){
|
|
|
|
$cateModel = new NewsCategory();
|
|
|
|
$cateInfo = $cateModel->read(['id'=>$source_id]);
|
|
|
|
if($cateInfo === false){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$name = $cateInfo['name'];
|
|
|
|
}else{
|
|
|
|
$newsModel = new News();
|
|
|
|
$newsInfo = $newsModel->read(['id'=>$source_id]);
|
|
|
|
if($newsInfo === false){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$name = $newsInfo['name'];
|
|
|
|
}
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取blog名称
|
|
|
|
* @name :getBlogName
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/5/13 11:05
|
|
|
|
*/
|
|
|
|
public function getBlogName($source_id,$is_list){
|
|
|
|
if($is_list == BTemplate::IS_LIST){
|
|
|
|
$cateModel = new BlogCategory();
|
|
|
|
$cateInfo = $cateModel->read(['id'=>$source_id]);
|
|
|
|
if($cateInfo === false){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$name = $cateInfo['name'];
|
|
|
|
}else{
|
|
|
|
$blogModel = new Blog();
|
|
|
|
$productInfo = $blogModel->read(['id'=>$source_id]);
|
|
|
|
if($productInfo === false){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$name = $productInfo['name'];
|
|
|
|
}
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取产品名称
|
|
|
|
* @name :getProductName
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/5/13 11:00
|
|
|
|
*/
|
|
|
|
public function getProductName($source_id,$is_list){
|
|
|
|
if($is_list == BTemplate::IS_LIST){
|
|
|
|
$cateModel = new Category();
|
|
|
|
$cateInfo = $cateModel->read(['id'=>$source_id]);
|
|
|
|
if($cateInfo === false){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$name = $cateInfo['title'];
|
|
|
|
}else{
|
|
|
|
$productModel = new Product();
|
|
|
|
$productInfo = $productModel->read(['id'=>$source_id]);
|
|
|
|
if($productInfo === false){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$name = $productInfo['title'];
|
|
|
|
}
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取扩展模块名称
|
|
|
|
* @name :getCustomName
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/5/13 10:55
|
|
|
|
*/
|
|
|
|
public function getCustomName($source,$source_id,$is_list){
|
|
|
|
$customModuleModel = new CustomModule();
|
|
|
|
$moduleInfo = $customModuleModel->read(['id'=>$source]);
|
|
|
|
if($moduleInfo === false){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if($is_list == BTemplate::IS_LIST){
|
|
|
|
$categoryModel = new CustomModuleCategory();
|
|
|
|
$cateInfo = $categoryModel->read(['id'=>$source_id],['id','name']);
|
|
|
|
if($cateInfo === false){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$name = $cateInfo['name'];
|
|
|
|
}else{
|
|
|
|
$contentModel = new CustomModuleContent();
|
|
|
|
$contentInfo = $contentModel->read(['id'=>$source_id],['id','name']);
|
|
|
|
if($contentInfo === false){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$name = $contentInfo['name'];
|
|
|
|
}
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|