예제 #1
0
 /**
  * 删除分类
  * @param $id
  */
 public function delCategory($id = -1)
 {
     $CatsLogic = new CatsLogic();
     $PostsLogic = new PostsLogic();
     $process_method = I('post.process_method');
     if ($process_method == 'tocat' && I('post.newcat') == $id) {
         $this->error("移动后的分类不能和当前分类相同");
     }
     if ($id == 1) {
         $this->error("默认分类不可删除");
     } else {
         if ($CatsLogic->delete($id)) {
             if (D('Post_cat')->where(array("cat_id" => $id))->find()) {
                 $pc_list = D('Post_cat')->where(array("cat_id" => $id))->select();
                 foreach ($pc_list as $pc) {
                     if ($process_method == 'del') {
                         $PostsLogic->preDel($pc['post_id']);
                     }
                     if ($process_method == 'tocat') {
                         $data['cat_id'] = I('post.newcat');
                         D('Post_cat')->where(array("pc_id" => $pc['pc_id']))->data($data)->save();
                     }
                 }
             }
         } else {
             $this->error('分类删除失败:没有找到指定分类,可能它已经被删除', U('Admin/Posts/category'));
         }
     }
     $this->success('分类删除成功', U('Admin/Posts/category'));
 }