|
...
|
...
|
@@ -48,18 +48,27 @@ class NewsLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :添加博客
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
* @remark :保存数据
|
|
|
|
* @name :newsSave
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/9/7 11:02
|
|
|
|
*/
|
|
|
|
public function news_add(){
|
|
|
|
public function newsSave(){
|
|
|
|
//拼接参数
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
$this->param = $this->paramProcessing($this->param);
|
|
|
|
$rs = $this->model->insertGetId($this->param);
|
|
|
|
$route = RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
//是否更新路由
|
|
|
|
$id = $this->editNewsRoute($this->param['id'],$this->param['url']);
|
|
|
|
$this->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
}else{
|
|
|
|
$id = $this->model->addReturnId($this->param);
|
|
|
|
}
|
|
|
|
//更新路由
|
|
|
|
$route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $id, $this->user['project_id']);
|
|
|
|
$this->edit(['url'=>$route],['id'=>$id]);
|
|
|
|
DB::commit();
|
|
|
|
}catch (\Exception $e){
|
|
|
|
DB::rollBack();
|
|
...
|
...
|
@@ -71,29 +80,26 @@ class NewsLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :编辑
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
* @remark :查看是否编辑路由
|
|
|
|
* @name :editCategoryRoute
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/9/7 11:05
|
|
|
|
*/
|
|
|
|
public function news_edit(){
|
|
|
|
//拼接参数
|
|
|
|
$this->param = $this->paramProcessing($this->param);
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
//设置路由
|
|
|
|
$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('参数错误或其他服务器原因,编辑失败');
|
|
|
|
public function editNewsRoute($id,$route){
|
|
|
|
//生成一条删除路由记录
|
|
|
|
$info = $this->model->read(['id'=>$id],['id','url']);
|
|
|
|
if($info['url'] != $route){
|
|
|
|
$data = [
|
|
|
|
'source'=>RouteMap::SOURCE_NEWS,
|
|
|
|
'route'=>$info['url'],
|
|
|
|
];
|
|
|
|
$this->setRouteDeleteSave($data);
|
|
|
|
}
|
|
|
|
//通知更新
|
|
|
|
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS, 'route'=>$route]);
|
|
|
|
return $this->success();
|
|
|
|
return $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :编辑seo
|
|
|
|
* @return void
|
|
...
|
...
|
@@ -132,16 +138,10 @@ class NewsLogic extends BaseLogic |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function news_info(){
|
|
|
|
//读取缓存
|
|
|
|
$info = Common::get_user_cache($this->model->getTable(),$this->param['id']);
|
|
|
|
if(empty($info)){
|
|
|
|
$info = $this->model->read($this->param);
|
|
|
|
$newsCategoryLogic = new NewsCategoryLogic();
|
|
|
|
$info = $newsCategoryLogic->get_category_name($info);
|
|
|
|
//写入缓存
|
|
|
|
Common::set_user_cache($info,$this->model->getTable(),$this->param['id']);
|
|
|
|
}
|
|
|
|
public function newsInfo(){
|
|
|
|
$info = $this->model->read($this->param);
|
|
|
|
$newsCategoryLogic = new NewsCategoryLogic();
|
|
|
|
$info = $newsCategoryLogic->get_category_name($info);
|
|
|
|
return $this->success($info);
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -151,14 +151,14 @@ class NewsLogic extends BaseLogic |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function news_del(){
|
|
|
|
public function newsDel(){
|
|
|
|
$ids = $this->param['id'];
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
$this->param['id'] = ['in',$this->param['id']];
|
|
|
|
$this->del($this->param,$ids);
|
|
|
|
$this->model->del($this->param);
|
|
|
|
foreach ($ids as $id){
|
|
|
|
RouteMap::delRoute(RouteMap::SOURCE_NEWS, $id, $this->user['project_id']);
|
|
|
|
$this->delRoute($id);
|
|
|
|
}
|
|
|
|
DB::commit();
|
|
|
|
}catch (Exception $e){
|
|
...
|
...
|
@@ -182,8 +182,6 @@ class NewsLogic extends BaseLogic |
|
|
|
$param['create_id'] = $this->user['id'];
|
|
|
|
$param['operator_id'] = $this->user['id'];
|
|
|
|
$param['project_id'] = $this->user['project_id'];
|
|
|
|
$param['created_at'] = date('Y-m-d H:i:s',time());
|
|
|
|
$param['updated_at'] = date('Y-m-d H:i:s',time());
|
|
|
|
$param['category_id'] = ','.$param['category_id'].',';
|
|
|
|
}
|
|
|
|
return $this->success($param);
|
|
...
|
...
|
@@ -223,4 +221,24 @@ class NewsLogic extends BaseLogic |
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :删除路由
|
|
|
|
* @name :delRoute
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/9/7 10:50
|
|
|
|
*/
|
|
|
|
public function delRoute($id){
|
|
|
|
//删除路由映射
|
|
|
|
RouteMap::delRoute(RouteMap::SOURCE_NEWS, $id, $this->user['project_id']);
|
|
|
|
//生成一条删除路由记录
|
|
|
|
$info = $this->model->read(['id'=>$id],['id','route']);
|
|
|
|
$data = [
|
|
|
|
'source'=>RouteMap::SOURCE_NEWS,
|
|
|
|
'route'=>$info['route'],
|
|
|
|
];
|
|
|
|
$this->setRouteDeleteSave($data);
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|