作者 赵彬吉
<?php
namespace App\Console\Commands\Test;
use App\Models\Collect\CollectTask;
use App\Models\Com\UpdateLog;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class Temp extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test_temp';
/**
* The console command description.
*
* @var string
*/
protected $description = '临时脚本';
public function handle()
{
$data = UpdateLog::where('sort', 0)->get();
foreach ($data as $item) {
$project_id = $item->project_id;
$project = ProjectServer::useProject($project_id);
if ($project) {
try {
DB::connection('custom_mysql')->statement("ALTER TABLE `gl_product_category` ADD COLUMN `original_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '来源id'");
} catch (\Exception $e) {
echo $project_id . '已存在';
continue;
}
}
//关闭数据库
DB::disconnect('custom_mysql');
echo $project_id.'成功';
}
}
}
... ...
... ... @@ -98,6 +98,8 @@ class HtmlCollect extends Command
if($html == '0'){
$collect_info->status = CollectTask::STATUS_FAIL;
$collect_info->save();
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: no html' . PHP_EOL;
sleep(2);
return true;
}
... ... @@ -111,6 +113,7 @@ class HtmlCollect extends Command
$collect_info->save();
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: ' . $e->getMessage() . PHP_EOL;
sleep(2);
return true;
}
... ... @@ -123,6 +126,7 @@ class HtmlCollect extends Command
//关闭数据库
DB::disconnect('custom_mysql');
sleep(2);
return true;
}
... ... @@ -151,9 +155,6 @@ class HtmlCollect extends Command
case 'blog':
$source = RouteMap::SOURCE_BLOG;
break;
case 'tag':
$source = RouteMap::SOURCE_PRODUCT_KEYWORD;
break;
default:
$source = RouteMap::SOURCE_PRODUCT;
break;
... ...
... ... @@ -105,6 +105,8 @@ class HtmlLanguageCollect extends Command
if($html == '0'){
$collect_info->status = CollectTask::STATUS_FAIL;
$collect_info->save();
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: no html' . PHP_EOL;
sleep(2);
return true;
}
... ... @@ -118,6 +120,7 @@ class HtmlLanguageCollect extends Command
$collect_info->save();
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: ' . $e->getMessage() . PHP_EOL;
sleep(2);
return true;
}
... ... @@ -130,6 +133,7 @@ class HtmlLanguageCollect extends Command
//关闭数据库
DB::disconnect('custom_mysql');
sleep(2);
return true;
}
... ...
... ... @@ -5,6 +5,7 @@ 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\CollectSource;
use App\Models\Collect\CollectTask;
use App\Models\Com\UpdateLog;
use App\Models\News\News;
... ... @@ -14,6 +15,7 @@ use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BCustomTemplate;
use App\Models\WebSetting\WebSettingReceiving;
use App\Services\CosService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
... ... @@ -79,10 +81,22 @@ class ProjectUpdate extends Command
$domain_arr = parse_url($api_url);
//获取网站配置
$link_type = 0;
$web_url_domain = $domain_arr['host'];
$home_url = $domain_arr['host'];
$url_web_config = 'https://' . $domain_arr['host'] . '/wp-content/cache/user_config.text';
$data_config = curl_c($url_web_config);
if ($data_config) {
$link_type = $data_config['link_type'];
$link_type = $data_config['link_type'] ?? 0;
$web_url_arr = parse_url($data_config['web_url_domain'] ?? '');
if (isset($web_url_arr['host'])) {
$web_url_domain = $web_url_arr['host'];
}
$home_url_arr = parse_url($data_config['home_url'] ?? '');
if (isset($home_url_arr['host'])) {
$home_url = $home_url_arr['host'];
}
}
//获取所有语种
$language_list = [];
... ... @@ -140,11 +154,10 @@ class ProjectUpdate extends Command
'seo_title' => $item['seo_title'] ?? '',
'seo_keywords' => $item['seo_keywords'] ?? '',
'seo_description' => $item['seo_description'] ?? '',
'is_upgrade' => 1,
'route' => $route
]);
$this->set_map($route, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);
CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $link_type, $language_list, $page_list);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
continue;
... ... @@ -224,6 +237,8 @@ class ProjectUpdate extends Command
$items = $data_page['data']['data'] ?? [];
$model = new Product();
$category_model = new Category();
$logic = new CategoryLogic();
foreach ($items as $item) {
$route = $this->get_url_route($item['url'] ?? '');
... ... @@ -234,31 +249,39 @@ class ProjectUpdate extends Command
$gallery = [];
if ($item['images'] ?? []) {
foreach ($item['images'] as $k_img => $img) {
$gallery[] = ['alt' => '这是一张产品图', 'url' => $img];
$gallery[] = ['alt' => '这是一张产品图', 'url' => $this->source_download($img, $project_id, $domain_arr['host'], $web_url_domain, $home_url)];
}
}
//分类
$category_id = '';
//产品类型,2Featured Products,3Hot Products
$product_type = '';
if ($item['category'] ?? []) {
$category_arr = [];
$pid = 0;
for ($i = 0; $i < count($item['category']); $i++) {
$return = $this->get_category_name_arr($item['category'], $pid);
if ($return) {
$category_arr[] = $this->special2str($return['name'] ?? '');
$pid = $return['id'];
$type_arr = [];
$new_category = [];
foreach ($item['category'] as $cate) {
if ($cate['parent'] == 0 && $cate['name'] == 'Featured Products') {
$type_arr[] = 2;
} elseif ($cate['parent'] == 0 && $cate['name'] == 'Hot Products') {
$type_arr[] = 3;
} else {
$new_category[] = $cate['id'];
}
}
if ($category_arr) {
$categoryLogic = new CategoryLogic();
$category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr));
if ($type_arr) {
$product_type = ',' . implode(',', $type_arr);
}
if ($new_category) {
$category_arr = $category_model->list(['original_id' => ['in', $new_category]]);
$category_id = $logic->getLastCategory(array_column($category_arr, 'id'));
}
}
try {
$item['ttile'] = $this->special2str($item['ttile'] ?? '');
$id = $model->addReturnId([
$id = $model->insertGetId([
'project_id' => $project_id,
'title' => $item['ttile'],
'intro' => $item['description'] ?? '',
... ... @@ -266,13 +289,18 @@ class ProjectUpdate extends Command
'category_id' => $category_id,
'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
'gallery' => Arr::a2s($gallery),
'product_type' => $product_type,
'seo_mate' => Arr::a2s([
'title' => $item['ttile'],
'keyword' => $item['keywords'] ?? '',
'description' => $item['description'] ?? ''
]),
'status' => Product::STATUS_ON,
'created_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
'updated_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
'sort' => $item['sort'] ?? 0,
'is_upgrade' => 1,
'six_read' => 1,
'route' => $route
]);
$this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id);
... ... @@ -323,19 +351,21 @@ class ProjectUpdate extends Command
} else {
$image = $item['images'] ?? '';
}
if (strpos($image, '//') === 0) {
$image = 'https:' . $image;
}
$id = $model->addReturnId([
$id = $model->insertGetId([
'project_id' => $project_id,
'name' => $item['ttile'],
'seo_title' => $item['ttile'],
'seo_keywords' => $item['keywords'] ?? '',
'seo_description' => $item['description'] ?? '',
'text' => $item['content'] ?? '',
'image' => $image,
'image' => $this->source_download($image, $project_id, $domain_arr['host'], $web_url_domain, $home_url),
'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE,
'created_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
'updated_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
'sort' => $item['sort'] ?? 0,
'is_upgrade' => 1,
'six_read' => 1,
'url' => $route
]);
$this->set_map($route, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);
... ... @@ -376,7 +406,7 @@ class ProjectUpdate extends Command
if (!$custom) {
try {
$item['ttile'] = $this->special2str($item['ttile'] ?? '');
$id = $model->addReturnId([
$id = $model->insertGetId([
'project_id' => $project_id,
'name' => $item['ttile'],
'title' => $item['ttile'],
... ... @@ -384,7 +414,10 @@ class ProjectUpdate extends Command
'description' => $item['description'] ?? '',
'html' => $item['content'] ?? '',
'status' => 1,
'created_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
'updated_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
'is_upgrade' => 1,
'six_read' => 1,
'url' => $route
]);
$this->set_map($route, RouteMap::SOURCE_PAGE, $id, $project_id);
... ... @@ -424,7 +457,7 @@ class ProjectUpdate extends Command
return $task_id;
}
$task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(7)->get();
$task_list = UpdateLog::where('project_id', 543)->where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(7)->get();
if ($task_list->count() == 0) {
return false;
}
... ... @@ -472,6 +505,7 @@ class ProjectUpdate extends Command
'pid' => $pid,
'keywords' => $item['keywords'] ?? '',
'describe' => $item['description'] ?? '',
'original_id' => $item['id'],
'route' => $route
]);
$this->set_map($route, RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
... ... @@ -490,18 +524,6 @@ class ProjectUpdate extends Command
}
}
//获取分类名称数组
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)
{
... ... @@ -547,4 +569,45 @@ class ProjectUpdate extends Command
}
}
}
//资源下载
protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url)
{
if (!$url) {
return '';
}
$arr = parse_url($url);
$scheme = $arr['scheme'] ?? '';
$host = $arr['host'] ?? '';
$path = $arr['path'] ?? '';
$url_complete = ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path;
if ((empty($host) || $host == $web_url_domain || $host == $home_url) && $path) {
$source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first();
if (!$source) {
$new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete);
if ($new_url) {
CollectSource::insert([
'project_id' => $project_id,
'origin' => $url,
'target' => $new_url,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
]);
return getImageUrl($new_url);
} else {
return $url_complete;
}
} else {
return getImageUrl($source['target']);
}
} else {
return $url_complete;
}
}
}
... ...
... ... @@ -246,6 +246,7 @@ class OptimizeController extends BaseController
if($rs === false){
$this->response('系统错误,请联系管理员',Code::SYSTEM_ERROR);
}
//TODO::通知C端
$this->response('success');
}
}
... ...
... ... @@ -7,6 +7,7 @@ use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Template\ATemplateLogic;
use App\Http\Requests\Aside\Template\ATemplateRequest;
use App\Models\Template\Setting;
use App\Models\Template\Template;
/**
* @remark :A端主题模板管理
... ... @@ -25,6 +26,7 @@ class ATemplateController extends BaseController
*/
public function lists(ATemplateLogic $aTemplateLogic){
$filed = ['id','name','image','url','status','sort','deleted_status','test_model','created_at','project_id'];
$this->map['project_id'] = 0;
$lists = $aTemplateLogic->aTemplateList($this->map,$this->page,$this->row,$this->order,$filed);
if(!empty($lists) && !empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
... ... @@ -186,6 +188,7 @@ class ATemplateController extends BaseController
}
$filed = ['id','name','status','image','created_at'];
$this->map['test_model'] = 0;
$this->map['project_id'] = 0;
$lists = $aTemplateLogic->aTemplateList($this->map,$this->page,$this->row,$this->order,$filed);
$data = [];
if(!empty($lists) && !empty($lists['list'])){
... ... @@ -222,4 +225,25 @@ class ATemplateController extends BaseController
}
$this->response('success',Code::SUCCESS,$info);
}
/**
* @remark :私有公共模板
* @name :getProjectPublicTemplate
* @author :lyh
* @method :post
* @time :2023/6/28 16:34
*/
public function getProjectPublicTemplate(ATemplateLogic $aTemplateLogic){
$filed = ['id','name','image','url','status','sort','deleted_status','test_model','created_at','project_id'];
$this->map['project_id'] = ['!=',0];
$lists = $aTemplateLogic->aTemplateList($this->map,$this->page,$this->row,$this->order,$filed);
if(!empty($lists) && !empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$v['image_link'] = getImageUrl($v['image']);
$lists['list'][$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$lists);
}
}
... ...
... ... @@ -45,26 +45,25 @@ class CNoticeController extends BaseController
'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))){
$progressInfo = $progressInfo->toArray();
if(($progressInfo['total_num'] > $progressInfo['current_num'])){
$this->response('当前页面正在生成了,请完成后再点击',Code::SUCCESS,$progressInfo);
}
}
//通知更新
if($this->param['type'] == UpdateNotify::TYPE_MASTER){
$this->updateMaster();
}else{
$this->updateMinorLanguages();
}
$urlStr = $this->getString($this->param['type'],$this->param['page']);
curlGet($urlStr);
$this->response('更新成功');
http_post($url, json_encode($param));
$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))){
// $progressInfo = $progressInfo->toArray();
// if(($progressInfo['total_num'] > $progressInfo['current_num'])){
// $this->response('当前页面正在生成了,请完成后再点击',Code::SUCCESS,$progressInfo);
// }
// }
// //通知更新
// if($this->param['type'] == UpdateNotify::TYPE_MASTER){
// $this->updateMaster();
// }else{
// $this->updateMinorLanguages();
// }
// $urlStr = $this->getString($this->param['type'],$this->param['page']);
// curlGet($urlStr);
// $this->response('更新成功');
}
/**
... ...
... ... @@ -226,15 +226,9 @@ class ComController extends BaseController
case 'news':
$url_link = $this->user['domain'].RouteMap::SOURCE_NEWS.'/';
break;
case 'news_category':
$url_link = $this->user['domain'].RouteMap::PATH_NEWS_CATE.'/';
break;
case 'blog':
$url_link = $this->user['domain'].RouteMap::SOURCE_BLOG.'/';
break;
case 'blog_category':
$url_link = $this->user['domain'].RouteMap::PATH_BLOG_CATE.'/';
break;
default:
$url_link = $this->user['domain'];
}
... ...
... ... @@ -284,7 +284,7 @@ class ProductController extends BaseController
*/
public function getExtendInfo($product_id){
$extendModel = new Extend();
$list = $extendModel->list([],'id',['type','key','title']);
$list = $extendModel->list([],'id',['id','type','key','title']);
if(empty($list)){
return [];
}
... ... @@ -301,14 +301,15 @@ class ProductController extends BaseController
if($v['type'] == 3){
$arr = json_decode($info['values']);
foreach ($arr as $k1=>$v1){
$v1 = getImageUrl($v1);
$v1 = (array)$v1;
$v1['url'] = getImageUrl($v1['url']);
$arr[$k1] = $v1;
}
$v['values'] = $arr;
}elseif($v['type'] == 4){
$arr1 = json_decode($info['values']);
foreach ($arr1 as $k1=>$v1){
$v1 = getImageUrl($v1);
$v1 = getFileUrl($v1);
$arr1[$k1] = $v1;
}
$v['values'] = $arr1;
... ...
... ... @@ -149,4 +149,5 @@ class BTemplateController extends BaseController
$BTemplateLogic->saveDetail();
$this->response('success');
}
}
... ...
... ... @@ -24,7 +24,7 @@ class BTemplateModuleController extends BaseController
*/
public function lists(BTemplateModuleLogic $BTemplateModuleLogic){
if(!isset($this->map['test_model'])){
$this->map['test_model'] = 0;
$this->map['test_model'] = ['in',[0,1]];
}
$data = [];
$list = $BTemplateModuleLogic->ModuleList($this->map,$this->order);
... ...
... ... @@ -46,4 +46,21 @@ class BTemplateModuleProjectController extends BaseController
$logic->moduleProjectSave();
return $this->response('success');
}
/**
* @remark :
* @name :del
* @author :lyh
* @method :post
* @time :2023/11/28 17:39
*/
public function del(BTemplateModuleProjectLogic $logic){
$this->request->validate([
'id'=>'required',
],[
'id.required' => 'id不能为空',
]);
$logic->delModule();
$this->response('success');
}
}
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Http\Logic\Aside\Project;
use App\Helper\Common;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Project\DeployOptimize;
use App\Models\Project\OnlineCheck;
use App\Models\Project\Project;
... ... @@ -29,9 +30,12 @@ class OnlineCheckLogic extends BaseLogic
if($info === false){
$this->fail('项目未提交审核');
}
//获取项目优化人员
$optimizeModel = new DeployOptimize();
$optimizeInfo = $optimizeModel->read(['project_id'=>$this->param['id']]);
//查看当前用户是否有权限审核
if($this->param['type'] == 'optimist'){
if($info['optimist_mid'] != $this->manager['id']){
if(($info['optimist_mid'] != $this->manager['id']) && ($optimizeInfo['assist_mid'] != $this->manager['id'])){
$this->fail('你无权限提交审核');
}
}else{
... ...
... ... @@ -28,7 +28,6 @@ class ATemplateLogic extends BaseLogic
* @time :2023/6/28 17:03
*/
public function aTemplateList($map,$page,$row,$order = ['created_at'],$filed = ['*']){
$map['project_id'] = 0;
$map['deleted_status'] = 0;
$map['status'] = 0;
$lists = $this->model->lists($map,$page,$row,$order,$filed);
... ... @@ -79,7 +78,7 @@ class ATemplateLogic extends BaseLogic
* @time :2023/6/28 17:15
*/
public function aTemplateStatus(){
$rs = $this->model->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
... ...
... ... @@ -60,6 +60,10 @@ class BTemplateLogLogic extends BaseLogic
$commonData = $this->setCommonParam($info);
$commonTemplateModel = new BTemplateCommon();
$commonTemplateModel->edit($commonData,['template_id'=>$info['template_id'],'type'=>1,'project_id'=>$this->user['project_id']]);
//更新所有界面的other
if(!empty($info['other'])){
$commonTemplateModel->edit(['other'=>$info['other']],['project_id'=>$this->user['project_id'],'template_id'=>$info['template_id']]);
}
}catch (\Exception $e){
$this->fail('系统错误,请联系管理员');
}
... ... @@ -93,7 +97,7 @@ class BTemplateLogLogic extends BaseLogic
'head_html'=>$info['head_html'],
'head_css'=>$info['head_css'],
'footer_html'=>$info['footer_html'],
'footer_css'=>$info['footer_css'],
'footer_css'=>$info['footer_css']
];
return $this->success($data);
}
... ... @@ -110,12 +114,22 @@ class BTemplateLogLogic extends BaseLogic
if($info === false){
$this->fail('当前数据不存在,或已被删除');
}
if(empty($info['other'])){
$info['other'] = str_replace('<header','',characterTruncation($info['text'],"/<link id=\"google-fonts-link\"(.*?)<header/s"));;
}
$html = $info['head_css'].$info['main_css'].$info['footer_css'].$info['other'].
$info['head_html'].$info['main_html'].$info['footer_html'];
$serviceSettingModel = new ServiceSettingModel();
$list = $serviceSettingModel->list(['type'=>2],'created_at');
$data = [
'info' => $info,
'header_footer'=>$list,
];
return $this->success($data);
//拼接html
foreach ($list as $v){
if($v['key'] == 'head'){
$html = $v['values'].$html;
}
if($v['key'] == 'footer'){
$html = $html.$v['values'];
}
}
return $this->success(['html'=>$html]);
}
}
... ...
... ... @@ -287,7 +287,7 @@ class BTemplateLogic extends BaseLogic
$templateCommonModel->edit($data,['id'=>$info['id']]);
}
//更新所有界面的other
$templateCommonModel->edit(['other'=>$other],['project_id'=>$this->user['project_id']]);
$templateCommonModel->edit(['other'=>$other],['project_id'=>$this->user['project_id'],'template_id'=>$param['template_id']]);
return $this->success();
}
... ... @@ -335,6 +335,7 @@ class BTemplateLogic extends BaseLogic
'main_css'=>$param['main_css'],
'footer_html'=>$param['footer_html'],
'footer_css'=>$param['footer_css'],
'other'=> str_replace('<header','',characterTruncation($param['html'],"/<link id=\"google-fonts-link\"(.*?)<header/s"))
];
$bTemplateLogModel = new BTemplateLog();
return $bTemplateLogModel->add($data);
... ... @@ -524,7 +525,9 @@ class BTemplateLogic extends BaseLogic
*/
public function savePublicTemplateHtml(){
$this->param['project_id'] = $this->user['project_id'];
$this->param['test_model'] = 2;//未审核模版
$this->param['operator_id'] = $this->user['manager_id'] ?? 0;
$this->param['html'] = characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/footer>/s');
$this->param = $this->stringProcessing($this->param);
$publicTemplateModel = new Template();
$rs = $publicTemplateModel->add($this->param);
... ...
... ... @@ -38,4 +38,20 @@ class BTemplateModuleProjectLogic extends BaseLogic
}
return $this->success();
}
/**
* @remark :
* @name :delModule
* @author :lyh
* @method :post
* @time :2023/11/28 17:42
*/
public function delModule(){
try {
$this->model->del($this->param);
}catch (\Exception $e){
$this->fail('系统错误,请联系管理员');
}
return $this->success();
}
}
... ...
... ... @@ -8,6 +8,7 @@ use App\Models\RouteMap\RouteMap;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BCustomTemplate;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\BTemplateLog;
use App\Models\Template\Setting;
use App\Models\Template\BTemplate;
... ... @@ -94,9 +95,16 @@ class CustomTemplateLogic extends BaseLogic
$html = $this->param['html'];
$info = $this->model->read(['id'=>$this->param['id']],['id','is_visualization','url']);
if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){//非定制项目+可视化页面
$this->saveCommonTemplate($html);
//获取设置的默认模版
$bSettingModel = new Setting();
$bSettingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
if($bSettingInfo === false){
$this->fail('请先选择模版');
}
$this->saveCommonTemplate($html,$bSettingInfo['template_id']);
$this->param['html'] = characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s');
$this->param['html_style'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
$this->setTemplateLog($bSettingInfo['template_id'],$html,$this->param['id']);
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
... ... @@ -108,19 +116,44 @@ class CustomTemplateLogic extends BaseLogic
}
/**
* @remark :生成记录
* @name :setTemplateLog
* @author :lyh
* @method :post
* @time :2023/8/23 11:16
*/
public function setTemplateLog($template_id,$html,$source_id){
$data = [
'template_id'=>$template_id,
'project_id'=>$this->user['project_id'],
'operator_id'=>$this->user['id'],
'text'=>$html,
'source'=>9,
'source_id'=>$source_id,
'head_html'=>characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'),
'head_css'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'),
'footer_html'=>characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'),
'footer_css'=>characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
'main_html' => characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s'),
'main_css' => characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
'other'=> str_replace('<header','',characterTruncation($html,"/<link id=\"google-fonts-link\"(.*?)<header/s"))
];
$bTemplateLogModel = new BTemplateLog();
return $bTemplateLogModel->add($data);
}
/**
* @remark :保存头部公共数据
* @name :saveCommonTemplate
* @author :lyh
* @method :post
* @time :2023/10/13 14:27
*/
public function saveCommonTemplate($html){
public function saveCommonTemplate($html,$template_id){
$type = $this->getType();
//获取设置的默认模版
$bSettingModel = new Setting();
$bSettingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
$templateCommonModel = new BTemplateCommon();
$info = $templateCommonModel->read(['template_id'=>$bSettingInfo['template_id'],'project_id'=>$this->user['project_id'],'type'=>$type]);
$info = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type]);
$data = [
'head_html'=>characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'),
'head_css'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'),
... ... @@ -129,7 +162,7 @@ class CustomTemplateLogic extends BaseLogic
];
$other = str_replace('<header','',characterTruncation($html,"/<link id=\"google-fonts-link\"(.*?)<header/s"));
if($info === false){
$data['template_id'] = $bSettingInfo['template_id'];
$data['template_id'] = $template_id;
$data['project_id'] = $this->user['project_id'];
$data['type'] = $type;
$templateCommonModel->add($data);
... ...
... ... @@ -14,6 +14,7 @@ use App\Models\Project\PageSetting;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\BTemplateLog;
use App\Models\Template\BTemplateMain;
use App\Models\Template\Setting;
use App\Models\Template\Template;
... ... @@ -272,6 +273,9 @@ class VisualizationLogic extends BaseLogic
* @time :2023/11/15 11:47
*/
public function saveHtml(){
if(!isset($this->user['is_visualization']->page_array)){
$this->fail('当前为定制项目,请先选择定制界面');
}
$page_array = (array)$this->user['is_visualization']->page_array;
$type = $this->getType($this->param['source'],$this->param['source_id']);
try {
... ... @@ -306,6 +310,7 @@ class VisualizationLogic extends BaseLogic
}else{
$bTemplateModel->edit($this->param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id']]);
}
$this->setTemplateLog($this->param['template_id'],$this->param['html'],$this->param['source'],$this->param['source_id']);
}
}catch (\Exception $e){
$this->fail('系统错误,请联系管理员');
... ... @@ -315,6 +320,32 @@ class VisualizationLogic extends BaseLogic
}
/**
* @remark :生成记录
* @name :setTemplateLog
* @author :lyh
* @method :post
* @time :2023/8/23 11:16
*/
public function setTemplateLog($template_id,$html,$source,$source_id){
$data = [
'template_id'=>$template_id,
'project_id'=>$this->user['project_id'],
'operator_id'=>$this->user['id'],
'text'=>$html,
'source'=>$source,
'source_id'=>$source_id,
'main_html'=>characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'),
'main_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
'head_html'=>characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'),
'head_css'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'),
'footer_html'=>characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'),
'footer_css'=>characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
];
$bTemplateLogModel = new BTemplateLog();
return $bTemplateLogModel->add($data);
}
/**
* @remark :保存头部公共数据
* @name :saveCommonTemplate
* @author :lyh
... ... @@ -341,7 +372,7 @@ class VisualizationLogic extends BaseLogic
$templateCommonModel->edit($data,['id'=>$info['id']]);
}
//更新所有界面的other
$templateCommonModel->edit(['other'=>$other],['project_id'=>$this->user['project_id']]);
$templateCommonModel->edit(['other'=>$other],['project_id'=>$this->user['project_id'],'template_id'=>$template_id]);
return $this->success();
}
... ...
... ... @@ -268,13 +268,21 @@ class BlogLogic extends BaseLogic
$text = '';
if($data[4]){
//处理内容中的图片
$pattern = '<img src="(.*?)">';
preg_match_all($pattern, $data[4], $result);
if($result[1]){
foreach ($result[1] as $img){
preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result);
if($result[2]??[]){
foreach ($result[2] as $img){
$data[4] = str_replace($img,getImageUrl(CosService::uploadRemote($project_id,'image_news',$img)),$data[4]);
}
}
//处理内容中的视频
preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result_video);
if($result_video[2]??[]){
foreach ($result_video[2] as $video){
$data[4] = str_replace($video,getImageUrl(CosService::uploadRemote($project_id,'image_news',$video)),$data[4]);
}
}
$text = $data[4];
}
... ...
... ... @@ -304,13 +304,21 @@ class NewsLogic extends BaseLogic
$text = '';
if($data[4]){
//处理内容中的图片
$pattern = '<img src="(.*?)">';
preg_match_all($pattern, $data[4], $result);
if($result[1]){
foreach ($result[1] as $img){
preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result);
if($result[2]??[]){
foreach ($result[2] as $img){
$data[4] = str_replace($img,getImageUrl(CosService::uploadRemote($project_id,'image_news',$img)),$data[4]);
}
}
//处理内容中的视频
preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result_video);
if($result_video[2]??[]){
foreach ($result_video[2] as $video){
$data[4] = str_replace($video,getImageUrl(CosService::uploadRemote($project_id,'image_news',$video)),$data[4]);
}
}
$text = $data[4];
}
... ...
... ... @@ -50,6 +50,8 @@ class ProductLogic extends BaseLogic
if(isset($this->param['category_id']) && !empty($this->param['category_id'])) {
$category_ids = $this->getLastCategoryArr($this->param['category_id']);
$this->param['category_id'] = ','.implode(',',$category_ids).',';
}else{
$this->param['category_id'] = '';
}
DB::connection('custom_mysql')->beginTransaction();
try {
... ... @@ -111,12 +113,18 @@ class ProductLogic extends BaseLogic
continue;
}
unset($v['title']);
if($v['type'] == 3 || $v['type'] == 4){
if($v['type'] == 3){
foreach ($v['values'] as $k1=>$v1){
$v1['url'] = str_replace_url($v1['url']);
$v['values'][$k1] = $v1;
}
$v['values'] = json_encode($v['values']);
}elseif ($v['type'] == 4){
foreach ($v['values'] as $k1=>$v1){
$v1 = str_replace_url($v1);
$v['values'][$k1] = $v1;
}
$v['values'] = json_encode($v['values']);
}
$v['project_id'] = $this->user['project_id'];
$v['product_id'] = $product_id;
... ... @@ -146,6 +154,9 @@ class ProductLogic extends BaseLogic
}else{
$this->param['thumb'] = Arr::a2s([]);
}
if(isset($this->param['route']) && !empty($this->param['route'])){
$this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $this->param['id'], $this->user['project_id']);
}
$this->model->edit($this->param,['id'=>$this->param['id']]);
return $this->success();
}
... ... @@ -594,26 +605,42 @@ class ProductLogic extends BaseLogic
$intro = '';
if($data[5]){
//处理短描述中的图片
$pattern = '/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i';
preg_match_all($pattern, $data[5], $result_intro);
if($result_intro[2]){
preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[5], $result_intro);
if($result_intro[2]??[]){
foreach ($result_intro[2] as $vi_img){
$data[5] = str_replace($vi_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vi_img)),$data[5]);
}
}
//处理短描述中的视频
preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[5], $result_intro_video);
if($result_intro_video[2]??[]){
foreach ($result_intro_video[2] as $vi_video){
$data[5] = str_replace($vi_video,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vi_video)),$data[5]);
}
}
$intro = $data[5];
}
$content = '';
if($data[6]){
//处理内容中的图片
$pattern = '/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i';
preg_match_all($pattern, $data[6], $result_content);
if($result_content[2]){
preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[6], $result_content);
if($result_content[2]??[]){
foreach ($result_content[2] as $vc_img){
$data[6] = str_replace($vc_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vc_img)),$data[6]);
}
}
//处理内容中的视频
preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[6], $result_content_video);
if($result_content_video[2]??[]){
foreach ($result_content_video[2] as $vc_video){
$data[6] = str_replace($vc_video,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vc_video)),$data[6]);
}
}
$content = $data[6];
}
... ...
... ... @@ -311,6 +311,7 @@ Route::middleware(['aloginauth'])->group(function () {
Route::any('/setHeadFooter', [Aside\Template\ATemplateController::class, 'setHeadFooter'])->name('admin.template_setHeadFooter');
Route::any('/getHeadFooter', [Aside\Template\ATemplateController::class, 'getHeadFooter'])->name('admin.template_getHeadFooter');
Route::any('/setPublicTemplate', [Aside\Template\ATemplateController::class, 'setPublicTemplate'])->name('admin.template_setPublicTemplate');
Route::any('/getProjectPublicTemplate', [Aside\Template\ATemplateController::class, 'getProjectPublicTemplate'])->name('admin.template_getProjectPublicTemplate');
// 左侧模块
Route::prefix('module')->group(function () {
Route::any('/', [Aside\Template\ATemplateModuleController::class, 'lists'])->name('admin.ATemplateModule_lists');
... ...
... ... @@ -238,6 +238,7 @@ Route::middleware(['bloginauth'])->group(function () {
//扩展字段
Route::any('extend', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'lists'])->name('product_extend');
Route::any('extend/save', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'save'])->name('product_extend_save');
Route::any('extend/del', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'del'])->name('product_extend_del');
});
... ... @@ -326,6 +327,7 @@ Route::middleware(['bloginauth'])->group(function () {
//获取所有左侧模版
Route::any('/', [\App\Http\Controllers\Bside\Template\BTemplateModuleProjectController::class, 'lists'])->name('template_module_project_lists');
Route::any('/save', [\App\Http\Controllers\Bside\Template\BTemplateModuleProjectController::class, 'save'])->name('template_module_project_save');
Route::any('/del', [\App\Http\Controllers\Bside\Template\BTemplateModuleProjectController::class, 'del'])->name('template_module_project_del');
});
//编辑记录
... ...