<?php
defined('ECMSAPI_MOD') or exit;
$page = $api->param('page' , 1 , 'intval');
$pagesize = $api->param('pagesize' , 10 , 'intval');
$classid = $api->param('classid' , 0 , 'intval');
$keyword = $api->param('keyword' , 0 , 'strip_tags');
$fun = $api->load('fun');
$page = $fun->toInt($page , 1);
$pagesize = $fun->toInt($pagesize , 1 , 100);
if($classid !== 0 && !isset($class_r[$classid])){
$classid = 0;
}
$map = '1=1';
if($classid !== 0){
$classdata = $class_r[$classid];
if($classdata['islast']){
$map .= ' and classid = '.$classid;
}else{
$sonclass = $classdata['sonclass'];
$sonclass = $api->load('fun')->toNumArray($sonclass);
$sonclass = implode(',' , $sonclass);
if($sonclass !== ''){
$map .= ' and classid in('.$sonclass.')';
}
}
}
if($keyword != ''){
$map .= ' and title like "%'.$keyword.'%"';
}
$total = $api->load('db')->total('[!db.pre!]ecms_movie' , $map);
$totalpage = $total > 0 ? ceil($total/$pagesize) : 1;
$list = $total > 0 || $page > $totalpage ? $api->load('db')->select('[!db.pre!]ecms_movie' , '*' , $map , $pagesize.','.$page , 'id desc') : [];
foreach($list as $i=>$v){
$list[$i]['newstime'] = date('Y-m-d' , $v['newstime']);
}
$fun->json(1 , [
'total' => $total,
'page' => $page,
'pagesize' => $pagesize,
'totalpage' => $totalpage,
'classid' => $classid,
'keyword' => $keyword,
'list' => $list
]);