作者 郭文星

123

正在显示 49 个修改的文件 包含 174 行增加32 行删除
@@ -162,8 +162,6 @@ class Department extends Backend @@ -162,8 +162,6 @@ class Department extends Backend
162 } 162 }
163 163
164 164
165 -  
166 -  
167 //根据部门id获取所有子部门 165 //根据部门id获取所有子部门
168 public function getDepartIdById($id = 6) 166 public function getDepartIdById($id = 6)
169 { 167 {
@@ -234,5 +232,8 @@ class Department extends Backend @@ -234,5 +232,8 @@ class Department extends Backend
234 $this->success('', null, implode(",", $arr)); 232 $this->success('', null, implode(",", $arr));
235 } 233 }
236 234
237 - 235 + public function downloadexcel($id)
  236 + {
  237 + $department = Db::name("department")->where('id', $id)->find();
  238 + }
238 } 239 }
@@ -128,15 +128,115 @@ class Project extends Backend @@ -128,15 +128,115 @@ class Project extends Backend
128 $this->success(); 128 $this->success();
129 } 129 }
130 130
131 - public function downloadexcel($ids){ 131 + public function export()
  132 + {
  133 + if ($this->request->isPost()) {
  134 + set_time_limit(0);
  135 + $search = $this->request->post('search');
  136 + $ids = $this->request->post('ids');
  137 + $filter = $this->request->post('filter');
  138 + $op = $this->request->post('op');
  139 + $columns = $this->request->post('columns');
  140 +
  141 + $excel = new PHPExcel();
  142 +
  143 + $excel->getProperties()
  144 + ->setCreator("FastAdmin")
  145 + ->setLastModifiedBy("FastAdmin")
  146 + ->setTitle("标题")
  147 + ->setSubject("Subject");
  148 + $excel->getDefaultStyle()->getFont()->setName('Microsoft Yahei');
  149 + $excel->getDefaultStyle()->getFont()->setSize(12);
  150 +
  151 + $this->sharedStyle = new PHPExcel_Style();
  152 + $this->sharedStyle->applyFromArray(
  153 + array(
  154 + 'fill' => array(
  155 + 'type' => PHPExcel_Style_Fill::FILL_SOLID,
  156 + 'color' => array('rgb' => '000000')
  157 + ),
  158 + 'font' => array(
  159 + 'color' => array('rgb' => "000000"),
  160 + ),
  161 + 'alignment' => array(
  162 + 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  163 + 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  164 + 'indent' => 1
  165 + ),
  166 + 'borders' => array(
  167 + 'allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
  168 + )
  169 + ));
  170 +
  171 + $worksheet = $excel->setActiveSheetIndex(0);
  172 + $worksheet->setTitle('标题');
  173 +
  174 + $whereIds = $ids == 'all' ? '1=1' : ['id' => ['in', explode(',', $ids)]];
  175 + $this->request->get(['search' => $search, 'ids' => $ids, 'filter' => $filter, 'op' => $op]);
  176 + list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  177 +
  178 + $line = 1;
  179 + $list = [];
  180 + $this->model
  181 + ->field($columns)
  182 + ->where($where)
  183 + ->where($whereIds)
  184 + ->chunk(100, function ($items) use (&$list, &$line, &$worksheet) {
  185 + $styleArray = array(
  186 + 'font' => array(
  187 + 'bold' => true,
  188 + 'color' => array('rgb' => 'FF0000'),
  189 + 'size' => 15,
  190 + 'name' => 'Verdana'
  191 + ));
  192 + $list = $items = collection($items)->toArray();
  193 + foreach ($items as $index => $item) {
  194 + $line++;
  195 + $col = 0;
  196 + foreach ($item as $field => $value) {
  197 +
  198 + $worksheet->setCellValueByColumnAndRow($col, $line, $value);
  199 + $worksheet->getStyleByColumnAndRow($col, $line)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
  200 + $worksheet->getCellByColumnAndRow($col, $line)->getStyle()->applyFromArray($styleArray);
  201 + $col++;
  202 + }
  203 + }
  204 + });
  205 + $first = array_keys($list[0]);
  206 + foreach ($first as $index => $item) {
  207 + $worksheet->setCellValueByColumnAndRow($index, 1, __($item));
  208 + }
  209 +
  210 + $excel->createSheet();
  211 + // Redirect output to a client’s web browser (Excel2007)
  212 + $title = date("YmdHis");
  213 + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  214 + header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
  215 + header('Cache-Control: max-age=0');
  216 + // If you're serving to IE 9, then the following may be needed
  217 + header('Cache-Control: max-age=1');
  218 +
  219 + // If you're serving to IE over SSL, then the following may be needed
  220 + header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  221 + header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
  222 + header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  223 + header('Pragma: public'); // HTTP/1.0
  224 +
  225 + $objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
  226 + $objWriter->save('php://output');
  227 + return;
  228 + }
  229 + }
  230 +
  231 +
  232 + public function downloadexcel($id){
132 $workinghours=Db::name("workinghours") 233 $workinghours=Db::name("workinghours")
133 ->alias("a") 234 ->alias("a")
134 ->join("user b","a.user_id=b.id") 235 ->join("user b","a.user_id=b.id")
135 - ->where("project_id",$ids) 236 + ->where("project_id",$id)
136 ->select(); 237 ->select();
137 - $project=Db::name("project")->where("id",$ids)->find();  
138 - $res=$this->projectexcel($workinghours,$project);  
139 - return $res; 238 + $project=Db::name("project")->where("id",$id)->find();
  239 + $file=$this->projectexcel($workinghours,$project);
140 } 240 }
141 241
142 /** 242 /**
@@ -155,7 +255,7 @@ class Project extends Backend @@ -155,7 +255,7 @@ class Project extends Backend
155 $objActSheet = $objExcel->getActiveSheet(); 255 $objActSheet = $objExcel->getActiveSheet();
156 $key = ord("A"); 256 $key = ord("A");
157 $letter = explode(',', "A,B,C,D,E"); 257 $letter = explode(',', "A,B,C,D,E");
158 - $arrHeader = array('序号', '项目名称', '提交人','工时','提交时间'); 258 + $arrHeader = array('序号', '项目名称', '提交人', '工时', '提交时间');
159 //填充表头信息 259 //填充表头信息
160 $lenth = count($arrHeader); 260 $lenth = count($arrHeader);
161 for ($i = 0; $i < $lenth; $i++) { 261 for ($i = 0; $i < $lenth; $i++) {
@@ -169,10 +269,41 @@ class Project extends Backend @@ -169,10 +269,41 @@ class Project extends Backend
169 $objActSheet->setCellValue('B' . $k, $project['project_name']); 269 $objActSheet->setCellValue('B' . $k, $project['project_name']);
170 $objActSheet->setCellValue('C' . $k, $v['username']); 270 $objActSheet->setCellValue('C' . $k, $v['username']);
171 $objActSheet->setCellValue('D' . $k, $v['working_hours']); 271 $objActSheet->setCellValue('D' . $k, $v['working_hours']);
172 - $objActSheet->setCellValue('E' . $k, date("Y-m-d",$v['reporttime'])); 272 + $objActSheet->setCellValue('E' . $k, date("Y-m-d", $v['reporttime']));
173 } 273 }
174 - $outfile = $project['project_name'] . ".xlsx"; 274 + $outfile = $project['project_name'] ."-". rand(10000, 99999) . ".xlsx";
175 $objWriter->save('./datauploads/' . $outfile); 275 $objWriter->save('./datauploads/' . $outfile);
176 - return $outfile; 276 +
  277 + $file = '../public/datauploads/' . $outfile; // 文件路径
  278 + $filename = $outfile; // 下载时的文件名
  279 +
  280 + $objExcel->createSheet();
  281 + // Redirect output to a client’s web browser (Excel2007)
  282 + $title = date("YmdHis");
  283 + header('Content-Disposition: attachment;filename="' . $outfile . '.xlsx"');
  284 + $objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
  285 + $objWriter->save('php://output');
  286 + }
  287 + function download( $file_url , $new_name = '' ){
  288 + $file_url='../public/datauploads/'.$file_url;
  289 + if (!isset( $file_url )||trim( $file_url )== '' ){
  290 + echo '500' ;
  291 + }
  292 + if (! file_exists ( $file_url )){ //检查文件是否存在
  293 + echo '404' ;
  294 + }
  295 + $file_name = basename ( $file_url );
  296 + $file_type = explode ( '.' , $file_url );
  297 + $file_type = $file_type [ count ( $file_type )-1];
  298 + $file_name =trim( $new_name == '' )? $file_name :urlencode( $new_name );
  299 + $file_type = fopen ( $file_url , 'r' ); //打开文件
  300 + //输入文件标签
  301 + header( "Content-type: application/octet-stream" );
  302 + header( "Accept-Ranges: bytes" );
  303 + header( "Accept-Length: " . filesize ( $file_url ));
  304 + header( "Content-Disposition: attachment; filename=" . $file_name );
  305 + //输出文件内容
  306 + echo fread ( $file_type , filesize ( $file_url ));
  307 + fclose( $file_type );
177 } 308 }
178 } 309 }
@@ -10,11 +10,6 @@ @@ -10,11 +10,6 @@
10 <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('project/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a> 10 <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('project/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
11 <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> 11 <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>
12 <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> 12 <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>
13 -  
14 -  
15 -  
16 -  
17 -  
18 </div> 13 </div>
19 <table id="table" class="table table-striped table-bordered table-hover table-nowrap" 14 <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
20 data-operate-edit="{:$auth->check('project/edit')}" 15 data-operate-edit="{:$auth->check('project/edit')}"
@@ -11,7 +11,7 @@ use think\exception\ErrorException; @@ -11,7 +11,7 @@ use think\exception\ErrorException;
11 */ 11 */
12 class Index extends Api 12 class Index extends Api
13 { 13 {
14 - protected $noNeedLogin = ['*']; 14 + protected $noNeedLogin = ['departmentlist','projectlist'];
15 protected $noNeedRight = ['*']; 15 protected $noNeedRight = ['*'];
16 16
17 /** 17 /**
@@ -46,8 +46,10 @@ class Index extends Api @@ -46,8 +46,10 @@ class Index extends Api
46 $content = $this->request->param("content");//内容 46 $content = $this->request->param("content");//内容
47 $working_hours = $this->request->param("working_hours");//工时 47 $working_hours = $this->request->param("working_hours");//工时
48 $reporttime = $this->request->param("reporttime");//内容 48 $reporttime = $this->request->param("reporttime");//内容
  49 + $project=Db::name("project")->where("id",$project_id)->find();
49 $data=[ 50 $data=[
50 'project_id'=>$project_id, 51 'project_id'=>$project_id,
  52 + 'department_id'=>$project['department_id'],
51 'working_hours'=>$working_hours, 53 'working_hours'=>$working_hours,
52 'content'=>$content, 54 'content'=>$content,
53 'user_id'=>$this->auth->id, 55 'user_id'=>$this->auth->id,
@@ -30,7 +30,8 @@ @@ -30,7 +30,8 @@
30 "ext-curl": "*", 30 "ext-curl": "*",
31 "ext-pdo": "*", 31 "ext-pdo": "*",
32 "ext-bcmath": "*", 32 "ext-bcmath": "*",
33 - "txthinking/mailer": "^2.0" 33 + "txthinking/mailer": "^2.0",
  34 + "phpoffice/phpexcel": "^1.8"
34 }, 35 },
35 "config": { 36 "config": {
36 "preferred-install": "dist" 37 "preferred-install": "dist"
@@ -38,7 +39,7 @@ @@ -38,7 +39,7 @@
38 "repositories": [ 39 "repositories": [
39 { 40 {
40 "type": "git", 41 "type": "git",
41 - "url": "https://gitee.com/fastadminnet/framework.git" 42 + "url": "https://gitee.com/karson/framework"
42 } 43 }
43 ] 44 ]
44 } 45 }
@@ -31,8 +31,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -31,8 +31,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
31 } 31 }
32 }, 32 },
33 {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, 33 {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
34 - {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}  
35 - ] 34 + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
  35 + buttons: [
  36 + {
  37 + name:'下载报表',
  38 + title: '下载报表',
  39 + classname: 'btn btn-xs btn-info btn-click',
  40 + icon: 'fa fa-leaf',
  41 + // dropdown: '更多',//如果包含dropdown,将会以下拉列表的形式展示
  42 + click: function (data,row) {
  43 + top.location.href="department/downloadexcel?id="+row.id;
  44 + }
  45 + }
  46 +
  47 + ]} ]
36 ] 48 ]
37 }); 49 });
38 50
@@ -37,26 +37,26 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -37,26 +37,26 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
37 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, 37 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
38 buttons: [ 38 buttons: [
39 { 39 {
40 - name: 'ajax',  
41 - title: "下载报表",  
42 - text: "下载报表",  
43 - classname: 'btn btn-xs btn-warning btn-magic btn-ajax',  
44 - icon: 'fa fa-paper-plane',  
45 - confirm: function (row) {  
46 - return "确认下载报表"  
47 - },  
48 - url: 'project/downloadexcel?id={id}',  
49 - 40 + name:'下载报表',
  41 + title: '下载报表',
  42 + classname: 'btn btn-xs btn-info btn-click',
  43 + icon: 'fa fa-leaf',
  44 + // dropdown: '更多',//如果包含dropdown,将会以下拉列表的形式展示
  45 + click: function (data,row) {
  46 + top.location.href="project/downloadexcel?id="+row.id;
  47 + }
50 } 48 }
51 49
52 ]} 50 ]}
53 ] 51 ]
54 ] 52 ]
  53 +
55 }); 54 });
56 55
57 // 为表格绑定事件 56 // 为表格绑定事件
58 Table.api.bindevent(table); 57 Table.api.bindevent(table);
59 }, 58 },
  59 +
60 add: function () { 60 add: function () {
61 Controller.api.bindevent(); 61 Controller.api.bindevent();
62 }, 62 },
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型