Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
data-collect-api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyi.chen
data-collect-api
Commits
4fe0d1e9
Commit
4fe0d1e9
authored
Apr 16, 2024
by
cwy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
多数据导出问题
parent
5615cfc3
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
1164 additions
and
32 deletions
+1164
-32
app/api/controller/ExcelFile.php
+80
-32
app/api/controller/ExcelFileaaaaaaaaaaa.php
+1078
-0
runtime/session/sess_9a8331d316fe296bae8a1a1f41ca1b30
+2
-0
runtime/session/sess_acb0c381fd1d72e898f32fac9f3f1f6c
+2
-0
runtime/session/sess_b4e3758727b2b9c530f29aab3f9a2228
+2
-0
No files found.
app/api/controller/ExcelFile.php
View file @
4fe0d1e9
...
@@ -25,11 +25,9 @@ class ExcelFile extends BaseController
...
@@ -25,11 +25,9 @@ class ExcelFile extends BaseController
* @param $file //excel文件地址
* @param $file //excel文件地址
* @return array|void
* @return array|void
*/
*/
public
function
importFormat
(
$
file
)
public
function
importFormat
(
$
objWorksheet
)
{
{
try
{
try
{
$spreadsheet
=
IOFactory
::
load
(
$file
);
$objWorksheet
=
$spreadsheet
->
getSheet
(
0
);
$drawings
=
$objWorksheet
->
getDrawingCollection
();
$drawings
=
$objWorksheet
->
getDrawingCollection
();
$imgList
=
[];
$imgList
=
[];
foreach
(
$drawings
as
$index
=>
$drawing
)
{
foreach
(
$drawings
as
$index
=>
$drawing
)
{
...
@@ -205,14 +203,13 @@ class ExcelFile extends BaseController
...
@@ -205,14 +203,13 @@ class ExcelFile extends BaseController
}
}
}
}
if
(
$error
!=
0
){
if
(
$error
!=
0
){
$message
=
"
文件
第"
.
$num
.
"行数据错误,原因["
.
$errorInfo
.
"],请检查!"
;
$message
=
"第"
.
$num
.
"行数据错误,原因["
.
$errorInfo
.
"],请检查!"
;
return
[
'data'
=>
$list
,
'message'
=>
$message
,
'status'
=>
0
];
return
[
'data'
=>
$list
,
'message'
=>
$message
,
'status'
=>
0
,
'num'
=>
$num
];
}
else
{
}
else
{
$message
=
"
文件
导入成功,共读取"
.
$num
.
"行!"
;
$message
=
"导入成功,共读取"
.
$num
.
"行!"
;
return
[
'data'
=>
$list
,
'message'
=>
$message
,
'status'
=>
1
];
return
[
'data'
=>
$list
,
'message'
=>
$message
,
'status'
=>
1
,
'num'
=>
$num
];
}
}
}
catch
(
\Exception
$e
){
}
catch
(
\Exception
$e
){
var_dump
(
$e
->
getMessage
());
exception
(
$e
,
'ExcelFile.importFile'
);
exception
(
$e
,
'ExcelFile.importFile'
);
}
}
}
}
...
@@ -241,10 +238,6 @@ class ExcelFile extends BaseController
...
@@ -241,10 +238,6 @@ class ExcelFile extends BaseController
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
}
$norm_id
=
Db
::
name
(
'norm'
)
->
insertGetId
(
$normInfo
);
$norm_id
=
Db
::
name
(
'norm'
)
->
insertGetId
(
$normInfo
);
$file
=
request
()
->
file
(
'file'
);
// 上传到本地服务器
$savename
=
\think\facade\Filesystem
::
putFile
(
'import'
,
$file
);
$res
=
$this
->
importFormat
(
'storage/'
.
$savename
);
$taskInfo
=
Db
::
name
(
'task_package'
)
->
where
(
'id'
,
$task_id
)
->
find
();
$taskInfo
=
Db
::
name
(
'task_package'
)
->
where
(
'id'
,
$task_id
)
->
find
();
$normInfo
=
Db
::
name
(
'norm'
)
->
where
(
'id'
,
$norm_id
)
->
find
();
$normInfo
=
Db
::
name
(
'norm'
)
->
where
(
'id'
,
$norm_id
)
->
find
();
if
(
empty
(
$taskInfo
)){
if
(
empty
(
$taskInfo
)){
...
@@ -255,16 +248,26 @@ class ExcelFile extends BaseController
...
@@ -255,16 +248,26 @@ class ExcelFile extends BaseController
$res
[
'message'
]
=
'获取不到子任务信息'
;
$res
[
'message'
]
=
'获取不到子任务信息'
;
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
}
$file
=
request
()
->
file
(
'file'
);
// 上传到本地服务器
$savename
=
\think\facade\Filesystem
::
putFile
(
'import'
,
$file
);
$spreadsheet
=
IOFactory
::
load
(
'storage/'
.
$savename
);
$cou
=
$spreadsheet
->
getAllSheets
();
$num
=
0
;
$control
=
0
;
for
(
$sheetsIndex
=
0
;
$sheetsIndex
<
count
(
$cou
);
$sheetsIndex
++
){
$objWorksheet
=
$spreadsheet
->
getSheet
(
$sheetsIndex
);
$res
=
$this
->
importFormat
(
$objWorksheet
);
// 格式化信息错误
// 格式化信息错误
if
(
$res
[
'status'
]
==
0
){
if
(
$res
[
'status'
]
==
0
){
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
return
returnResult
(
config
(
"config.code.error"
),
'文件第'
.
(
$sheetsIndex
+
1
)
.
'页,'
.
$res
[
'message'
]);
}
}
if
(
empty
(
$res
[
'data'
])){
if
(
empty
(
$res
[
'data'
])){
$res
[
'message'
]
=
'表格内容为空'
;
$res
[
'message'
]
=
'表格内容为空'
;
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
return
returnResult
(
config
(
"config.code.error"
),
'文件第'
.
(
$sheetsIndex
+
1
)
.
'页,'
.
$res
[
'message'
]);
}
}
$num
+=
$res
[
'num'
];
// 开启数据库事务
// 开启数据库事务
$control
=
1
;
$user_id
=
1
;
//用户ID
$user_id
=
1
;
//用户ID
$normExtendSql
=
[];
// 指标自定义
$normExtendSql
=
[];
// 指标自定义
// 展时端自定义
// 展时端自定义
...
@@ -316,7 +319,9 @@ class ExcelFile extends BaseController
...
@@ -316,7 +319,9 @@ class ExcelFile extends BaseController
'type'
=>
1
,
'type'
=>
1
,
];
];
$norm_list_id
=
Db
::
name
(
'norm_list'
)
->
insertGetId
(
$arr
);
$norm_list_id
=
Db
::
name
(
'norm_list'
)
->
insertGetId
(
$arr
);
if
(
empty
(
$norm_list_id
)){
$control
++
;
}
// 指标列表扩展
// 指标列表扩展
foreach
(
$value
[
'adminData'
]
as
$kk
){
foreach
(
$value
[
'adminData'
]
as
$kk
){
$arr
=
[
$arr
=
[
...
@@ -326,7 +331,10 @@ class ExcelFile extends BaseController
...
@@ -326,7 +331,10 @@ class ExcelFile extends BaseController
'extend_value'
=>
$kk
[
'value'
],
'extend_value'
=>
$kk
[
'value'
],
'extend_type'
=>
1
'extend_type'
=>
1
];
];
Db
::
name
(
'norm_list_extend'
)
->
insertGetId
(
$arr
);
$sqlInser
=
Db
::
name
(
'norm_list_extend'
)
->
insertGetId
(
$arr
);
if
(
empty
(
$sqlInser
)){
$control
++
;
}
}
}
// 指标领取
// 指标领取
...
@@ -342,7 +350,9 @@ class ExcelFile extends BaseController
...
@@ -342,7 +350,9 @@ class ExcelFile extends BaseController
'not_collectible_remarks'
=>
$value
[
'not_collectible_remarks'
],
'not_collectible_remarks'
=>
$value
[
'not_collectible_remarks'
],
];
];
$norm_receives_id
=
Db
::
name
(
'norm_receives'
)
->
insertGetId
(
$arr
);
$norm_receives_id
=
Db
::
name
(
'norm_receives'
)
->
insertGetId
(
$arr
);
if
(
empty
(
$norm_receives_id
)){
$control
++
;
}
// 用户填写指标
// 用户填写指标
$arr
=
[
$arr
=
[
'task_id'
=>
$task_id
,
'task_id'
=>
$task_id
,
...
@@ -357,9 +367,14 @@ class ExcelFile extends BaseController
...
@@ -357,9 +367,14 @@ class ExcelFile extends BaseController
'file_name'
=>
$value
[
'file_name'
],
'file_name'
=>
$value
[
'file_name'
],
];
];
$norm_collects_id
=
Db
::
name
(
'norm_collects'
)
->
insertGetId
(
$arr
);
$norm_collects_id
=
Db
::
name
(
'norm_collects'
)
->
insertGetId
(
$arr
);
if
(
empty
(
$norm_collects_id
)){
$control
++
;
}
// 用户填写扩展
// 用户填写扩展
$info
=
Db
::
name
(
'norm_list_extend'
)
->
where
(
'norm_list_id'
,
$norm_list_id
)
->
find
();
$info
=
Db
::
name
(
'norm_list_extend'
)
->
where
(
'norm_list_id'
,
$norm_list_id
)
->
find
();
if
(
empty
(
$info
)){
$control
++
;
}
foreach
(
$value
[
'userData'
]
as
$val
){
foreach
(
$value
[
'userData'
]
as
$val
){
$arr
=
[
$arr
=
[
'norm_collects_id'
=>
$norm_collects_id
,
'norm_collects_id'
=>
$norm_collects_id
,
...
@@ -371,7 +386,10 @@ class ExcelFile extends BaseController
...
@@ -371,7 +386,10 @@ class ExcelFile extends BaseController
'extend_value'
=>
$val
[
'value'
],
'extend_value'
=>
$val
[
'value'
],
'extend_type'
=>
1
,
'extend_type'
=>
1
,
];
];
Db
::
name
(
'norm_collects_extend'
)
->
insertGetId
(
$arr
);
$sqlInser
=
Db
::
name
(
'norm_collects_extend'
)
->
insertGetId
(
$arr
);
if
(
empty
(
$sqlInser
)){
$control
++
;
}
}
}
}
}
...
@@ -403,15 +421,21 @@ class ExcelFile extends BaseController
...
@@ -403,15 +421,21 @@ class ExcelFile extends BaseController
array_push
(
$normExtendSql
,
$normExtendArr
);
array_push
(
$normExtendSql
,
$normExtendArr
);
}
}
// 指标扩展信息
// 指标扩展信息
Db
::
name
(
'norm_extend'
)
->
insertAll
(
$normExtendSql
);
$sqlInser
=
Db
::
name
(
'norm_extend'
)
->
insertAll
(
$normExtendSql
);
if
(
empty
(
$sqlInser
)){
$control
++
;
}
}
// 文件格式化有问题
// 文件格式化有问题
if
(
$res
[
'status'
]
==
0
){
if
(
$res
[
'status'
]
==
0
||
$control
>
0
){
if
(
$control
>
0
){
$res
[
'message'
]
=
'文件第'
.
$sheetsIndex
.
'页入库错误!'
;
}
Db
::
rollback
();
Db
::
rollback
();
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
else
{
}
else
{
Db
::
commit
();
Db
::
commit
();
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.success"
)
,
''
);
return
returnResult
(
config
(
"config.code.success"
),
'导入成功,共'
.
$sheetsIndex
.
'页'
.
$num
.
"行"
,
''
);
}
}
}
catch
(
\Exception
$e
){
}
catch
(
\Exception
$e
){
Db
::
rollback
();
Db
::
rollback
();
...
@@ -892,7 +916,7 @@ class ExcelFile extends BaseController
...
@@ -892,7 +916,7 @@ class ExcelFile extends BaseController
$spreadsheet
->
getDefaultStyle
()
->
getAlignment
()
->
setWrapText
(
true
);
$spreadsheet
->
getDefaultStyle
()
->
getAlignment
()
->
setWrapText
(
true
);
$sheet
->
getDefaultRowDimension
()
->
setRowHeight
(
20
);
// 默认行高
$sheet
->
getDefaultRowDimension
()
->
setRowHeight
(
20
);
// 默认行高
$sheet
->
getDefaultColumnDimension
()
->
setWidth
(
20
);
// 默认单元格宽度
$sheet
->
getDefaultColumnDimension
()
->
setWidth
(
20
);
// 默认单元格宽度
$sheet
->
getStyle
(
'A1:
Z
1'
)
->
getFill
()
$sheet
->
getStyle
(
'A1:
CW
1'
)
->
getFill
()
->
setFillType
(
\PhpOffice\PhpSpreadsheet\Style\Fill
::
FILL_SOLID
)
->
setFillType
(
\PhpOffice\PhpSpreadsheet\Style\Fill
::
FILL_SOLID
)
->
getStartColor
()
->
setARGB
(
'C5D9F1'
);
// FF后面的六位数是颜色的RGB值
->
getStartColor
()
->
setARGB
(
'C5D9F1'
);
// FF后面的六位数是颜色的RGB值
$title
=
[
$title
=
[
...
@@ -924,13 +948,16 @@ class ExcelFile extends BaseController
...
@@ -924,13 +948,16 @@ class ExcelFile extends BaseController
array_push
(
$title
,
'是否可采集'
);
array_push
(
$title
,
'是否可采集'
);
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'
];
$col
=
'A'
;
$row
=
1
;
$column
=
[
'A'
];
for
(
$coli
=
0
;
$coli
<
100
;
$coli
++
)
{
$col
=
$this
->
excelColPlus
(
$col
);
array_push
(
$column
,
$col
);
}
// 遍历标题数组,设置每个单元格的值
// 遍历标题数组,设置每个单元格的值
foreach
(
$title
as
$columns
=>
$val
)
{
foreach
(
$title
as
$columns
=>
$val
)
{
// 使用列的数字来定位列,例如 'A', 'B', 'C', ...
// 'A1', 'B1', 'C1', ...
$columnLetter
=
chr
(
65
+
$columns
);
$cell
=
$column
[
$columns
]
.
'1'
;
$cell
=
$columnLetter
.
$row
;
// 设置单元格的值
// 设置单元格的值
$sheet
->
setCellValue
(
$cell
,
$val
);
$sheet
->
setCellValue
(
$cell
,
$val
);
// 设置单元格A1的对齐方式为居中
// 设置单元格A1的对齐方式为居中
...
@@ -967,7 +994,6 @@ class ExcelFile extends BaseController
...
@@ -967,7 +994,6 @@ class ExcelFile extends BaseController
//信源类型
//信源类型
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'referType'
]);
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'referType'
]);
$position
++
;
$position
++
;
// 展示端
// 展示端
foreach
(
$value
[
'admin'
]
as
$ss
){
foreach
(
$value
[
'admin'
]
as
$ss
){
if
(
$ss
[
'name'
]
==
'年份'
){
if
(
$ss
[
'name'
]
==
'年份'
){
...
@@ -982,6 +1008,7 @@ class ExcelFile extends BaseController
...
@@ -982,6 +1008,7 @@ class ExcelFile extends BaseController
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$hh
[
'value'
]);
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$hh
[
'value'
]);
$position
++
;
$position
++
;
}
}
$position
--
;
$sheet
->
getRowDimension
(
$row
)
->
setRowHeight
(
80
);
// 设置第n行的高度为30
$sheet
->
getRowDimension
(
$row
)
->
setRowHeight
(
80
);
// 设置第n行的高度为30
$sheet
->
getColumnDimension
(
$column
[
$num
+
$position
])
->
setWidth
(
30
);
// 设置A列的宽度为20
$sheet
->
getColumnDimension
(
$column
[
$num
+
$position
])
->
setWidth
(
30
);
// 设置A列的宽度为20
if
(
$title
[
$position
]
==
'图片'
){
if
(
$title
[
$position
]
==
'图片'
){
...
@@ -1059,5 +1086,26 @@ class ExcelFile extends BaseController
...
@@ -1059,5 +1086,26 @@ class ExcelFile extends BaseController
exception
(
$e
,
'ExcelFile.exportFile'
);
exception
(
$e
,
'ExcelFile.exportFile'
);
}
}
}
}
// 求$col 的下一个列号
public
function
excelColPlus
(
$col
)
{
//先转化成27进制数字
$col_chars
=
str_split
(
$col
);
$col_num
=
0
;
foreach
(
$col_chars
as
$col_char
)
{
$col_num
=
(
ord
(
$col_char
)
-
64
)
+
27
*
(
$col_num
);
}
$col_num
++
;
//数字转化为答案
$ans
=
''
;
while
(
$col_num
)
{
$ans
.=
chr
(
floor
(
$col_num
%
27
)
+
64
);
$col_num
=
floor
(
$col_num
/
27
);
}
// '@' 都变成A
$ans
=
str_replace
(
'@'
,
'A'
,
$ans
);
// 反转
$ans
=
strrev
(
$ans
);
return
$ans
;
}
}
}
app/api/controller/ExcelFileaaaaaaaaaaa.php
0 → 100644
View file @
4fe0d1e9
<?php
/**
* Create by wenyi
* E-mail: wesley_prc@163.com
* Description: thinkphp6
* Date: 2024/3/13 9:21
* Update: 2024/3/13 9:21
* Remarks:
*/
namespace
app\api\controller
;
use
app\BaseController
;
use
PhpOffice\PhpSpreadsheet\IOFactory
;
use
PhpOffice\PhpSpreadsheet\Worksheet\Drawing
;
use
think\facade\Filesystem
;
use
PhpOffice\PhpSpreadsheet\Spreadsheet
;
use
PhpOffice\PhpSpreadsheet\Writer\Xlsx
;
use
think\facade\Env
;
use
think\facade\Db
;
class
ExcelFileaaaaaaaaaaa
extends
BaseController
{
/**
* 导入指标格式化文件数据
* @param $file //excel文件地址
* @return array|void
*/
public
function
importFormat
(
$file
)
{
try
{
$spreadsheet
=
IOFactory
::
load
(
$file
);
$cou
=
$spreadsheet
->
getAllSheets
();
$listAll
=
[];
//所有页数据
for
(
$sheetsIndex
=
0
;
$sheetsIndex
<
count
(
$cou
);
$sheetsIndex
++
){
$objWorksheet
=
$spreadsheet
->
getSheet
(
$sheetsIndex
);
$drawings
=
$objWorksheet
->
getDrawingCollection
();
$imgList
=
[];
$list
=
[];
// 所以表格格式化数据
foreach
(
$drawings
as
$index
=>
$drawing
)
{
// 图片类型:JPEG, PNG, GIF
$imageType
=
'png'
;
// $imageType = $drawing->getExtension();
$imageName
=
'image_'
.
time
()
.
$index
.
'.'
.
$imageType
;
$imagePath
=
'images/'
.
$imageName
;
$savePath
=
config
(
"config.resource_address"
)
.
'public/storage/images/'
.
$imageName
;
// 保存图片到本地
$drawing
->
getPath
()
?
Filesystem
::
put
(
$imagePath
,
file_get_contents
(
$drawing
->
getPath
()))
:
$drawing
->
save
(
$imagePath
);
array_push
(
$imgList
,
$savePath
);
}
$data
=
$objWorksheet
->
toArray
();
$title
=
$data
[
0
];
// 表格标题
$imgIndex
=
0
;
// 读取的图片当前下标
$error
=
0
;
// 是否有错误
$num
=
0
;
// 成功读取行数
$errorInfo
=
''
;
// 读取到当前报错的信息
foreach
(
$data
as
$index
=>
$value
){
$num
++
;
if
(
$index
>
0
){
$current
=
0
;
// 当前读取到的下标位置,取一次加1
$arr
=
[
'name'
=>
''
,
// 指标名称
'refer_type'
=>
''
,
// 信源类型
'remark'
=>
''
,
// 收集指南
'adminData'
=>
[],
// 展示端
'userData'
=>
[],
// 用户端
'not_collectible'
=>
''
,
// 是否可以采集
'not_collectible_remarks'
=>
''
,
//原因
'imgPath'
=>
''
,
//图片路径
'fileListPdf'
=>
''
,
//文件路径
'file_name'
=>
''
//文件名称
];
// 指标名称
if
(
empty
(
$value
[
$current
])){
$error
++
;
$errorInfo
=
'指标名称不能为空'
;
break
;
}
else
{
$arr
[
'name'
]
=
$value
[
$current
];
$current
++
;
}
// 信源类型
if
(
empty
(
$value
[
$current
])){
$error
++
;
$errorInfo
=
'信源信息错误!'
;
break
;
}
else
{
if
(
$value
[
1
]
!=
"官网/政府"
&&
$value
[
1
]
!=
"权威媒体"
&&
$value
[
1
]
!=
"其他信源"
){
$error
++
;
$errorInfo
=
'信源信息错误!'
;
break
;
}
else
{
if
(
$value
[
1
]
==
"官网/政府"
){
$arr
[
'refer_type'
]
=
1
;
}
else
if
(
$value
[
1
]
==
"官网/权威媒体"
){
$arr
[
'refer_type'
]
=
2
;
}
else
{
$arr
[
'refer_type'
]
=
3
;
}
}
$current
++
;
}
// 收集备注
$arr
[
'remark'
]
=
$value
[
$current
];
$current
++
;
// 文件路径
$arr
[
'fileListPdf'
]
=
$value
[
$current
];
$current
++
;
// 文件名称
$arr
[
'file_name'
]
=
$value
[
$current
];
$current
++
;
$adminSign
=
0
;
// 需要读取的列数 3 2
// 展示端数量
if
(
is_numeric
(
$value
[
$current
])){
if
(
$value
[
$current
]
>
20
){
$error
++
;
$errorInfo
=
'展示端自定义数值超出范围!'
;
break
;
}
$adminSign
=
$value
[
$current
];
$current
++
;
}
else
{
$error
++
;
$errorInfo
=
'展示端自定义数值非数值!'
;
break
;
}
// 展示端内容
if
(
$adminSign
>
0
){
for
(
$i
=
0
;
$i
<
$adminSign
;
$i
++
){
array_push
(
$arr
[
'adminData'
],[
'name'
=>
$title
[
$current
],
'value'
=>
$value
[
$current
]]);
$current
++
;
}
}
// 判断展示端的数据是否正确
if
(
$title
[
$current
]
!=
"用户端自定义数量"
){
$error
++
;
$errorInfo
=
'展示端的数量与要读取的列数不匹配!'
;
break
;
}
$userSign
=
0
;
// 需要读取的列数
// 用户端数量
if
(
is_numeric
(
$value
[
$current
])){
if
(
$value
[
$current
]
>
50
){
$error
++
;
$errorInfo
=
'用户端自定义数值超出范围!'
;
break
;
}
$userSign
=
$value
[
$current
];
$current
++
;
}
else
{
$error
++
;
$errorInfo
=
'用户端自定义数值非数值!'
;
break
;
}
// 用户端内容
if
(
$userSign
>
0
){
for
(
$i
=
0
;
$i
<
$userSign
;
$i
++
){
array_push
(
$arr
[
'userData'
],[
'name'
=>
$title
[
$current
],
'value'
=>
$value
[
$current
]]);
$current
++
;
}
}
// 判断用户端端的数据是否正确
if
(
$title
[
$current
]
!=
"是否可采集"
){
$error
++
;
$errorInfo
=
'用户端的数量与要读取的列数不匹配!'
;
break
;
}
// 是否可采集
if
(
empty
(
$value
[
$current
])){
$error
++
;
$errorInfo
=
'请填写是否可采集!'
;
break
;
}
else
{
if
(
$value
[
$current
]
==
'是'
){
$arr
[
'not_collectible'
]
=
''
;
}
else
{
$arr
[
'not_collectible'
]
=
1
;
}
// 不可采集的原因
$arr
[
'not_collectible_remarks'
]
=
$value
[
$current
];
$current
+=
2
;
}
// 是否有图片
if
(
!
empty
(
$value
[
$current
])){
if
(
$value
[
$current
]
==
"有"
){
if
(
isset
(
$imgList
[
$imgIndex
])){
$arr
[
'imgPath'
]
=
$imgList
[
$imgIndex
];
$imgIndex
++
;
}
else
{
$error
++
;
$num
=
'x'
;
$errorInfo
=
'是否有图片该列填写了“有”但是并没有放对应的图片'
;
break
;
}
}
$current
+=
2
;
}
else
{
$current
+=
2
;
}
array_push
(
$list
,
$arr
);
}
}
array_push
(
$listAll
,
$list
);
}
if
(
$error
!=
0
){
$message
=
"文件第"
.
$sheetsIndex
.
"页,第"
.
$num
.
"行数据错误,原因["
.
$errorInfo
.
"],请检查!"
;
return
[
'data'
=>
$listAll
,
'message'
=>
$message
,
'status'
=>
0
];
}
else
{
$message
=
"文件导入成功,共读取"
.
$sheetsIndex
.
"页,"
.
$num
.
"行!"
;
return
[
'data'
=>
$listAll
,
'message'
=>
$message
,
'status'
=>
1
];
}
}
catch
(
\Exception
$e
){
exception
(
$e
,
'ExcelFile.importFile'
);
}
}
/**
* 文件导入
* @return \josn|void
*/
public
function
importFile
()
{
try
{
$task_id
=
input
(
'task_id'
);
$normInfo
=
[];
$normInfo
[
'task_id'
]
=
input
(
'task_id'
);
$normInfo
[
'name'
]
=
input
(
'name'
);
$normInfo
[
'level'
]
=
input
(
'level'
);
$normInfo
[
'refer'
]
=
input
(
'refer'
);
$normInfo
[
'price'
]
=
input
(
'price'
);
$normInfo
[
'guide'
]
=
input
(
'guide'
);
$normInfo
[
'sort'
]
=
input
(
'sort'
);
$normInfo
[
'type'
]
=
1
;
Db
::
startTrans
();
$info
=
Db
::
name
(
'norm'
)
->
where
(
'name'
,
$normInfo
[
'name'
])
->
find
();
if
(
$info
){
$res
[
'message'
]
=
'子任务名称已存在!'
;
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
$norm_id
=
Db
::
name
(
'norm'
)
->
insertGetId
(
$normInfo
);
$file
=
request
()
->
file
(
'file'
);
// 上传到本地服务器
$savename
=
\think\facade\Filesystem
::
putFile
(
'import'
,
$file
);
$res
=
$this
->
importFormat
(
'storage/'
.
$savename
);
$taskInfo
=
Db
::
name
(
'task_package'
)
->
where
(
'id'
,
$task_id
)
->
find
();
$normInfo
=
Db
::
name
(
'norm'
)
->
where
(
'id'
,
$norm_id
)
->
find
();
if
(
empty
(
$taskInfo
)){
$res
[
'message'
]
=
'获取不到任务信息'
;
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
if
(
empty
(
$normInfo
)){
$res
[
'message'
]
=
'获取不到子任务信息'
;
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
// 格式化信息错误
if
(
$res
[
'status'
]
==
0
){
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
if
(
empty
(
$res
[
'data'
])){
$res
[
'message'
]
=
'表格内容为空'
;
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
// 开启数据库事务
$control
=
0
;
$user_id
=
1
;
//用户ID
foreach
(
$res
[
'data'
]
as
$resIndex
=>
$value
){
// 展时端自定义
$extendName
=
[];
$extendValue
=
[];
// 用户端自定义
$extendUserName
=
[];
$extendUserValue
=
[];
$normExtendSql
=
[];
// 指标自定义
// 展示端自定义
foreach
(
$value
[
$resIndex
][
'adminData'
]
as
$kk
){
if
(
in_array
(
$kk
[
'name'
],
$extendName
)){
$key
=
array_search
(
$kk
[
'name'
],
$extendName
);
if
(
!
in_array
(
$kk
[
'value'
],
$extendValue
[
$key
])){
array_push
(
$extendValue
[
$key
],
$kk
[
'value'
]);
}
}
else
{
array_push
(
$extendName
,
$kk
[
'name'
]);
array_push
(
$extendValue
,[
$kk
[
'value'
]]);
}
}
// 用户填写端自定义
foreach
(
$value
[
$resIndex
][
'userData'
]
as
$kk
){
if
(
in_array
(
$kk
[
'name'
],
$extendUserName
)){
$key
=
array_search
(
$kk
[
'name'
],
$extendUserName
);
if
(
!
in_array
(
$kk
[
'value'
],
$extendUserValue
[
$key
])){
array_push
(
$extendUserValue
[
$key
],
$kk
[
'value'
]);
}
}
else
{
array_push
(
$extendUserName
,
$kk
[
'name'
]);
array_push
(
$extendUserValue
,[
$kk
[
'value'
]]);
}
}
// 指标列表
$arr
=
[
'norm_id'
=>
$norm_id
,
'task_id'
=>
$task_id
,
'name'
=>
$value
[
$resIndex
][
'name'
],
'level'
=>
$normInfo
[
'level'
],
'refer'
=>
$normInfo
[
'refer'
],
'price'
=>
$normInfo
[
'price'
],
'status'
=>
$normInfo
[
'status'
],
'num'
=>
0
,
'sort'
=>
$normInfo
[
'sort'
],
'guide'
=>
$normInfo
[
'guide'
],
'type'
=>
1
,
];
$norm_list_id
=
Db
::
name
(
'norm_list'
)
->
insertGetId
(
$arr
);
if
(
empty
(
$norm_list_id
)){
$control
++
;
}
// 指标列表扩展
foreach
(
$value
[
$resIndex
][
'adminData'
]
as
$kk
){
$arr
=
[
'norm_id'
=>
$norm_id
,
'norm_list_id'
=>
$norm_list_id
,
'extend_name'
=>
$kk
[
'name'
],
'extend_value'
=>
$kk
[
'value'
],
'extend_type'
=>
1
];
$info
=
Db
::
name
(
'norm_list_extend'
)
->
insertGetId
(
$arr
);
if
(
empty
(
$info
)){
$control
++
;
}
}
// 指标领取
$arr
=
[
'task_id'
=>
$task_id
,
'norm_list_id'
=>
$norm_list_id
,
'norm_id'
=>
$norm_id
,
'user_id'
=>
$user_id
,
'status'
=>
4
,
'time'
=>
date
(
'Y-m-d H:i:s'
),
'review_time'
=>
date
(
'Y-m-d H:i:s'
),
'not_collectible'
=>
$value
[
$resIndex
][
'not_collectible'
],
'not_collectible_remarks'
=>
$value
[
$resIndex
][
'not_collectible_remarks'
],
];
$norm_receives_id
=
Db
::
name
(
'norm_receives'
)
->
insertGetId
(
$arr
);
if
(
empty
(
$norm_receives_id
)){
$control
++
;
}
// 用户填写指标
$arr
=
[
'task_id'
=>
$task_id
,
'norm_id'
=>
$norm_id
,
'norm_list_id'
=>
$norm_list_id
,
'norm_receive_id'
=>
$norm_receives_id
,
'user_id'
=>
$user_id
,
'refer_type'
=>
$value
[
$resIndex
][
'refer_type'
],
'remark'
=>
$value
[
$resIndex
][
'remark'
],
'imgPath'
=>
$value
[
$resIndex
][
'imgPath'
],
'fileListPdf'
=>
$value
[
$resIndex
][
'fileListPdf'
],
'file_name'
=>
$value
[
$resIndex
][
'file_name'
],
];
$norm_collects_id
=
Db
::
name
(
'norm_collects'
)
->
insertGetId
(
$arr
);
// 用户填写扩展
$info
=
Db
::
name
(
'norm_list_extend'
)
->
where
(
'norm_list_id'
,
$norm_list_id
)
->
find
();
foreach
(
$value
[
$resIndex
][
'userData'
]
as
$val
){
$arr
=
[
'norm_collects_id'
=>
$norm_collects_id
,
'norm_list_extend_id'
=>
$info
[
'id'
],
'norm_receive_id'
=>
$norm_receives_id
,
'task_id'
=>
$task_id
,
'norm_id'
=>
$norm_id
,
'extend_name'
=>
$val
[
'name'
],
'extend_value'
=>
$val
[
'value'
],
'extend_type'
=>
1
,
];
$info
=
Db
::
name
(
'norm_collects_extend'
)
->
insertGetId
(
$arr
);
}
//======================处理指标扩展
// 处理指标展示端自定义扩展
foreach
(
$extendName
as
$index
=>
$ss
){
$normExtendArr
=
[
'norm_id'
=>
$norm_id
,
'extend_name'
=>
$ss
,
'extend_value'
=>
implode
(
","
,
$extendValue
[
$index
]),
'extend_type'
=>
1
,
'required'
=>
1
,
'user_filled'
=>
0
,
'extend_remarks'
=>
''
,
];
array_push
(
$normExtendSql
,
$normExtendArr
);
}
// 处理指标用户端自定义扩展
foreach
(
$extendUserName
as
$index
=>
$hh
){
$normExtendArr
=
[
'norm_id'
=>
$norm_id
,
'extend_name'
=>
$hh
,
'extend_value'
=>
implode
(
","
,
$extendUserValue
[
$index
]),
'extend_type'
=>
1
,
'required'
=>
1
,
'user_filled'
=>
1
,
'extend_remarks'
=>
''
,
];
array_push
(
$normExtendSql
,
$normExtendArr
);
}
// 指标扩展信息
$info
=
Db
::
name
(
'norm_extend'
)
->
insertAll
(
$normExtendSql
);
}
// 文件格式化有问题
if
(
$res
[
'status'
]
==
0
||
$control
!=
0
){
if
(
$control
>
0
){
$res
[
'message'
]
=
'导入数据失败!'
;
}
Db
::
rollback
();
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
else
{
Db
::
commit
();
var_dump
(
$res
);
return
returnResult
(
config
(
"config.code.success"
),
$res
[
'message'
],
''
);
}
}
catch
(
\Exception
$e
){
Db
::
rollback
();
exception
(
$e
,
'ExcelFile.importFile'
);
}
}
/**
* @return void
* 按任务导出文件
*/
public
function
taskExportFile
()
{
try
{
$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
=
[
'title'
=>
$value
[
'name'
],
'data'
=>
[]];
$normList
=
Db
::
table
(
'norm_list'
)
->
where
(
'norm_id'
,
$value
[
'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
=
[
'norm'
=>
$value
[
'name'
],
'name'
=>
$val
[
'name'
],
'level'
=>
$val
[
'level'
],
'refer'
=>
$val
[
'refer'
],
'price'
=>
$val
[
'price'
],
'guide'
=>
$value
[
'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
();
// 设置为活动工作表
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
){
exception
(
$e
,
'ExcelFile.taskExportFile'
);
}
}
/**
* @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
=
[
'norm'
=>
$norm
[
'name'
],
'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
(
$normCollects
){
$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
);
}
}
else
{
$normExtendInfo
=
Db
::
table
(
'norm_extend'
)
->
where
(
'norm_id'
,
$norm
[
'id'
])
->
where
(
'user_filled'
,
1
)
->
select
();
foreach
(
$normExtendInfo
as
$normExtendInfoValue
){
$arr
=
[
'name'
=>
$normExtendInfoValue
[
'extend_name'
],
'value'
=>
$normExtendInfoValue
[
'extend_value'
]
?
$normExtendInfoValue
[
'extend_value'
]
:
'/'
];
array_push
(
$data
[
'user'
],
$arr
);
}
}
// 添加第一条指标信息
array_push
(
$sheet
[
'data'
],
$data
);
}
if
(
$sheet
[
'data'
]){
array_push
(
$list
,
$sheet
);
}
// 创建一个新的 Spreadsheet 对象
$spreadsheet
=
new
Spreadsheet
();
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
){
exception
(
$e
,
'ExcelFile.normExportFile'
);
}
}
/**
* @return void
* 按多个指标导出文件
*/
public
function
multipleExportFile
()
{
try
{
$Ids
=
input
(
'ids'
);
if
(
empty
(
$Ids
)){
return
returnResult
(
config
(
"config.code.error"
),
'请选择导出的子任务!'
,[]);
}
$data
=
[];
foreach
(
$Ids
as
$value
){
$info
=
Db
::
table
(
'norm'
)
->
where
(
'id'
,
$value
)
->
find
();
array_push
(
$data
,
$info
);
}
if
(
$data
){
$list
=
[];
foreach
(
$data
as
$value
){
$sheet
=
[
'title'
=>
$value
[
'name'
],
'data'
=>
[]];
$normList
=
Db
::
table
(
'norm_list'
)
->
where
(
'norm_id'
,
$value
[
'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
=
[
'norm'
=>
$value
[
'name'
],
'name'
=>
$val
[
'name'
],
'level'
=>
$val
[
'level'
],
'refer'
=>
$val
[
'refer'
],
'price'
=>
$val
[
'price'
],
'guide'
=>
$value
[
'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
();
// 设置为活动工作表
for
(
$i
=
0
;
$i
<
count
(
$list
);
$i
++
){
$this
->
exportFile
(
$spreadsheet
,
$i
,
$list
[
$i
][
'title'
],
$list
[
$i
][
'data'
]);
}
// 保存 ExcelFile 文件
$writer
=
new
Xlsx
(
$spreadsheet
);
$name
=
'xlsx/多选子任务导出_'
.
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.error"
),
'没有该任务存在!'
,[]);
}
}
catch
(
\Exception
$e
){
exception
(
$e
,
'ExcelFile.multipleExportFile'
);
}
}
/**
* 格式化单页表格数据
* @param $spreadsheet
* @param $number
* @param $title
* @param $data
* @return void
*/
public
function
exportFile
(
$spreadsheet
,
$number
,
$title
,
$data
)
{
try
{
$spreadsheet
->
createSheet
();
$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
=
[
'子任务名称'
,
'指标名称'
,
'难度等级'
,
'参考信源'
,
'单价'
,
'参考指南'
,
'优先级'
,
'用户收集备注'
,
'信源类型'
,
];
$arr
=
[];
foreach
(
$data
as
$index
=>
$value
)
{
foreach
(
$value
[
'admin'
]
as
$inx
=>
$val
){
if
(
!
in_array
(
$val
[
'name'
],
$arr
)){
array_push
(
$arr
,
$val
[
'name'
]);
}
}
foreach
(
$value
[
'user'
]
as
$inx
=>
$val
){
if
(
!
in_array
(
$val
[
'name'
],
$arr
)){
array_push
(
$arr
,
$val
[
'name'
]);
}
}
}
$title
=
array_merge
(
$title
,
$arr
);
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
as
$value
)
{
$position
=
0
;
$sheet
=
$spreadsheet
->
getActiveSheet
();
// 指标名称
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'norm'
]);
$position
++
;
// 指标名称
$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'
]
!=
"无"
&&
$value
[
'imgPath'
]
!=
"/"
){
// 创建一个 Drawing 对象,并设置图片的路径
$drawing
=
new
Drawing
();
$drawing
->
setName
(
'Sample Image'
);
$drawing
->
setDescription
(
'Sample Image'
);
$imgList
=
explode
(
","
,
$value
[
'imgPath'
]);
$words
=
explode
(
"storage"
,
$imgList
[
0
]);
if
(
count
(
$words
)
==
2
){
$path
=
'./storage'
.
$words
[
1
];
}
else
{
$path
=
'./storage/'
.
$words
[
0
];
}
$drawing
->
setPath
(
$path
);
// 图片路径
$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'
]
!=
"无"
&&
$value
[
'imgPath'
]
!=
"/"
){
// 创建一个 Drawing 对象,并设置图片的路径
$drawing
=
new
Drawing
();
$drawing
->
setName
(
'Sample Image'
);
$drawing
->
setDescription
(
'Sample Image'
);
$imgList
=
explode
(
","
,
$value
[
'imgPath'
]);
$words
=
explode
(
"storage"
,
$imgList
[
0
]);
$drawing
->
setPath
(
'./storage'
.
$words
[
1
]);
// 图片路径
// $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
++
;
}
}
catch
(
\Exception
$e
){
exception
(
$e
,
'ExcelFile.exportFile'
);
}
}
}
\ No newline at end of file
runtime/session/sess_9a8331d316fe296bae8a1a1f41ca1b30
0 → 100644
View file @
4fe0d1e9
a:1:{s:5:"users";a:10:{s:2:"id";i:1;s:4:"name";s:12:"开发人员";s:5:"phone";s:11:"18417180202";s:7:"account";s:5:"admin";s:8:"password";s:32:"e10adc3949ba59abbe56e057f20f883e";s:6:"status";i:1;s:4:"type";i:1;s:11:"create_time";s:1:"1";s:5:"email";s:18:"wesley_prc@163.com";s:13:"department_id";i:3;}}
\ No newline at end of file
runtime/session/sess_acb0c381fd1d72e898f32fac9f3f1f6c
0 → 100644
View file @
4fe0d1e9
a:1:{s:5:"users";a:10:{s:2:"id";i:3;s:4:"name";s:10:"管理员1";s:5:"phone";s:11:"18417180202";s:7:"account";s:8:"admin001";s:8:"password";s:32:"e10adc3949ba59abbe56e057f20f883e";s:6:"status";i:1;s:4:"type";i:1;s:11:"create_time";s:10:"1709196711";s:5:"email";s:0:"";s:13:"department_id";i:1;}}
\ No newline at end of file
runtime/session/sess_b4e3758727b2b9c530f29aab3f9a2228
0 → 100644
View file @
4fe0d1e9
a:1:{s:5:"users";a:10:{s:2:"id";i:1;s:4:"name";s:12:"开发人员";s:5:"phone";s:11:"18417180202";s:7:"account";s:5:"admin";s:8:"password";s:32:"e10adc3949ba59abbe56e057f20f883e";s:6:"status";i:1;s:4:"type";i:1;s:11:"create_time";s:1:"1";s:5:"email";s:18:"wesley_prc@163.com";s:13:"department_id";i:3;}}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment