<?
header('Access-Control-Allow-Origin:*'); 

dd_session_start();
app("base")->check_url();
$table=$_REQUEST['table'];
if ($table=="shop"){
    $table="income";
    $t5=1;
}
    
//更新排序
$usort=$_REQUEST['usort'];
if ($usort){
  $id=$_REQUEST['id'];
  $udata['sort']=$_REQUEST['value'];
  $duoduo->update($table,$udata,"id=$id");
  $result['code']=1;
  echo json_encode($result,JSON_UNESCAPED_UNICODE);exit();
}

$title="title";
$q=$_REQUEST['title'];
$by="sort desc ,id desc";
if ($table=="exam" || $_POST['order'] == 'asc'){
   $by="sort asc ,id desc";
}
$page = !($_POST['page'])?'1':intval($_POST['page']);
$pagesize=$_REQUEST['limit']?$_REQUEST['limit']:20;
$frmnum=($page-1)*$pagesize;
$where=" and 1=1";
if (method_exists($table ,"listwhere" )){
     $where=app($table)->listwhere($where,$frmnum,$pagesize);
}
$count=$duoduo->count($table,'`'.$title.'` like "%'.$q.'%" '.$where);

$list=$duoduo->select_all($table,'*','`'.$title.'` like "%'.$q.'%" '.$where.' order by '.$by.' limit '.$frmnum.','.$pagesize);


if (method_exists($table ,"list" )){
       $list=app($table)->list($list,$pagesize,$frmnum);
}
if (db()->TableField($table,"addtime")){
  foreach ($list as $key => $value) {

      if ($table=="zw")
      $list[$key]['addtime']=date("Y-m-d",$value['addtime']);
      else
      $list[$key]['addtime']=$value['addtime']>0?date("Y-m-d H:i:s",$value['addtime']):"";
  }
}
json(0,"",$list,$count,$other);

?>