Commit 49dff0f9 by wenyi.chen

线上更新

parent 97ec0eba
......@@ -135,26 +135,34 @@ class ExcelFile extends BaseController
/**
* @return void
* 导出任务
* 按任务导出文件
*/
public function taskExportFile()
{
try{
$task = Db::table('task_package')->where('id', 22)->find();
$norm = Db::table('norm')->where('task_id', 22)->select();
$id = input("param.id",0,"intval");
if(empty($id)){
return returnResult(config("config.code.error"),'ID错误!',[]);
}
$task = Db::table('task_package')->where('id', $id)->find();
if($task){
$norm = Db::table('norm')->where('task_id', $task['id'])->select();
if($norm){
$list = [];
foreach ($norm as $value){
$sheet = ['total'=>0,'data'=>[]];
$sheet = ['title'=>$value['name'],'data'=>[]];
$normList = Db::table('norm_list')->where('norm_id', $value['id'])->select();
$longest = 0;
$total = 0;
foreach ($normList as $index=> $val){
$total = 0;
$normReceives = Db::table('norm_receives')->where('norm_list_id', $val['id'])->find();
$normCollects = Db::table('norm_collects')->where('norm_list_id', $val['id'])->find();
$referType = '无'; // 信源类型
$imgPath = '无'; // 图片
$remark = '无';
$referType = '/'; // 信源类型
$imgPath = '/'; // 图片
$remark = '/';
$normCollectsId = '';
$not_collectible = '/';
$not_collectible_remarks='/';
$reviewStatus='/';
// 填写内容
if ($normCollects){
if($normCollects['refer_type']==1){
$referType = '官网/政府';
......@@ -171,24 +179,66 @@ class ExcelFile extends BaseController
}
$normCollectsId = $normCollects['id'];
}
// 是否可以采集
if ($normReceives){
if($normReceives['not_collectible']==1){
$not_collectible = '不可采集';
$not_collectible_remarks = $normReceives['not_collectible_remarks'];
}else{
$not_collectible = '可采集';
}
if($normReceives['status']==0){
$reviewStatus = '已领取、未完成';
}else if($normReceives['status']==1){
$reviewStatus = '已完成、未审核';
}else if($normReceives['status']==2){
$reviewStatus = '审核不通过';
}else if($normReceives['status']==3){
$reviewStatus = '审核通过';
}else if($normReceives['status']==4){
$reviewStatus = '已经结算';
}else{
$reviewStatus = '/';
}
}
// 难度等级
if(isset($val['level'])){
$val['level'] =$val['level'].'级';
}else{
$val['level'] ='/';
}
if(isset($val['sort'])){
if ($val['sort'] ==1){
$val['sort'] ='低';
}else if($val['sort']==2){
$val['sort'] ='中';
}else{
$val['sort'] ='高';
}
}else{
$val['sort'] ='/';
}
$data = [
'number'=>$index,
'name'=>$val['name'],
'level'=>$val['level'],
'refer'=>$val['refer'],
'price'=>$val['price'],
'guide'=>$value['guide'],
'sort'=>$value['sort'],
'sort'=>$val['sort'],
'remark'=>$remark,
'referType'=>$referType,
'admin'=>[],
'user'=>[],
'imgPath'=>$imgPath
'adminLength'=>0,
'userLength'=>0,
'imgPath'=>$imgPath,
'not_collectible'=>$not_collectible,
'not_collectible_remarks'=>$not_collectible_remarks,
'review_status'=>$reviewStatus,
];
$normListExtend = Db::table('norm_list_extend')->where('norm_list_id', $val['id'])->select();
// 添加展示端
foreach ($normListExtend as $extendValue){
$total +=1;
$arr = ['name'=>$extendValue['extend_name'],'value'=>$extendValue['extend_value']];
array_push($data['admin'],$arr);
}
......@@ -196,37 +246,212 @@ class ExcelFile extends BaseController
if($normCollectsId){
$collectsInfo = Db::table('norm_collects_extend')->where('norm_collects_id', $normCollectsId)->select();
foreach ($collectsInfo as $collectsValue){
$total +=1;
$arr = ['name'=>$collectsValue['extend_name'],'value'=>$collectsValue['extend_value']];
array_push($data['user'],$arr);
}
}
// 添加图片信息
array_push($data,$imgPath);
// 记录表头自定义个数
if ($total>$longest){
$longest = $total;
}
$sheet['total'] = $longest;
// 添加第一条指标信息
array_push($sheet['data'],$data);
}
if($sheet['data']){
array_push($list,$sheet);
}
$this->exportFile($list[1]);
}
// 创建一个新的 Spreadsheet 对象
$spreadsheet = new Spreadsheet();
// 设置为活动工作表
$spreadsheet->createSheet();
for ($i=0;$i<count($list);$i++){
$this->exportFile($spreadsheet,$i,$list[$i]['title'],$list[$i]['data']);
}
// 保存 ExcelFile 文件
$writer = new Xlsx($spreadsheet);
$name = 'xlsx/'.$task['name'].'_'.date('YmdHis').'.xlsx';
$writer->save($name);
// header('Content-Type: application/vnd.ms-excel');
// header('Content-Disposition: attachment;filename="'.$task['name'].'_'.date('YmdHis').'.xlsx"');
// header('Cache-Control: max-age=0');
// // 输出Excel文件到浏览器
// $writer->save('php://output');
return returnResult(config("config.code.success"),config("config.describe.success"),config("config.resource_address").'public/'.$name);
}else{
return returnResult(config("config.code.success"),'该任务下未找到相关指标信息!',[]);
}
}else{
return returnResult(config("config.code.error"),'没有该任务存在!',[]);
}
}catch (\Exception $e){
var_dump($e->getMessage());
}
}
public function exportFile($data)
/**
* @return void
* 按指标导出文件
*/
public function normExportFile()
{
try{
$id = input("param.id",0,"intval");
if(empty($id)){
return returnResult(config("config.code.error"),'ID错误!',[]);
}
$norm = Db::table('norm')->where('id', $id)->find();
if($norm){
$list = [];
$sheet = ['title'=>$norm['name'],'data'=>[]];
$normList = Db::table('norm_list')->where('norm_id', $norm['id'])->select();
foreach ($normList as $index=> $val){
$normReceives = Db::table('norm_receives')->where('norm_list_id', $val['id'])->find();
$normCollects = Db::table('norm_collects')->where('norm_list_id', $val['id'])->find();
$referType = '/'; // 信源类型
$imgPath = '/'; // 图片
$remark = '/';
$normCollectsId = '';
$not_collectible = '/';
$not_collectible_remarks='/';
$reviewStatus='/';
// 填写内容
if ($normCollects){
if($normCollects['refer_type']==1){
$referType = '官网/政府';
}else if ($normCollects['refer_type']==2){
$referType = '权威媒体';
}else{
$referType = '其他可信信源';
}
if ($normCollects['imgPath']){
$imgPath = $normCollects['imgPath'];
}
if ($normCollects['remark']){
$remark = $normCollects['remark'];
}
$normCollectsId = $normCollects['id'];
}
// 是否可以采集
if ($normReceives){
if($normReceives['not_collectible']==1){
$not_collectible = '不可采集';
$not_collectible_remarks = $normReceives['not_collectible_remarks'];
}else{
$not_collectible = '可采集';
}
if($normReceives['status']==0){
$reviewStatus = '已领取、未完成';
}else if($normReceives['status']==1){
$reviewStatus = '已完成、未审核';
}else if($normReceives['status']==2){
$reviewStatus = '审核不通过';
}else if($normReceives['status']==3){
$reviewStatus = '审核通过';
}else if($normReceives['status']==4){
$reviewStatus = '已经结算';
}else{
$reviewStatus = '/';
}
}
// 难度等级
if(isset($val['level'])){
$val['level'] =$val['level'].'级';
}else{
$val['level'] ='/';
}
if(isset($val['sort'])){
if ($val['sort'] ==1){
$val['sort'] ='低';
}else if($val['sort']==2){
$val['sort'] ='中';
}else{
$val['sort'] ='高';
}
}else{
$val['sort'] ='/';
}
$data = [
'name'=>$val['name'],
'level'=>$val['level'],
'refer'=>$val['refer'],
'price'=>$val['price'],
'guide'=>$norm['guide'],
'sort'=>$val['sort'],
'remark'=>$remark,
'referType'=>$referType,
'admin'=>[],
'user'=>[],
'adminLength'=>0,
'userLength'=>0,
'imgPath'=>$imgPath,
'not_collectible'=>$not_collectible,
'not_collectible_remarks'=>$not_collectible_remarks,
'review_status'=>$reviewStatus,
];
$normListExtend = Db::table('norm_list_extend')->where('norm_list_id', $val['id'])->select();
// 添加展示端
foreach ($normListExtend as $extendValue){
$arr = ['name'=>$extendValue['extend_name'],'value'=>$extendValue['extend_value']];
array_push($data['admin'],$arr);
}
// 添加用户端
if($normCollectsId){
$collectsInfo = Db::table('norm_collects_extend')->where('norm_collects_id', $normCollectsId)->select();
foreach ($collectsInfo as $collectsValue){
$arr = ['name'=>$collectsValue['extend_name'],'value'=>$collectsValue['extend_value']];
array_push($data['user'],$arr);
}
}
// 添加第一条指标信息
array_push($sheet['data'],$data);
}
if($sheet['data']){
array_push($list,$sheet);
}
// 创建一个新的 Spreadsheet 对象
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 设置为活动工作表
$spreadsheet->createSheet();
for ($i=0;$i<count($list);$i++){
$this->exportFile($spreadsheet,$i,$list[$i]['title'],$list[$i]['data']);
}
// 保存 ExcelFile 文件
$writer = new Xlsx($spreadsheet);
$name = 'xlsx/'.$norm['name'].'_'.date('YmdHis').'.xlsx';
$writer->save($name);
return returnResult(config("config.code.success"),config("config.describe.success"),config("config.resource_address").'public/'.$name);
}else{
return returnResult(config("config.code.success"),'该任务下未找到相关指标信息!',[]);
}
}catch (\Exception $e){
var_dump($e->getMessage());
}
}
/**
* 单页表格输出
* @param $spreadsheet
* @param $number
* @param $title
* @param $data
* @return void
*/
public function exportFile($spreadsheet,$number,$title,$data)
{
try{
$spreadsheet->setActiveSheetIndex($number);
$spreadsheet->getActiveSheet($number)->setTitle($title);
$sheet = $spreadsheet->getActiveSheet($number);
// 设置A列的所有单元格文本居中
$spreadsheet->getDefaultStyle()->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
$spreadsheet->getDefaultStyle()->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
$spreadsheet->getDefaultStyle()->getAlignment()->setWrapText(true);
$sheet->getDefaultRowDimension()->setRowHeight(20); // 默认行高
$sheet->getDefaultColumnDimension()->setWidth(20); // 默认单元格宽度
$sheet->getStyle('A1:Z1')->getFill()
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
->getStartColor()->setARGB('C5D9F1'); // FF后面的六位数是颜色的RGB值
$title = [
'序号',
'指标名称',
'难度等级',
'参考信源',
......@@ -237,7 +462,7 @@ class ExcelFile extends BaseController
'信源类型',
];
$arr = [];
foreach ($data['data'] as $index=> $value) {
foreach ($data as $index=> $value) {
foreach ($value['admin'] as $inx=>$val){
if (!in_array($val['name'],$arr)){
array_push($arr,$val['name']);
......@@ -250,60 +475,130 @@ class ExcelFile extends BaseController
}
}
$title = array_merge($title,$arr);
$column = ['A','B','C','D','E'.'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
array_push($title,'图片');
array_push($title,'是否可采集');
array_push($title,'不可采集原因');
array_push($title,'审核状态');
$column = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
$row = 1;
// 遍历标题数组,设置每个单元格的值
// 遍历标题数组,设置每个单元格的值
foreach ($title as $columns => $val) {
// 使用列的数字来定位列,例如 'A', 'B', 'C', ...
$columnLetter = chr(65 + $columns);
$cell = $columnLetter . $row;
// 设置单元格的值
$sheet->setCellValue($cell, $val);
// 设置单元格A1的对齐方式为居中
}
$num = 0;
$row = 2;
foreach ($data['data'] as $index=> $value) {
foreach ($data as $value) {
$position = 0;
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue($column[$num].$row, isset($value['number'])?$value['number']:'无');
// 设置一些数据到单元格中
$sheet->setCellValue($column[$num+1].$row, isset($value['name'])?$value['name']:'无');
$sheet->setCellValue($column[$num+2].$row, isset($value['level'])?$value['level']:'无');
// $sheet->setCellValue($column[$num+2].$index, isset($value['refer'])?$value['refer']:'无');
// $sheet->setCellValue($column[$num+3].$index, isset($value['price'])?$value['price']:'无');
// $sheet->setCellValue($column[$num+4].$index, isset($value['guide'])?$value['guide']:'无');
// $sheet->setCellValue($column[$num+5].$index, isset($value['sort'])?$value['sort']:'无');
// $sheet->setCellValue($column[$num+6].$index, isset($value['remark'])?$value['remark']:'无');
// $sheet->setCellValue($column[$num+7].$index, isset($value['referType'])?$value['referType']:'无');
// $sheet->setCellValue('K'.$index, $value[10]);
// $sheet->setCellValue('L'.$index,$value[11]);
// $sheet->setCellValue('M'.$index, $value[12]);
// $sheet->setCellValue('N'.$index, $value[13]);
// $sheet->getRowDimension(0)->setRowHeight(50); // 设置第一行的高度为30
//// $sheet->getRowDimension(1)->setWidth(130); // 设置第一行的高度为30
// $sheet->getColumnDimension('A')->setWidth(25); // 设置A列的宽度为20
// $sheet->getRowDimension($index+1)->setRowHeight(50); // 设置第一行的高度为30
//// $sheet->getRowDimension(1)->setWidth(130); // 设置第一行的高度为30
// $sheet->getColumnDimension('B')->setWidth(25); // 设置A列的宽度为20
// if($value[13] != "无"){
// var_dump($value[14]);
// // 创建一个 Drawing 对象,并设置图片的路径
// $drawing = new Drawing();
// $drawing->setName('Sample Image');
// $drawing->setDescription('Sample Image');
// $drawing->setPath($value[13]); // 图片路径
// $drawing->setCoordinates('N'.$index); // 图片放置的单元格位置
// $drawing->setWorksheet($sheet); // 关联到工作表
// // 调整图片大小以适应单元格(可选)
// $drawing->setHeight(80); // 图片高度,单位为磅
// $drawing->setWidth(80); // 图片宽度,单位为磅
// }
// 指标名称
$sheet->setCellValue($column[$num+$position].$row, $value['name']);
$position++;
// 难度等级
$sheet->setCellValue($column[$num+$position].$row, $value['level']);
$position++;
//参考信源
$sheet->setCellValue($column[$num+$position].$row, $value['refer']);
$position++;
//单价
$sheet->setCellValue($column[$num+$position].$row, $value['price']);
$position++;
//参考指南
$sheet->setCellValue($column[$num+$position].$row, $value['guide']);
$position++;
//优先级
$sheet->setCellValue($column[$num+$position].$row, $value['sort']);
$position++;
// 备注
$sheet->setCellValue($column[$num+$position].$row, $value['remark']);
$position++;
//信源类型
$sheet->setCellValue($column[$num+$position].$row, $value['referType']);
$position++;
// 展示端
foreach ($value['admin'] as $ss){
if($ss['name']=='年份'){
$sheet->setCellValue($column[$num+$position].$row, $ss['value'].'年');
}else{
$sheet->setCellValue($column[$num+$position].$row, $ss['value']);
}
$position++;
}
// 用户端
foreach ($value['user'] as $hh){
$sheet->setCellValue($column[$num+$position].$row, $hh['value']);
$position++;
}
$sheet->getRowDimension($row)->setRowHeight(80); // 设置第n行的高度为30
$sheet->getColumnDimension($column[$num+$position])->setWidth(30); // 设置A列的宽度为20
if($title[$position]=='图片'){
if($value['imgPath'] != "无"){
// 创建一个 Drawing 对象,并设置图片的路径
$drawing = new Drawing();
$drawing->setName('Sample Image');
$drawing->setDescription('Sample Image');
$drawing->setPath('./storage/topic/20240402/bff4607948a621271fac9b86ca8dc17c.png'); // 图片路径
$drawing->setCoordinates($column[$num+$position].$row); // 图片放置的单元格位置
$drawing->setWorksheet($sheet); // 关联到工作表
// 调整图片大小以适应单元格(可选)
$drawing->setHeight(136); // 图片高度,单位为磅
$drawing->setWidth(132); // 图片宽度,单位为磅
}else{
//图片
$sheet->setCellValue($column[$num+$position].$row, '无');
$position++;
}
}else{
while ($title[$position]!='图片'){
$sheet->setCellValue($column[$num+$position].$row, '/');
$position++;
}
if($value['imgPath'] != "无"){
// 创建一个 Drawing 对象,并设置图片的路径
$drawing = new Drawing();
$drawing->setName('Sample Image');
$drawing->setDescription('Sample Image');
$drawing->setPath('./storage/topic/20240402/bff4607948a621271fac9b86ca8dc17c.png'); // 图片路径
$drawing->setCoordinates($column[$num+$position].$row); // 图片放置的单元格位置
$drawing->setWorksheet($sheet); // 关联到工作表
// 调整图片大小以适应单元格(可选)
$drawing->setHeight(136); // 图片高度,单位为磅
$drawing->setWidth(132); // 图片宽度,单位为磅
}else{
//图片
$sheet->setCellValue($column[$num+$position].$row, '无');
$position++;
}
}
if($title[$position]=='是否可采集'){
//是否可采集
$sheet->setCellValue($column[$num+$position].$row, $value['not_collectible']);
$position++;
}else{
while ($title[$position]!='是否可采集'){
$sheet->setCellValue($column[$num+$position].$row, '/');
$position++;
}
//是否可采集
$sheet->setCellValue($column[$num+$position].$row, $value['not_collectible']);
$position++;
}
//不可采集的原因
$sheet->setCellValue($column[$num+$position].$row, $value['not_collectible_remarks']);
$position++;
//审核状态
$sheet->setCellValue($column[$num+$position].$row, $value['review_status']);
$position++;
// 每行++
$row++;
}
// 保存 ExcelFile 文件
$writer = new Xlsx($spreadsheet);
$writer->save('import.xlsx');
}catch (\Exception $e){
var_dump($e->getMessage());
exception($e,'ExcelFile.exportFile');
}
}
......
......@@ -25,14 +25,12 @@ class Test extends BaseController
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 设置一些数据到单元格中
$sheet->setCellValue('A1', '带有图片的 ExcelFile 表格');
// 创建一个 Drawing 对象,并设置图片的路径
$drawing = new Drawing();
$drawing->setName('Sample Image');
$drawing->setDescription('Sample Image');
$drawing->setPath('./image_0.png'); // 图片路径
$drawing->setPath('./image_0.jpg'); // 图片路径
$drawing->setCoordinates('B1'); // 图片放置的单元格位置
$drawing->setWorksheet($sheet); // 关联到工作表
......@@ -84,7 +82,6 @@ class Test extends BaseController
// 保存Excel文件
$writer->save($outputFileName);
// 下载Excel文件(或者你可以返回文件路径让用户自己下载)
// return response()->download($outputFileName, 'file.xlsx')->deleteFileAfterSend(true);
}catch (\Exception $e){
......
......@@ -93,9 +93,10 @@ Route::rule("normOrders/list","NormOrders/list"); //结算指标列表
Route::rule("normOrders/detail","NormOrders/detail"); //结算指标列表
Route::rule("importFile","ExcelFile/importFile"); //结算指标列表
Route::rule("exportFile","ExcelFile/exportFile"); //结算指标列表
Route::rule("taskExportFile","ExcelFile/taskExportFile"); //结算指标列表
//Route::rule("importFile","ExcelFile/importFile"); //结算指标列表
//Route::rule("exportFile","ExcelFile/exportFile"); //结算指标列表
Route::rule("taskExportFile","ExcelFile/taskExportFile"); //按任务导出数据
Route::rule("normExportFile","ExcelFile/normExportFile"); //按指标导出数据
Route::rule("test","test/index"); //结算指标列表
//Route::rule("import","ImportFile/import");
\ No newline at end of file
......@@ -69,5 +69,6 @@ return [
"table_delete" =>99, // 删除
],
// "resource_address"=>'https://data-collect.raisound.com/data-collect-api/',
"resource_address"=>'http://192.168.10.168/data-collect-api/'
// "resource_address"=>'http://192.168.10.168/data-collect-api/'
"resource_address"=>'http://gcspider.raisound.com:81/data-collect-api/'
];
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment