下面展示一些 前端html代码
。
// A code block
<form method="post" action="{:url('search')}" id="listform" data-type=ajax>
<input type="text" class="intxt" name="name" placeholder="请输入姓名" />
<input type="text" class="intxt" name="tel" placeholder="请输入电话" />
<div class="layui-form">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">日期范围</label>
<div class="layui-inline" id="test6">
<div class="layui-input-inline">
<input type="text" autocomplete="off" id="test-startDate-1" class="layui-input" placeholder="开始日期" name="starttime">
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline">
<input type="text" autocomplete="off" id="test-endDate-1" class="layui-input" placeholder="结束日期" name="endtime">
</div>
</div>
</div>
</div>
</div>
<button type="button" class="btn"><i class="icon-search"></i> 搜索</button>
</form>
下面展示一些 控制器代码篇
。
public function search(){
if(input('uname')!=""){
$map['name'] = array('like','%'.input('uname').'%');
}
if(input('tel')!=""){
$map['tel'] = array('like','%'.input('tel').'%');
}
$arr['starttime'] = input('param.starttime','','urldecode');
$arr['endtime'] = input('param.endtime','','urldecode');
//按时间查询
if (!empty($arr['starttime']) && !empty($arr['endtime']) ) {
$map['datetime'] = array('between',strtotime($arr['starttime']).','.strtotime($arr['endtime']));
} else if ( !empty($arr['starttime']) ) {
$map['datetime'] = array('gt',strtotime($arr['starttime']) );
} else if ( !empty($arr['endtime']) ) {
$map['datetime'] = array('lt',strtotime($arr['endtime']) );
}
$list = db('counsel')->where($map)->order("id desc")->paginate(10,false,['query' => request()->param()]);
$lastMySql=substr(db('counsel')->getLastSql(),0,strpos(db('counsel')->getLastSql(),'LIMIT'));
session('lastMySql',$lastMySql);
$this->assign("list",$list);
$page = $list->render();
$this->assign("page",$page);
return $this->fetch();
}
下面展示一些 导出代码
。
// A code block
//导出excel
public function exportexcel () {
$Mysql = session('lastMySql');
$ResultInfo = db('counsel')->query($Mysql);
// 清空(擦除)缓冲区并关闭输出缓冲
ob_end_clean();
//创建对象
vendor("PHPExcel.PHPExcel");
$excel = new \PHPExcel();
$excel->getActiveSheet()->setTitle('在线留言');
// 设置单元格高度
// 所有单元格默认高度
$excel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(25);
// 第一行的默认高度
$excel->getActiveSheet()->getRowDimension('1')->setRowHeight(30);
// 垂直居中
$excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
// 设置水平居中
$excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//Excel表格式
$letter = array('A','B','C','D','E','F','F','G','H',);
//设置表头
$tableheader = array('编号','姓名','手机号','留言内容','提交时间');
//设置表头表格宽度
$tablestyle = array(
array('width'=>'5'), //编号
array('width'=>'15'), //姓名
array('width'=>'15'), //手机号
array('width'=>'10'), //内容
array('width'=>'20'), //时间
);
//填充表头信息
for($i = 0;$i < count($tableheader);$i++) {
$excel->getActiveSheet()->setCellValue("$letter[$i]1","$tableheader[$i]");
$excel->getActiveSheet()->getColumnDimension($letter[$i])->setWidth($tablestyle[$i]['width']);
}
//填充表格信息
for ($i = 2;$i <= count($ResultInfo) + 1;$i++) {
$j = 0;
foreach ($ResultInfo[$i - 2] as $key=>$value) {
$excel->getActiveSheet()->setCellValue("$letter[$j]$i","$value");
$j++;
}
}
$filename = 'Excel'.date('YmdHis').'.xls';
//直接下载的代码
$write = new \PHPExcel_Writer_Excel5($excel);
//$write->save($filename);
header("Pragma: public");
header("Expires: 0");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl;charset=utf-8");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header("Content-Disposition:attachment; filename=".$filename);
header("Content-Transfer-Encoding:binary");
$write->save('php://output');
}
记录打卡,有需要的朋友交流一下