{dede:field name='typeid' runphp='yes'}
global $dsql,$cfg_basedir,$cfg_templets_dir,$cfg_df_style;
require_once ZB_THEME_LIB.'/zb_url.php';
require_once ZB_THEME_LIB.'/zb_cache.php';
$catMap=array(10=>'资讯',11=>'视频',12=>'录像',13=>'集锦',14=>'直播',15=>'赛事');
// 直播(channel=14)文档标题末尾的数字是开赛时间戳(matchdatetime),转成可读 m-d H:i;其余模型无此后缀原样返回
if(!function_exists('hotCleanTitle')){function hotCleanTitle($title,$ch){ if(intval($ch)===14 && preg_match('/^(.*)-(\d{9,11})$/s',trim($title),$m)){ $ts=intval($m[2]); if($ts>946656000 && $ts<2051222400){ return trim($m[1]).' '.date('m-d H:i',$ts); } } return $title; }}
// 热榜整段缓存60秒(置顶+24h+7天兜底),命中即零SQL
$out=zb_cache_get('rank24_html',60);
if($out===null){
$out='';$topAids=array();
// 1) 手动置顶(自建表 biz_hot_arc_top 必然存在,无需每次 information_schema 探测)
$dsql->SetQuery("SELECT a.id,a.title,a.channel FROM `#@__hot_arc_top` h JOIN `#@__archives` a ON a.id=h.aid WHERE h.isshow=1 AND a.arcrank>-1 ORDER BY h.sortrank ASC,h.id DESC LIMIT 5");
$dsql->Execute('hatop');
while($r=$dsql->GetArray('hatop')){
$topAids[]=intval($r['id']);
$tt=htmlspecialchars(hotCleanTitle($r['title'],$r['channel']),ENT_QUOTES,'UTF-8');
$cc=isset($catMap[$r['channel']])?$catMap[$r['channel']]:'';
$out.='
顶'.$cc.'';
}
// 2) 跨模型热榜:直播(按开赛时间)与其他模型(按发布时间)分两条查询后PHP合并排序,
// 各自走索引、避免OR全表扫描;注意不能用 UNION 关键字(DedeBIZ的CheckSql会拦截union判为注入)
$now=time();$cut24=$now-86400;
$notIn=$topAids?(' AND a.id NOT IN('.implode(',',array_map('intval',$topAids)).')'):'';
function zb_rank_rows($dsql,$cut,$notIn,$lim){
$now=time();$liveHi=$now+86400;$lim=intval($lim);
// 各模型分别取窗口内按点击降序的候选,再轮转交织:保证热榜覆盖多种类型,
// 避免某类模型(如采集时基础点击偏高的直播/赛事)靠 click 量级霸榜。
$order=array(14,10,13,12,15,11); // 轮转顺序:直播→资讯→集锦→录像→赛事→视频
$buckets=array();
foreach($order as $ch){
$buf=array();$ch=intval($ch);
if($ch===14){
$dsql->SetQuery("SELECT a.id id,a.title title,a.channel channel,a.click click FROM `#@__archives` a JOIN `#@__addonlive` l ON l.aid=a.id WHERE a.arcrank>-1 AND a.channel=14 AND l.matchdatetime>=$cut AND l.matchdatetime<=$liveHi $notIn ORDER BY a.click DESC LIMIT $lim");
}else{
$dsql->SetQuery("SELECT a.id id,a.title title,a.channel channel,a.click click FROM `#@__archives` a WHERE a.arcrank>-1 AND a.channel=$ch AND a.senddate>=$cut AND a.senddate<=$now $notIn ORDER BY a.click DESC LIMIT $lim");
}
$dsql->Execute('zbr');while($r=$dsql->GetArray('zbr')) $buf[]=$r;
if($buf) $buckets[]=$buf;
}
$out=array();
while(count($out)<$lim){
$moved=false;
foreach($buckets as $bi=>$buf){
if(!empty($buckets[$bi])){ $out[]=array_shift($buckets[$bi]); $moved=true; if(count($out)>=$lim) break; }
}
if(!$moved) break;
}
return $out;
}
// 严格24小时热榜:各模型只取近24h(直播含未来24h内将赛),轮转混合最多10条;不足按实际条数展示,不再用旧数据兜底
$hotRows=zb_rank_rows($dsql,$cut24,$notIn,10);
$ep=0;
foreach($hotRows as $r){
$ep++;
$tt=htmlspecialchars(hotCleanTitle($r['title'],$r['channel']),ENT_QUOTES,'UTF-8');
$cc=isset($catMap[$r['channel']])?$catMap[$r['channel']]:'';
$out.='
'.$ep.''.$cc.'';
}
zb_cache_set('rank24_html',$out);
}
$DedeMeValue=$out;
{/dede:field}