作者 lyh

gx

... ... @@ -440,27 +440,6 @@ 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
... ...
... ... @@ -7,6 +7,7 @@ use App\Models\Blog\BlogCategory;
use App\Models\News\NewsCategory;
use App\Models\Product\Category;
use App\Models\Product\Product;
use App\Models\RouteMap;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\ModuleSetting;
use App\Models\Template\Template;
... ... @@ -186,10 +187,32 @@ class BTemplateLogic extends BaseLogic
if($rs === false){
$this->fail('error');
}
//通知更新
$this->homeOrProduct($this->param['source'],$this->param['source_id']);
return $this->success();
}
/**
* @remark :通知首页更新
* @name :IsHome
* @author :lyh
* @method :post
* @time :2023/7/31 16:05
*/
public function homeOrProduct($source,$source_id = ''){
if($source == BTemplate::SOURCE_HOME){
$type = 'index';
$route = '';
}elseif($source == BTemplate::SOURCE_PRODUCT){
$type = RouteMap::SOURCE_PRODUCT;
$productModel = new Product();
$info = $productModel->read(['id'=>$source_id]);
$route = $info['route'];
}
return $this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>$type, 'route'=>$route]);
}
/**
* @remark :处理保存模版数据
* @name :templateParam
* @author :lyh
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Logic\Bside\BTemplate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\RouteMap;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BCustomTemplate;
use App\Models\Template\BSetting;
... ... @@ -70,6 +71,13 @@ class CustomTemplateLogic extends BaseLogic
if($rs === false){
$this->fail('error');
}
//TODO::通知网站更新
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_PAGE,
'route'=>$this->param['url'],
];
updateNotify($this->user['domain'],$data);
return $this->success();
}
... ...
... ... @@ -167,4 +167,21 @@ class BaseLogic extends Logic
return '';
}
/**
* @name :(通知更新)projectUrl
* @author :lyh
* @method :post
* @time :2023/6/6 14:09
*/
function updateNotify($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')
];
return (new UpdateNotify())->insertGetId($param);
}
}
... ...
... ... @@ -47,7 +47,7 @@ class BlogCategoryLogic extends BaseLogic
*/
public function add_blog_category(){
//验证名称是否存在
$this->verifyParamName();
$this->verifyParamName($this->param['name']);
//拼接参数
$this->param = $this->addParamProcessing($this->param);
DB::beginTransaction();
... ... @@ -61,13 +61,8 @@ class BlogCategoryLogic extends BaseLogic
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);
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_BLOG_CATE, 'route'=>$route]);
return $this->success();
}
... ... @@ -79,33 +74,41 @@ class BlogCategoryLogic extends BaseLogic
*/
public function edit_blog_category(){
//验证名称是否存在
$this->verifyParamName();
$info = $this->model->read(['id'=>$this->param['id']]);
if($info['id'] == $this->param['pid']){
$this->verifyParamName($this->param['name'],$this->param['id']);
//验证参数是否可编辑
$this->verifyParamEdit($this->param['id'],$this->param['pid']);
$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_BLOG_CATE, $this->param['id'], $this->user['project_id']);
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_BLOG_CATE, 'route'=>$route]);
return $this->success();
}
/**
* @remark :查看参数是否可编辑
* @name :verifyParamEdit
* @author :lyh
* @method :post
* @time :2023/7/31 16:31
*/
public function verifyParamEdit($id,$pid){
$info = $this->model->read(['id'=>$id]);
if($info['id'] == $pid){
$this->fail('不能成为自己的上级');
}
if($info['pid'] != $this->param['pid']){
$info = $this->model->read(['pid'=>$this->param['id']]);
if($info['pid'] != $pid){
$info = $this->model->read(['pid'=>$id]);
if($info !== false){
$this->fail('当前分类拥有子分类不允许修改父级');
}
//查询当前分类下是否有商品
$blogModel = new BlogModel();
$info = $blogModel->read(['id'=>['like','%,'.$this->param['id'].',%']]);
$info = $blogModel->read(['id'=>['like','%,'.$id.',%']]);
if($info !== false){
$this->fail('当前分类下已存在博客,不允许修改上级');
}
}
$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_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();
}
... ... @@ -198,15 +201,15 @@ class BlogCategoryLogic extends BaseLogic
* @method :post
* @time :2023/6/13 11:41
*/
public function verifyParamName(){
if(isset($this->param['id'])){
public function verifyParamName($name,$id = ''){
if(isset($id) && !empty($id)){
$condition = [
'id'=>['!=',$this->param['id']],
'name'=>$this->param['name'],
'id'=>['!=',$id],
'name'=>$name,
];
}else{
$condition = [
'name'=>$this->param['name']
'name'=>$name
];
}
$info = $this->model->read($condition);
... ...
... ... @@ -59,19 +59,14 @@ class BlogLogic extends BaseLogic
try {
$this->param = $this->paramProcessing($this->param);
$rs = $this->model->insertGetId($this->param);
$this->param['url'] = RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']);
$route = $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::通知网站更新
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_BLOG,
'route'=>$this->param['url'],
];
updateNotify($this->user['domain'],$data);
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_BLOG, 'route'=>$route]);
return $this->success();
}
... ... @@ -86,20 +81,15 @@ class BlogLogic extends BaseLogic
$this->param = $this->paramProcessing($this->param);
DB::beginTransaction();
try {
$this->param['url'] = RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_BLOG, $this->param['id'], $this->user['project_id']);
$route = 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);
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_BLOG, 'route'=>$route]);
return $this->success();
}
/**
... ...
... ... @@ -56,7 +56,7 @@ class NewsCategoryLogic extends BaseLogic
*/
public function add_news_category(){
//验证名称是否存在
$this->verifyParamName();
$this->verifyParamName($this->param['name']);
//参数处理
$this->param = $this->addParamProcessing($this->param);
DB::beginTransaction();
... ... @@ -70,13 +70,8 @@ class NewsCategoryLogic extends BaseLogic
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);
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS_CATE, 'route'=>$route]);
return $this->success();
}
... ... @@ -88,19 +83,14 @@ class NewsCategoryLogic extends BaseLogic
*/
public function edit_news_category(){
//验证名称是否存在
$this->verifyParamName();
$this->verifyParamName($this->param['name'],$this->param['id']);
//验证是否可编辑
$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);
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS_CATE, 'route'=>$route]);
return $this->success();
}
... ... @@ -111,19 +101,19 @@ class NewsCategoryLogic extends BaseLogic
* @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']){
public function verifyEditParam($id,$pid){
$info = $this->model->read(['id'=>$id]);
if($info['id'] == $pid){
$this->fail('不能成为自己的上级');
}
if($info['pid'] != $this->param['pid']){
$info = $this->model->read(['pid'=>$this->param['id']]);
if($info['pid'] != $pid){
$info = $this->model->read(['pid'=>$id]);
if($info !== false){
$this->fail('当前分类拥有子分类不允许修改父级');
}
//查询当前分类下是否有商品
$newsModel = new NewsModel();
$info = $newsModel->read(['id'=>['like','%,'.$this->param['id'].',%']]);
$info = $newsModel->read(['id'=>['like','%,'.$id.',%']]);
if($info !== false){
$this->fail('当前分类下已存在新闻,不允许修改上级');
}
... ... @@ -193,15 +183,15 @@ class NewsCategoryLogic extends BaseLogic
* @method :post
* @time :2023/6/13 11:41
*/
public function verifyParamName(){
if(isset($this->param['id'])){
public function verifyParamName($name,$id = ''){
if(isset($id) && !empty($id)){
$condition = [
'id'=>['!=',$this->param['id']],
'name'=>$this->param['name'],
'id'=>['!=',$id],
'name'=>$name,
];
}else{
$condition = [
'name'=>$this->param['name']
'name'=>$name
];
}
$info = $this->model->read($condition);
... ...
... ... @@ -59,19 +59,14 @@ class NewsLogic extends BaseLogic
try {
$this->param = $this->paramProcessing($this->param);
$rs = $this->model->insertGetId($this->param);
$this->param['url'] = RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
$route = 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);
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS, 'route'=>$route]);
return $this->success();
}
... ... @@ -87,20 +82,15 @@ class NewsLogic extends BaseLogic
DB::beginTransaction();
try {
//设置路由
$this->param['url'] = RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']);
$route = 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::通知网站更新
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_NEWS,
'route'=>$this->param['url'],
];
updateNotify($this->user['domain'],$data);
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS, 'route'=>$route]);
return $this->success();
}
... ...
... ... @@ -71,12 +71,8 @@ class CategoryLogic extends BaseLogic
errorLog('产品分类保存失败', $param, $e);
$this->fail('保存失败');
}
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_PRODUCT,
'route'=>$route,
];
updateNotify($this->user['domain'],$data);
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_PRODUCT_CATE, 'route'=>$route]);
return $this->success();
}
... ...
... ... @@ -48,13 +48,15 @@ class KeywordLogic extends BaseLogic
try {
$res = parent::save($param);
//路由映射
RouteMap::setRoute($param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $res['id'], $this->user['project_id']);
$route = RouteMap::setRoute($param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $res['id'], $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
errorLog('产品关键词保存失败', $param, $e);
$this->fail('保存失败');
}
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_PRODUCT_KEYWORD, 'route'=>$route]);
return $this->success();
}
... ...
... ... @@ -74,7 +74,6 @@ class ProductLogic extends BaseLogic
DB::beginTransaction();
try {
$data = $param;
unset($data['route']);
$data['created_uid'] = $this->user['id'];
$res = parent::save($data);
//关联分类
... ... @@ -82,19 +81,15 @@ class ProductLogic extends BaseLogic
//关联关键词
KeywordRelated::saveRelated($res['id'], $data['keyword_id']);
//路由映射
$param['route'] = RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $res['id'], $this->user['project_id']);
$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);
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_PRODUCT, 'route'=>$route]);
return $this->success();
}
... ...
... ... @@ -22,7 +22,7 @@ class Product extends Base
const STATUS_ON = 1;
const STATUS_RECYCLE = 2;
protected $appends = ['route'];
// protected $appends = ['route'];
public static function statusMap(){
return [
... ...