public static function listAppraise($courseId)
{
$field = 'id,content,user_id,point,pid,total_like,release_time,user_name,user_image,ctime,course_id,user_sex';
$commentInfo = CourseComment::where('course_id', $courseId)->field($field)->select();
if (count($commentInfo) > 0) {
$data = $commentInfo->toArray();
$result = self::get_tree_list($data);
return $result;
}
return 101;
}
//父子级树状结构
public static function get_tree_list($lists)
{
$list = self::get_cate_list($lists);
//将每条数据中的id值作为其下标
$temp = [];
foreach ($list as $v) {
$v['reply'] = [];
$temp[$v['id']] = $v;
}
//获取分类树
foreach ($temp as $k => $v) {
$temp[$v['pid']]['reply'][] = &$temp[$v['id']];
}
return isset($temp[0]['reply']) ? $temp[0]['reply'] : [];
}
//无限级分类
public static function get_cate_list($list, $pid = 0, $level = 0)
{
static $tree = array();
if ($level < 4) {
foreach ($list as $row) {
$row['avatar'] = Users::getAvatar($row['user_image'], $row['user_sex']);
$row['is_like'] = $row['user_id'] ? self::isUserlike($row['id'], $row['user_id']) : 0;
if ($row['pid'] == $pid) {
$row['level'] = $level;
$tree[] = $row;
self::get_cate_list($list, $row['id'], $level + 1);
}
}
}
return $tree;
}