/**
 * 通过pid获取子类所有id
 */
function getChildsID($array, $pid)
{
    $cids = array();
    foreach ($array as $v) {
        if ($v['pid'] == $pid) {
            $cids[] = $v['id'];
            $cids = array_merge($cids, getChildsID($array, $v['id']));
        }
    }
    return $cids;
}
 public function del()
 {
     /*删除该分类以及下面的子分类*/
     $id = $this->_get('id');
     $cate = M('category')->field(array('id', 'pid'))->select();
     //获取该父级id下的所有子类id号
     $cids = getChildsID($cate, $id);
     $cids[] = $id;
     $where = array('id' => array('IN', $cids));
     if (M('category')->where($where)->delete()) {
         $this->success('删除分类成功', U('index'));
     } else {
         $this->error('删除失败');
     }
 }