作者 lyh

gx

... ... @@ -6,6 +6,7 @@ use App\Utils\LogUtils;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Carbon;
use App\Models\UpdateNotify;
define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/');
/**
... ... @@ -439,6 +440,27 @@ if (!function_exists('getImageUrl')) {
}
}
if (!function_exists('getImageUrl')) {
/**
* @name :(获取当前登录用户域名并通知更新)projectUrl
* @author :lyh
* @method :post
* @time :2023/6/6 14:09
*/
function updateNotify($domain,$data)
{
$param = [
'project_id'=>$data['project_id'],
'type'=>$data['type'],
'route'=>$data['route'],
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
$id = (new UpdateNotify())->insertGetId($data);
$urlStr = $domain.'api/updateHtmlNotify?id=' . $id;
return http_get($urlStr);
}
}
/**
* @remark :字符串截取
* @name :characterTruncation
... ...
... ... @@ -198,22 +198,6 @@ class BaseController extends Controller
}
/**
* @name :(获取当前登录用户域名并通知更新)projectUrl
* @author :lyh
* @method :post
* @time :2023/6/6 14:09
*/
public function projectUrlNotify($str = ''){
$urlStr = 'api/updateHtmlNotify?model='.$str;
$domain = $this->getProjectDomain();
if(!empty($domain)){
$url = $domain.$urlStr;
return http_get($url);
}
return false;
}
/**
* @remark :获取域名
* @name :getProjectDomain
* @author :lyh
... ...
... ... @@ -89,9 +89,7 @@ class BlogController extends BaseController
*/
public function add(BlogRequest $request,BlogLogic $blogLogic){
$request->validated();
$blogLogic->blog_add();
//TODO::通知网站更新
$this->projectUrlNotify($this->updateModelView);
$blogLogic->blogAdd();
$this->response('success');
}
... ... @@ -106,9 +104,7 @@ class BlogController extends BaseController
],[
'id.required' => 'ID不能为空'
]);
$blogLogic->blog_edit();
//TODO::通知网站更新
$this->projectUrlNotify($this->updateModelView);
$blogLogic->blogEdit();
$this->response('success');
}
... ...
... ... @@ -87,9 +87,7 @@ class NewsController extends BaseController
public function add(NewsRequest $newsRequest,NewsLogic $newsLogic){
$newsRequest->validated();
$newsLogic->news_add();
//TODO::通知网站更新
$res = $this->projectUrlNotify($this->updateModelView);
$this->response('success',Code::SUCCESS,$res);
$this->response('success');
}
/**
... ...
... ... @@ -72,8 +72,6 @@ class ProductController extends BaseController
public function save(ProductRequest $request, ProductLogic $logic)
{
$data = $logic->save($this->param);
//通知更新界面
$this->projectUrlNotify('product');
return $this->success($data);
}
... ...
... ... @@ -64,9 +64,9 @@ class ATemplateLogic extends BaseLogic
$this->param['head_html'] = characterTruncation($this->param['html'],'/<header\b[^>]*>(.*?)<\/header>/s');
$this->param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');
$this->param['footer_html'] = characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s');
$this->param['head_css'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-header">(.*?)<\/style>/s');
$this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-styles">(.*?)<\/style>/s');
$this->param['footer_css'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-footer">(.*?)<\/style>/s');
$this->param['head_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s');
$this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');
$this->param['footer_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s');
}
/**
* @remark :修改模块状态
... ...
... ... @@ -124,14 +124,14 @@ class BTemplateLogic extends BaseLogic
if($homeTemplateInfo === false){
$this->fail('请先装修首页');
}
$html = preg_replace('/<style id="vvvebjs-styles">(.*?)<\/style>/s', "<style id='vvvebjs-styles'></style>", $homeTemplateInfo['html']);
$html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', "<style id='globalsojs-styles'></style>", $homeTemplateInfo['html']);
$html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s', "<main>{$this->getProductModule()}</main>", $html);
}else{
$homeTemplateInfo = $this->webTemplateInfo($info['template_id'],1,0);
if($homeTemplateInfo === false){
$this->fail('请先装修首页');
}
$html = preg_replace('/<style id="vvvebjs-styles">(.*?)<\/style>/s', $TemplateInfo['main_css'], $homeTemplateInfo['html']);
$html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', $TemplateInfo['main_css'], $homeTemplateInfo['html']);
$html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s',$TemplateInfo['main_html'] , $html);
}
$TemplateInfo['html'] = $this->getHeadFooter($html);//组装数据
... ... @@ -199,7 +199,7 @@ class BTemplateLogic extends BaseLogic
public function templateSaveParam($template_id){
$this->param['project_id'] = $this->user['project_id'];
if($this->param['source'] == 1){//首页
$this->param['html'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-header">(.*?)<\/footer>/s');
$this->param['html'] = characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/footer>/s');
}else{
$this->param['html'] = $this->param['main_html'];
}
... ... @@ -240,9 +240,9 @@ class BTemplateLogic extends BaseLogic
$this->param['head_html'] = characterTruncation($this->param['html'],'/<header\b[^>]*>(.*?)<\/header>/s');
$this->param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');
$this->param['footer_html'] = characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s');
$this->param['head_css'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-header">(.*?)<\/style>/s');
$this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-styles">(.*?)<\/style>/s');
$this->param['footer_css'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-footer">(.*?)<\/style>/s');
$this->param['head_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s');
$this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');
$this->param['footer_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s');
}
... ...
... ... @@ -60,7 +60,7 @@ class CustomTemplateLogic extends BaseLogic
if(isset($this->param['html']) && !empty($this->param['html'])){
$html = $this->param['html'];
$this->param['html'] = characterTruncation($html,'/<main>(.*?)<\/main>/s');
$this->param['html_style'] = characterTruncation($html,'/<style id="vvvebjs-styles">(.*?)<\/style>/s');
$this->param['html_style'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
... ... @@ -108,9 +108,9 @@ class CustomTemplateLogic extends BaseLogic
]);
if(empty($preg_html)){
$preg_html = "<main></main>";
$html = preg_replace('/<style id="vvvebjs-styles">(.*?)<\/style>/s', "<style id='vvvebjs-styles'></style>", $TemplateInfo['html']);
$html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', "<style id='globalsojs-styles'></style>", $TemplateInfo['html']);
}else{
$html = preg_replace('/<style id="vvvebjs-styles">(.*?)<\/style>/s',$html_style , $TemplateInfo['html']);
$html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s',$html_style , $TemplateInfo['html']);
}
//内容
$html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s', $preg_html, $html);
... ...
... ... @@ -166,4 +166,5 @@ class BaseLogic extends Logic
}
return '';
}
}
... ...
... ... @@ -55,12 +55,19 @@ class BlogCategoryLogic extends BaseLogic
$cate_id = $this->model->insertGetId($this->param);
//处理子集
$this->addProcessingSon($cate_id);
RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], RouteMap::SOURCE_BLOG_CATE, $cate_id, $this->user['project_id']);
$route = RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], RouteMap::SOURCE_BLOG_CATE, $cate_id, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
//TODO::通知网站更新
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_BLOG_CATE,
'route'=>$route,
];
updateNotify($this->user['domain'],$data);
return $this->success();
}
... ... @@ -91,7 +98,14 @@ class BlogCategoryLogic extends BaseLogic
}
$this->param['operator_id'] = $this->user['id'];
$this->edit($this->param,['id'=>$this->param['id']]);
RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], RouteMap::SOURCE_BLOG_CATE, $this->param['id'], $this->user['project_id']);
$route = RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], RouteMap::SOURCE_BLOG_CATE, $this->param['id'], $this->user['project_id']);
//TODO::通知网站更新
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_BLOG_CATE,
'route'=>$route,
];
updateNotify($this->user['domain'],$data);
return $this->success();
}
... ...
... ... @@ -53,19 +53,25 @@ class BlogLogic extends BaseLogic
* @author :liyuhang
* @method
*/
public function blog_add(){
public function blogAdd(){
//拼接参数
DB::beginTransaction();
try {
$this->param = $this->paramProcessing($this->param);
$rs = $this->model->insertGetId($this->param);
RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']);
$this->param['url'] = RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
//TODO::写入日志
//TODO::通知网站更新
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_BLOG,
'route'=>$this->param['url'],
];
updateNotify($this->user['domain'],$data);
return $this->success();
}
... ... @@ -75,18 +81,25 @@ class BlogLogic extends BaseLogic
* @author :liyuhang
* @method
*/
public function blog_edit(){
public function blogEdit(){
//拼接参数
$this->param = $this->paramProcessing($this->param);
DB::beginTransaction();
try {
RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_BLOG, $this->param['id'], $this->user['project_id']);
$this->param['url'] = RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_BLOG, $this->param['id'], $this->user['project_id']);
$this->edit($this->param,['id'=>$this->param['id']]);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
//TODO::通知网站更新
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_BLOG,
'route'=>$this->param['url'],
];
updateNotify($this->user['domain'],$data);
return $this->success();
}
/**
... ...
... ... @@ -64,12 +64,19 @@ class NewsCategoryLogic extends BaseLogic
$cate_id = $this->model->insertGetId($this->param);
//当父级分类拥有产品时,处理产品
$this->addProcessingSon($cate_id);
RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], RouteMap::SOURCE_NEWS_CATE, $cate_id, $this->user['project_id']);
$route = RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], RouteMap::SOURCE_NEWS_CATE, $cate_id, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
//TODO::通知网站更新
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_NEWS_CATE,
'route'=>$route,
];
updateNotify($this->user['domain'],$data);
return $this->success();
}
... ... @@ -82,6 +89,29 @@ class NewsCategoryLogic extends BaseLogic
public function edit_news_category(){
//验证名称是否存在
$this->verifyParamName();
//验证是否可编辑
$this->verifyEditParam();
$this->param['operator_id'] = $this->user['id'];
$this->edit($this->param,['id'=>$this->param['id']]);
$route = RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], RouteMap::SOURCE_NEWS_CATE, $this->param['id'], $this->user['project_id']);
//TODO::通知网站更新
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_NEWS_CATE,
'route'=>$route,
];
updateNotify($this->user['domain'],$data);
return $this->success();
}
/**
* @remark :验证是否可编辑
* @name :verifyEditParam
* @author :lyh
* @method :post
* @time :2023/7/31 15:41
*/
public function verifyEditParam(){
$info = $this->model->read(['id'=>$this->param['id']]);
if($info['id'] == $this->param['pid']){
$this->fail('不能成为自己的上级');
... ... @@ -98,9 +128,6 @@ class NewsCategoryLogic extends BaseLogic
$this->fail('当前分类下已存在新闻,不允许修改上级');
}
}
$this->param['operator_id'] = $this->user['id'];
$this->edit($this->param,['id'=>$this->param['id']]);
RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], RouteMap::SOURCE_NEWS_CATE, $this->param['id'], $this->user['project_id']);
return $this->success();
}
... ...
... ... @@ -59,12 +59,19 @@ class NewsLogic extends BaseLogic
try {
$this->param = $this->paramProcessing($this->param);
$rs = $this->model->insertGetId($this->param);
RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
$this->param['url'] = RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('添加失败');
}
//TODO::通知网站更新
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_NEWS,
'route'=>$this->param['url'],
];
updateNotify($this->user['domain'],$data);
return $this->success();
}
... ... @@ -80,14 +87,20 @@ class NewsLogic extends BaseLogic
DB::beginTransaction();
try {
//设置路由
RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']);
$this->param['url'] = RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']);
$this->edit($this->param,['id'=>$this->param['id']]);
DB::commit();
}catch (\exception $e){
DB::rollBack();
$this->fail('参数错误或其他服务器原因,编辑失败');
}
//TODO::写入日志
//TODO::通知网站更新
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_NEWS,
'route'=>$this->param['url'],
];
updateNotify($this->user['domain'],$data);
return $this->success();
}
... ...
... ... @@ -64,13 +64,19 @@ class CategoryLogic extends BaseLogic
try {
$res = parent::save($param);
//路由映射
RouteMap::setRoute($param['title'], RouteMap::SOURCE_PRODUCT_CATE, $res['id'], $this->user['project_id']);
$route = RouteMap::setRoute($param['title'], RouteMap::SOURCE_PRODUCT_CATE, $res['id'], $this->user['project_id']);
DB::commit();
} catch (\Exception $e){
DB::rollBack();
errorLog('产品分类保存失败', $param, $e);
$this->fail('保存失败');
}
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_PRODUCT,
'route'=>$route,
];
updateNotify($this->user['domain'],$data);
return $this->success();
}
... ...
... ... @@ -82,13 +82,19 @@ class ProductLogic extends BaseLogic
//关联关键词
KeywordRelated::saveRelated($res['id'], $data['keyword_id']);
//路由映射
RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $res['id'], $this->user['project_id']);
$param['route'] = RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $res['id'], $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
errorLog('产品保存失败', $param, $e);
$this->fail('保存失败');
}
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_PRODUCT,
'route'=>$param['route'],
];
updateNotify($this->user['domain'],$data);
return $this->success();
}
... ...
<?php
/**
* @remark :通知更新
* @name :UpdateNotify.php
* @author :lyh
* @method :post
* @time :2023/7/31 15:10
*/
namespace App\Models;
class UpdateNotify extends Base
{
protected $table = 'gl_update_notify';
}
... ...