作者 郭文星

123

正在显示 49 个修改的文件 包含 174 行增加32 行删除
... ... @@ -162,8 +162,6 @@ class Department extends Backend
}
//根据部门id获取所有子部门
public function getDepartIdById($id = 6)
{
... ... @@ -234,5 +232,8 @@ class Department extends Backend
$this->success('', null, implode(",", $arr));
}
public function downloadexcel($id)
{
$department = Db::name("department")->where('id', $id)->find();
}
}
... ...
... ... @@ -128,15 +128,115 @@ class Project extends Backend
$this->success();
}
public function downloadexcel($ids){
public function export()
{
if ($this->request->isPost()) {
set_time_limit(0);
$search = $this->request->post('search');
$ids = $this->request->post('ids');
$filter = $this->request->post('filter');
$op = $this->request->post('op');
$columns = $this->request->post('columns');
$excel = new PHPExcel();
$excel->getProperties()
->setCreator("FastAdmin")
->setLastModifiedBy("FastAdmin")
->setTitle("标题")
->setSubject("Subject");
$excel->getDefaultStyle()->getFont()->setName('Microsoft Yahei');
$excel->getDefaultStyle()->getFont()->setSize(12);
$this->sharedStyle = new PHPExcel_Style();
$this->sharedStyle->applyFromArray(
array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => '000000')
),
'font' => array(
'color' => array('rgb' => "000000"),
),
'alignment' => array(
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'indent' => 1
),
'borders' => array(
'allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
)
));
$worksheet = $excel->setActiveSheetIndex(0);
$worksheet->setTitle('标题');
$whereIds = $ids == 'all' ? '1=1' : ['id' => ['in', explode(',', $ids)]];
$this->request->get(['search' => $search, 'ids' => $ids, 'filter' => $filter, 'op' => $op]);
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$line = 1;
$list = [];
$this->model
->field($columns)
->where($where)
->where($whereIds)
->chunk(100, function ($items) use (&$list, &$line, &$worksheet) {
$styleArray = array(
'font' => array(
'bold' => true,
'color' => array('rgb' => 'FF0000'),
'size' => 15,
'name' => 'Verdana'
));
$list = $items = collection($items)->toArray();
foreach ($items as $index => $item) {
$line++;
$col = 0;
foreach ($item as $field => $value) {
$worksheet->setCellValueByColumnAndRow($col, $line, $value);
$worksheet->getStyleByColumnAndRow($col, $line)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
$worksheet->getCellByColumnAndRow($col, $line)->getStyle()->applyFromArray($styleArray);
$col++;
}
}
});
$first = array_keys($list[0]);
foreach ($first as $index => $item) {
$worksheet->setCellValueByColumnAndRow($index, 1, __($item));
}
$excel->createSheet();
// Redirect output to a client’s web browser (Excel2007)
$title = date("YmdHis");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
$objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$objWriter->save('php://output');
return;
}
}
public function downloadexcel($id){
$workinghours=Db::name("workinghours")
->alias("a")
->join("user b","a.user_id=b.id")
->where("project_id",$ids)
->where("project_id",$id)
->select();
$project=Db::name("project")->where("id",$ids)->find();
$res=$this->projectexcel($workinghours,$project);
return $res;
$project=Db::name("project")->where("id",$id)->find();
$file=$this->projectexcel($workinghours,$project);
}
/**
... ... @@ -155,7 +255,7 @@ class Project extends Backend
$objActSheet = $objExcel->getActiveSheet();
$key = ord("A");
$letter = explode(',', "A,B,C,D,E");
$arrHeader = array('序号', '项目名称', '提交人','工时','提交时间');
$arrHeader = array('序号', '项目名称', '提交人', '工时', '提交时间');
//填充表头信息
$lenth = count($arrHeader);
for ($i = 0; $i < $lenth; $i++) {
... ... @@ -169,10 +269,41 @@ class Project extends Backend
$objActSheet->setCellValue('B' . $k, $project['project_name']);
$objActSheet->setCellValue('C' . $k, $v['username']);
$objActSheet->setCellValue('D' . $k, $v['working_hours']);
$objActSheet->setCellValue('E' . $k, date("Y-m-d",$v['reporttime']));
$objActSheet->setCellValue('E' . $k, date("Y-m-d", $v['reporttime']));
}
$outfile = $project['project_name'] . ".xlsx";
$outfile = $project['project_name'] ."-". rand(10000, 99999) . ".xlsx";
$objWriter->save('./datauploads/' . $outfile);
return $outfile;
$file = '../public/datauploads/' . $outfile; // 文件路径
$filename = $outfile; // 下载时的文件名
$objExcel->createSheet();
// Redirect output to a client’s web browser (Excel2007)
$title = date("YmdHis");
header('Content-Disposition: attachment;filename="' . $outfile . '.xlsx"');
$objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
$objWriter->save('php://output');
}
function download( $file_url , $new_name = '' ){
$file_url='../public/datauploads/'.$file_url;
if (!isset( $file_url )||trim( $file_url )== '' ){
echo '500' ;
}
if (! file_exists ( $file_url )){ //检查文件是否存在
echo '404' ;
}
$file_name = basename ( $file_url );
$file_type = explode ( '.' , $file_url );
$file_type = $file_type [ count ( $file_type )-1];
$file_name =trim( $new_name == '' )? $file_name :urlencode( $new_name );
$file_type = fopen ( $file_url , 'r' ); //打开文件
//输入文件标签
header( "Content-type: application/octet-stream" );
header( "Accept-Ranges: bytes" );
header( "Accept-Length: " . filesize ( $file_url ));
header( "Content-Disposition: attachment; filename=" . $file_name );
//输出文件内容
echo fread ( $file_type , filesize ( $file_url ));
fclose( $file_type );
}
}
... ...
... ... @@ -10,11 +10,6 @@
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('project/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('project/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('project/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('project/edit')}"
... ...
... ... @@ -11,7 +11,7 @@ use think\exception\ErrorException;
*/
class Index extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedLogin = ['departmentlist','projectlist'];
protected $noNeedRight = ['*'];
/**
... ... @@ -46,8 +46,10 @@ class Index extends Api
$content = $this->request->param("content");//内容
$working_hours = $this->request->param("working_hours");//工时
$reporttime = $this->request->param("reporttime");//内容
$project=Db::name("project")->where("id",$project_id)->find();
$data=[
'project_id'=>$project_id,
'department_id'=>$project['department_id'],
'working_hours'=>$working_hours,
'content'=>$content,
'user_id'=>$this->auth->id,
... ...
... ... @@ -30,7 +30,8 @@
"ext-curl": "*",
"ext-pdo": "*",
"ext-bcmath": "*",
"txthinking/mailer": "^2.0"
"txthinking/mailer": "^2.0",
"phpoffice/phpexcel": "^1.8"
},
"config": {
"preferred-install": "dist"
... ... @@ -38,7 +39,7 @@
"repositories": [
{
"type": "git",
"url": "https://gitee.com/fastadminnet/framework.git"
"url": "https://gitee.com/karson/framework"
}
]
}
... ...
... ... @@ -31,8 +31,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
}
},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
buttons: [
{
name:'下载报表',
title: '下载报表',
classname: 'btn btn-xs btn-info btn-click',
icon: 'fa fa-leaf',
// dropdown: '更多',//如果包含dropdown,将会以下拉列表的形式展示
click: function (data,row) {
top.location.href="department/downloadexcel?id="+row.id;
}
}
]} ]
]
});
... ...
... ... @@ -37,26 +37,26 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
buttons: [
{
name: 'ajax',
title: "下载报表",
text: "下载报表",
classname: 'btn btn-xs btn-warning btn-magic btn-ajax',
icon: 'fa fa-paper-plane',
confirm: function (row) {
return "确认下载报表"
},
url: 'project/downloadexcel?id={id}',
name:'下载报表',
title: '下载报表',
classname: 'btn btn-xs btn-info btn-click',
icon: 'fa fa-leaf',
// dropdown: '更多',//如果包含dropdown,将会以下拉列表的形式展示
click: function (data,row) {
top.location.href="project/downloadexcel?id="+row.id;
}
}
]}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
... ...
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型