This commit is contained in:
wangjinlei
2023-07-24 09:35:34 +08:00
parent 9046c8d168
commit c88bc01c81

View File

@@ -1132,9 +1132,30 @@ class Article extends Controller
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$main_info = $this->article_main_obj->where('article_main_id',$data['article_main_id'])->find();
$next = $this->article_main_obj->where('pre_id',$data['article_main_id'])->where('state',0)->find();
$this->delArticleMain($data['article_main_id']);
return jsonSuccess([]);
}
public function delArticleMainsForSubmission(){
$data = $this->request->post();
$rule = new Validate([
"ids"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$ids = json_decode($data['ids']);
foreach ($ids as $v){
$this->delArticleMain($v);
}
return jsonSuccess([]);
}
private function delArticleMain($article_main_id){
$main_info = $this->article_main_obj->where('article_main_id',$article_main_id)->find();
$next = $this->article_main_obj->where('pre_id',$article_main_id)->where('state',0)->find();
if($next){
//找到目标删除点的上位节点
if($main_info['pre_id']>0){
$pre_id = $main_info['pre_id'];
}else{
@@ -1144,13 +1165,7 @@ class Article extends Controller
->order("article_main_id desc")
->limit(1)->select();
$pre_id = $pre[0]['article_main_id'];
}
//找到目标删除点的上位节点
$pre = $this->article_main_obj
->where('article_main_id','<',$main_info['article_main_id'])
->order("article_main_id desc")
->limit(1)->select();
$pre_id = $pre[0]['article_main_id'];
//查询上一个节点是否有附加节点
$find_add = true;
while ($find_add){
$fi = $this->article_main_obj->where('pre_id',$pre_id)->where('state',0)->find();
@@ -1160,10 +1175,10 @@ class Article extends Controller
$find_add = false;
}
}
}
$this->article_main_obj->where('article_main_id',$next['article_main_id'])->update(['pre_id'=>$pre_id]);
}
$this->article_main_obj->where('article_main_id',$data['article_main_id'])->update(['state'=>1]);
return jsonSuccess([]);
$this->article_main_obj->where('article_main_id',$article_main_id)->update(['state'=>1]);
}
@@ -1183,6 +1198,9 @@ class Article extends Controller
$update['note'] = $data['note'];
}else{
$update['content'] = trim($data['content']);
if(isset($data['is_title'])){
$update['is_title'] = $data['is_title'];
}
}
$this->article_main_obj->where('article_main_id',$data['article_main_id'])->update($update);
return jsonSuccess([]);
@@ -1201,6 +1219,7 @@ class Article extends Controller
return jsonError($rule->getError());
}
$pre_info = $this->article_main_obj->where('article_main_id',$data['pre_id'])->find();
$next_info = $this->article_main_obj->where('pre_id',$pre_info['article_main_id'])->where('state',0)->find();
$insert['article_id'] = $data['article_id'];
$insert['pre_id'] = $data['pre_id'];
$insert['is_add'] = 1;
@@ -1210,13 +1229,24 @@ class Article extends Controller
$insert['note'] = trim($data['note']);
}
$now_id = $this->article_main_obj->insertGetId($insert);
$next_info = $this->article_main_obj->where('pre_id',$pre_info['article_main_id'])->where('state',0)->find();
if($next_info){//如果原节点的下级存在,那么要变换下个节点的父节点
$this->article_main_obj->where('article_main_id',$next_info['article_main_id'])->update(['pre_id'=>$now_id]);
}
return jsonSuccess([]);
}
public function clearArticleMainForSubmission(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$this->article_main_obj->where('article_id',$data['article_id'])->update(['state'=>1]);
return jsonSuccess([]);
}
public function addArticleMainsAddForSubmission(){
$data = $this->request->post();
$rule = new Validate([
@@ -1253,12 +1283,12 @@ class Article extends Controller
return jsonError($rule->getError());
}
$pre_info = $this->article_main_obj->where('article_main_id',$data['pre_id'])->find();
$next_info = $this->article_main_obj->where('pre_id',$pre_info['article_main_id'])->where('state',0)->find();
$insert['article_id'] = $data['article_id'];
$insert['pre_id'] = $data['pre_id'];
$insert['is_add'] = 1;
$insert['content'] = "";
$now_id = $this->article_main_obj->insertGetId($insert);
$next_info = $this->article_main_obj->where('pre_id',$pre_info['article_main_id'])->where('state',0)->find();
if($next_info){//如果原节点的下级存在,那么要变换下个节点的父节点
$this->article_main_obj->where('article_main_id',$next_info['article_main_id'])->update(['pre_id'=>$now_id]);
}