/**递归查留言
* @param $data 原始数组
* @param $ret
* @return mixed
*/
function get_mess($data,&$ret){
$comment=D("comment");//留言表
foreach($data as $k => $v) {
$ret[$v['id']] = $v;
$p_con=$comment->where('pid='.$v['id'])->select();
if($p_con) {
get_mess($p_con, $ret);
}
}
return $ret;
}
/**
*递归获取评论列表
*/
function getCommlist($pid = 0,&$result = []){
$arr = db('comment')->where('pid',$pid)->order("id")->select();
if(empty($arr)){
return array();
}
foreach ($arr as $cm) {
$thisArr=&$result[];
$cm["children"] = getCommlist($cm["id"],$thisArr);
$thisArr = $cm;
}
return $result;
}
//删除留言,包含留言下所有留言
$id=I('id');
$comment=D('comment');
$pid=$comment->where('pid='.$id)->getfield('id',true);//下级回复id数组
$comment->where('id='.$id)->delete();
while ($pid) {
$p=$pid;
$pid=$comment->where(array('pid'=>array('in',$p)))->getfield('id',true);//重定义下级回复id数组
$comment->where(array('id'=>array('in',$p)))->delete();
}
//获取所有下级评论id
function getCommentList($ids,$in=1){
if(is_string($ids)){
$ids=explode(',',$ids);
}
foreach($ids as &$id){
$id=(int)$id;
}
$ids2=db('comment')->where('pid','in',$ids)->column('id');
$arr=[];
if($in){
$arr=array_merge($arr,$ids);
}
$ids2=array_diff($ids2,$arr);
while($ids2){
$ids2=array_diff($ids2,$arr);
$arr=array_merge($arr,$ids2);
$ids2=db('comment')->where('pid','in',$ids2)->column('id');
}
return $arr;
}