/**
* Info: 添加评论+回复
*/
public function addComment(){
$videoid = input('videoid/d',0);//视频id
$userid = input('userid/d',0);//用户id
$content = input('content');//评论内容
$parent_id = input('parent_id/d',0);//上级评论id
$Video = VideoModel::findOrEmpty($videoid);
if ($Video->isEmpty()){
page_result(1, "该视频不存在");
}
$data=[
'videoid'=>$videoid,
'userid'=>$userid,
'parent_id'=>$parent_id ?$parent_id:0,
'content'=>$content,
'createtime'=>time()
];
Db::name('video_comment')->insert($data);
page_result(0, "评论成功");
}
$this->getCommlist($id);//视频id,获取评论列表
/**
* Info: 递归获取评论列表
*/
protected function getCommlist($videoid,$parent_id = 0,&$result = array()){
$arr = Db::name('video_comment')->where("parent_id = '".$parent_id."'")->where('videoid',$videoid)->where('status',2)->order("createtime desc")->select();
if(empty($arr)){
return array();
}
foreach ($arr as $cm) {
$thisArr=&$result[];
$cm["createtime"] = $cm['createtime'] ? date("Y-m-d H:i:s",$cm['createtime']) : '--';
$cm["children"] = $this->getCommlist($videoid,$cm["id"],$thisArr);
$thisArr = $cm;
}
return $result;
}
?
|