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
5615cfc3
Commit
5615cfc3
authored
Apr 15, 2024
by
wenyi.chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
导入pdf
parent
eac39d4d
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
1161 additions
and
70 deletions
+1161
-70
app/api/controller/ExcelFile.php
+24
-62
app/api/controller/ExcelFilessssssss.php
+1054
-0
app/api/controller/Norm.php
+35
-1
app/api/controller/NormCollects.php
+28
-2
app/api/controller/TaskPackage.php
+9
-4
app/api/controller/Upload.php
+3
-1
app/api/route/api.php
+2
-0
runtime/session/sess_75f1472990e8c7cb747f128032bfb5ca
+2
-0
runtime/session/sess_aed0a9a703105fef024f8acb001acb3b
+2
-0
runtime/session/sess_b2b45fb0b1ecabc88f659ca396a1b9b1
+2
-0
No files found.
app/api/controller/ExcelFile.php
View file @
5615cfc3
...
...
@@ -19,64 +19,9 @@ use think\facade\Env;
use
think\facade\Db
;
class
ExcelFile
extends
BaseController
{
public
function
importFile1
()
{
try
{
$spreadsheet
=
IOFactory
::
load
(
'./import/测试.xls'
);
// $allSheets = $spreadsheet->getAllSheets();
$objWorksheet
=
$spreadsheet
->
getSheet
(
0
);
$drawings
=
$objWorksheet
->
getDrawingCollection
();
$imgList
=
[];
foreach
(
$drawings
as
$index
=>
$drawing
)
{
// 图片类型:JPEG, PNG, GIF
$imageType
=
$drawing
->
getExtension
();
$imageName
=
'image_'
.
$index
.
'.'
.
$imageType
;
$imagePath
=
'images/'
.
$imageName
;
// 保存图片到本地
$drawing
->
getPath
()
?
Filesystem
::
put
(
$imagePath
,
file_get_contents
(
$drawing
->
getPath
()))
:
$drawing
->
save
(
$imagePath
);
array_push
(
$imgList
,
$imagePath
);
// echo "图片已保存到:{$imagePath}\n";
}
dump
(
$imgList
);
// $data = $objWorksheet->toArray();
// $list = [];
// $i=0;
// foreach ($data as $index=>$value){
// if($index>0){
// $arr = [
// 'task_id'=>1,
// 'name'=>$value[1], // 指标名称
// 'level'=>1, // 难度等级
// 'name2'=>$value[4], // 参考信源
// 'name3'=>$value[5], // 单价
// 'name4'=>$value[6], // 参考指南
// 'name5'=>$value[7], // 任务状态
// 'name6'=>$value[8], //优先级高中低(3,2,1)
// 'name7'=>$value[9], //可领取次数
// 'name8'=>$value[10],
// 'name9'=>$value[11],
// 'name10'=>$value[12],
// 'name11'=>$value[13],
// 'name12'=>$value[14],
// 'name13'=>$value[15],
// 'name14'=>$value[16],
// ];
// if(empty($value[10])){
// $arr['name8'] = $imgList[$i];
// $i++;
// }
// array_push($list,$arr);
// }
// }
}
catch
(
\Exception
$e
){
exception
(
$e
,
'ExcelFile.importFile'
);
}
}
/**
* 格式化文件数据
*
导入指标
格式化文件数据
* @param $file //excel文件地址
* @return array|void
*/
...
...
@@ -89,7 +34,8 @@ class ExcelFile extends BaseController
$imgList
=
[];
foreach
(
$drawings
as
$index
=>
$drawing
)
{
// 图片类型:JPEG, PNG, GIF
$imageType
=
$drawing
->
getExtension
();
$imageType
=
'png'
;
// $imageType = $drawing->getExtension();
$imageName
=
'image_'
.
time
()
.
$index
.
'.'
.
$imageType
;
$imagePath
=
'images/'
.
$imageName
;
$savePath
=
config
(
"config.resource_address"
)
.
'public/storage/images/'
.
$imageName
;
...
...
@@ -119,6 +65,8 @@ class ExcelFile extends BaseController
'not_collectible'
=>
''
,
// 是否可以采集
'not_collectible_remarks'
=>
''
,
//原因
'imgPath'
=>
''
,
//图片路径
'fileListPdf'
=>
''
,
//文件路径
'file_name'
=>
''
//文件名称
];
// 指标名称
if
(
empty
(
$value
[
$current
])){
...
...
@@ -129,7 +77,6 @@ class ExcelFile extends BaseController
$arr
[
'name'
]
=
$value
[
$current
];
$current
++
;
}
// 信源类型
if
(
empty
(
$value
[
$current
])){
$error
++
;
...
...
@@ -156,6 +103,12 @@ class ExcelFile extends BaseController
$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
])){
...
...
@@ -188,7 +141,7 @@ class ExcelFile extends BaseController
$userSign
=
0
;
// 需要读取的列数
// 用户端数量
if
(
is_numeric
(
$value
[
$current
])){
if
(
$value
[
$current
]
>
2
0
){
if
(
$value
[
$current
]
>
5
0
){
$error
++
;
$errorInfo
=
'用户端自定义数值超出范围!'
;
break
;
...
...
@@ -280,7 +233,13 @@ class ExcelFile extends BaseController
$normInfo
[
'price'
]
=
input
(
'price'
);
$normInfo
[
'guide'
]
=
input
(
'guide'
);
$normInfo
[
'sort'
]
=
input
(
'sort'
);
$normInfo
[
'type'
]
=
input
(
'type'
);
$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'
);
// 上传到本地服务器
...
...
@@ -305,7 +264,7 @@ class ExcelFile extends BaseController
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
// 开启数据库事务
Db
::
startTrans
()
;
$control
=
1
;
$user_id
=
1
;
//用户ID
$normExtendSql
=
[];
// 指标自定义
// 展时端自定义
...
...
@@ -354,6 +313,7 @@ class ExcelFile extends BaseController
'num'
=>
0
,
'sort'
=>
$normInfo
[
'sort'
],
'guide'
=>
$normInfo
[
'guide'
],
'type'
=>
1
,
];
$norm_list_id
=
Db
::
name
(
'norm_list'
)
->
insertGetId
(
$arr
);
...
...
@@ -393,6 +353,8 @@ class ExcelFile extends BaseController
'refer_type'
=>
$value
[
'refer_type'
],
'remark'
=>
$value
[
'remark'
],
'imgPath'
=>
$value
[
'imgPath'
],
'fileListPdf'
=>
$value
[
'fileListPdf'
],
'file_name'
=>
$value
[
'file_name'
],
];
$norm_collects_id
=
Db
::
name
(
'norm_collects'
)
->
insertGetId
(
$arr
);
...
...
@@ -766,7 +728,7 @@ class ExcelFile extends BaseController
try
{
$Ids
=
input
(
'ids'
);
if
(
empty
(
$Ids
)){
return
returnResult
(
config
(
"config.code.
success
"
),
'请选择导出的子任务!'
,[]);
return
returnResult
(
config
(
"config.code.
error
"
),
'请选择导出的子任务!'
,[]);
}
$data
=
[];
foreach
(
$Ids
as
$value
){
...
...
app/api/controller/ExcelFilessssssss.php
0 → 100644
View file @
5615cfc3
<?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
ExcelFilessssssss
extends
BaseController
{
/**
* 导入指标格式化文件数据
* @param $file //excel文件地址
* @return array|void
*/
public
function
importFormat
(
$file
)
{
try
{
$spreadsheet
=
IOFactory
::
load
(
$file
);
$objWorksheet
=
$spreadsheet
->
getSheet
(
0
);
$drawings
=
$objWorksheet
->
getDrawingCollection
();
$imgList
=
[];
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
();
$list
=
[];
// 所以表格格式化数据
$num
=
0
;
// 成功读取行数
$error
=
0
;
// 读取到当前第几行错误
$errorInfo
=
''
;
// 读取到当前报错的信息
$title
=
$data
[
0
];
// 表格标题
$imgIndex
=
0
;
// 读取的图片当前下标
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'
=>
''
,
//图片路径
];
// 指标名称
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
++
;
$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
]
>
20
){
$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
);
}
}
if
(
$error
!=
0
){
$message
=
"文件第"
.
$num
.
"行数据错误,原因["
.
$errorInfo
.
"],请检查!"
;
return
[
'data'
=>
$list
,
'message'
=>
$message
,
'status'
=>
0
];
}
else
{
$message
=
"文件导入成功,共读取"
.
$num
.
"行!"
;
return
[
'data'
=>
$list
,
'message'
=>
$message
,
'status'
=>
1
];
}
}
catch
(
\Exception
$e
){
var_dump
(
$e
->
getMessage
());
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
=
1
;
$user_id
=
1
;
//用户ID
$normExtendSql
=
[];
// 指标自定义
// 展时端自定义
$extendName
=
[];
$extendValue
=
[];
// 用户端自定义
$extendUserName
=
[];
$extendUserValue
=
[];
foreach
(
$res
[
'data'
]
as
$value
){
// 展示端自定义
foreach
(
$value
[
'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
[
'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
[
'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
);
// 指标列表扩展
foreach
(
$value
[
'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
];
Db
::
name
(
'norm_list_extend'
)
->
insertGetId
(
$arr
);
}
// 指标领取
$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
[
'not_collectible'
],
'not_collectible_remarks'
=>
$value
[
'not_collectible_remarks'
],
];
$norm_receives_id
=
Db
::
name
(
'norm_receives'
)
->
insertGetId
(
$arr
);
// 用户填写指标
$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
[
'refer_type'
],
'remark'
=>
$value
[
'remark'
],
'imgPath'
=>
$value
[
'imgPath'
],
];
$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
[
'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
,
];
Db
::
name
(
'norm_collects_extend'
)
->
insertGetId
(
$arr
);
}
}
//======================处理指标扩展
// 处理指标展示端自定义扩展
foreach
(
$extendName
as
$index
=>
$value
){
$normExtendArr
=
[
'norm_id'
=>
$norm_id
,
'extend_name'
=>
$value
,
'extend_value'
=>
implode
(
","
,
$extendValue
[
$index
]),
'extend_type'
=>
1
,
'required'
=>
1
,
'user_filled'
=>
0
,
'extend_remarks'
=>
''
,
];
array_push
(
$normExtendSql
,
$normExtendArr
);
}
// 处理指标用户端自定义扩展
foreach
(
$extendUserName
as
$index
=>
$value
){
$normExtendArr
=
[
'norm_id'
=>
$norm_id
,
'extend_name'
=>
$value
,
'extend_value'
=>
implode
(
","
,
$extendUserValue
[
$index
]),
'extend_type'
=>
1
,
'required'
=>
1
,
'user_filled'
=>
1
,
'extend_remarks'
=>
''
,
];
array_push
(
$normExtendSql
,
$normExtendArr
);
}
// 指标扩展信息
Db
::
name
(
'norm_extend'
)
->
insertAll
(
$normExtendSql
);
// 文件格式化有问题
if
(
$res
[
'status'
]
==
0
){
Db
::
rollback
();
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
else
{
Db
::
commit
();
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.success"
),
''
);
}
}
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
app/api/controller/Norm.php
View file @
5615cfc3
...
...
@@ -115,7 +115,6 @@ class Norm
'refer'
=>
$data
[
'refer'
],
'price'
=>
$data
[
'price'
],
'guide'
=>
$data
[
'guide'
],
'type'
=>
1
,
'num'
=>
$this
->
num
,
];
$normBus
=
new
CommonBus
(
'NormBus'
);
// 通过公共业务初始化指标类
...
...
@@ -529,6 +528,41 @@ class Norm
}
/**
* 删除任务
* @return \josn|void
*/
public
function
delete
()
{
try
{
// 数据接收
$normId
=
input
(
"param.norm_id"
,
''
,
"trim"
);
// 业务处理
Db
::
startTrans
();
$control
=
1
;
$bus
=
new
\app\api\business\CommonBus
(
'NormBus'
);
$info
=
$bus
->
deleteData
(
$normId
);
$NormCollectsBus
=
new
\app\api\business\CommonBus
(
'NormCollectsBus'
);
$result
=
$NormCollectsBus
->
conditionDeletion
([
'norm_id'
=>
$normId
]);
$NormCollectsExtendBus
=
new
\app\api\business\CommonBus
(
'NormCollectsExtendBus'
);
$result
=
$NormCollectsExtendBus
->
conditionDeletion
([
'norm_id'
=>
$normId
]);
$NormListBus
=
new
\app\api\business\CommonBus
(
'NormListBus'
);
$result
=
$NormListBus
->
conditionDeletion
([
'norm_id'
=>
$normId
]);
$NormReceivesBus
=
new
\app\api\business\CommonBus
(
'NormReceivesBus'
);
$result
=
$NormReceivesBus
->
conditionDeletion
([
'norm_id'
=>
$normId
]);
// 全部添加完成提交
if
(
$control
==
1
){
Db
::
commit
();
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.success"
),
$info
);
}
else
{
Db
::
rollback
();
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.null_data"
),[]);
}
}
catch
(
\Exception
$e
){
exception
(
$e
,
'TaskPackage.add'
);
}
}
/**
* 返回最后一条信息
* @return \josn|void
*/
...
...
app/api/controller/NormCollects.php
View file @
5615cfc3
...
...
@@ -30,7 +30,6 @@ class NormCollects extends AuthBase
$data
[
'remark'
]
=
trim
(
$queryArr
[
'addItem'
][
'remark'
]);
$data
[
'imgPath'
]
=
$queryArr
[
'editorImgList'
];
$data
[
'fileListPdf'
]
=
$queryArr
[
'fileListPdf'
];
$data
[
'editorContent'
]
=
$queryArr
[
'editorContent'
];
$data
[
'user_id'
]
=
$this
->
userId
;
if
(
empty
(
$data
[
'norm_list_id'
])
||
empty
(
$data
[
'task_id'
])
||
empty
(
$data
[
'norm_id'
])
||
empty
(
$data
[
'norm_receive_id'
])
||
empty
(
$data
[
'user_id'
])){
errorRecord
(
'NormCollects.add'
,
json_encode
(
$data
),
true
);
...
...
@@ -56,9 +55,17 @@ class NormCollects extends AuthBase
$data
[
'imgPath'
]
=
''
;
}
if
(
$data
[
'fileListPdf'
]){
$data
[
'fileListPdf'
]
=
implode
(
','
,
$data
[
'fileListPdf'
]);
$file_name
=
[];
$fileUrl
=
[];
foreach
(
$data
[
'fileListPdf'
]
as
$value
){
array_push
(
$file_name
,
$value
[
'name'
]);
array_push
(
$fileUrl
,
$value
[
'url'
]);
}
$data
[
'fileListPdf'
]
=
implode
(
','
,
$fileUrl
);
$data
[
'file_name'
]
=
implode
(
','
,
$file_name
);
}
else
{
$data
[
'fileListPdf'
]
=
''
;
$data
[
'file_name'
]
=
''
;
}
$NormCollectsBus
=
new
\app\api\business\CommonBus
(
'NormCollectsBus'
);
// 通过公共业务初始化指标类
$res
=
$NormCollectsBus
->
getConditionalQuery
(
$arr
);
...
...
@@ -195,6 +202,8 @@ class NormCollects extends AuthBase
$data
[
'remark'
]
=
trim
(
$queryArr
[
'addItem'
][
'remark'
]);
$data
[
'imgPath'
]
=
$queryArr
[
'editorImgList'
];
$data
[
'editorContent'
]
=
$queryArr
[
'editorContent'
];
$fileListPdf
=
$queryArr
[
'fileListPdf'
];
$originalUpload
=
$queryArr
[
'originalUpload'
];
$data
[
'user_id'
]
=
$this
->
userId
;
if
(
empty
(
$data
[
'norm_list_id'
])
||
empty
(
$data
[
'task_id'
])
||
empty
(
$data
[
'norm_id'
])
||
empty
(
$data
[
'norm_receive_id'
])
||
empty
(
$data
[
'user_id'
])){
errorRecord
(
'NormCollects.add'
,
json_encode
(
$data
),
true
);
...
...
@@ -219,6 +228,21 @@ class NormCollects extends AuthBase
}
else
{
$data
[
'imgPath'
]
=
''
;
}
// 新文件上传
$data
[
'fileListPdf'
]
=
array_merge
(
$fileListPdf
,
$originalUpload
);
if
(
$data
[
'fileListPdf'
]){
$file_name
=
[];
$fileUrl
=
[];
foreach
(
$data
[
'fileListPdf'
]
as
$value
){
array_push
(
$file_name
,
$value
[
'name'
]);
array_push
(
$fileUrl
,
$value
[
'url'
]);
}
$data
[
'fileListPdf'
]
=
implode
(
','
,
$fileUrl
);
$data
[
'file_name'
]
=
implode
(
','
,
$file_name
);
}
else
{
$data
[
'fileListPdf'
]
=
''
;
$data
[
'file_name'
]
=
''
;
}
$NormCollectsBus
=
new
\app\api\business\CommonBus
(
'NormCollectsBus'
);
// 通过公共业务初始化指标类
$res
=
$NormCollectsBus
->
getConditionalQuery
(
$arr
);
if
(
empty
(
$res
)){
...
...
@@ -235,6 +259,8 @@ class NormCollects extends AuthBase
'remark'
=>
$data
[
'remark'
],
'imgPath'
=>
$data
[
'imgPath'
],
'editorContent'
=>
$data
[
'editorContent'
],
'fileListPdf'
=>
$data
[
'fileListPdf'
],
'file_name'
=>
$data
[
'file_name'
],
];
$update
=
$NormCollectsBus
->
updateData
(
$updateData
,
$where
);
if
(
empty
(
$update
)){
...
...
app/api/controller/TaskPackage.php
View file @
5615cfc3
...
...
@@ -40,15 +40,20 @@ class TaskPackage extends AuthBase
// $normRes = $normBus->getConditionalQuery(['task_id'=>$value['id']]);
// // 领取进度
$NormBus
=
new
CommonBus
(
'NormBus'
);
// 通过公共业务初始化指标类
$NormInfo
=
$NormBus
->
getConditionalQuery
([
'task_id'
=>
$value
[
'id'
]]);
$NormInfo
=
$NormBus
->
getConditionalQuery
([
'task_id'
=>
$value
[
'id'
]
,
'type'
=>
0
]);
$NormListBus
=
new
CommonBus
(
'NormListBus'
);
// 通过公共业务初始化指标类
$totalDegree
=
$NormListBus
->
getConditionalQueryAll
([
'task_id'
=>
$value
[
'id'
]]);
$totalDegree
=
$NormListBus
->
getConditionalQueryAll
([
'task_id'
=>
$value
[
'id'
]
,
'type'
=>
0
]);
$NormReceivesBus
=
new
CommonBus
(
'NormReceivesBus'
);
// 通过公共业务初始化指标类
$receivedTimes
=
$NormReceivesBus
->
getConditionalQueryAll
([
'task_id'
=>
$value
[
'id'
]]);
$NormCollectsBus
=
new
CommonBus
(
'NormCollectsBus'
);
// 通过公共业务初始化指标类
$collectsTimes
=
$NormCollectsBus
->
getConditionalQueryAll
([
'task_id'
=>
$value
[
'id'
]]);
if
(
$totalDegree
){
$totalNum
=
count
(
$totalDegree
)
*
$NormInfo
[
'num'
];
if
(
empty
(
$NormInfo
)){
$num
=
0
;
}
else
{
$num
=
$NormInfo
[
'num'
];
}
$totalNum
=
count
(
$totalDegree
)
*
$num
;
$result
[
'data'
][
$index
][
'receivedQuantity'
]
=
count
(
$receivedTimes
)
.
'/'
.
$totalNum
;
$result
[
'data'
][
$index
][
'collectsQuantity'
]
=
count
(
$collectsTimes
)
.
'/'
.
$totalNum
;
}
else
{
...
...
@@ -92,7 +97,7 @@ class TaskPackage extends AuthBase
}
/**
*
发布
任务
*
删除
任务
* @return \josn|void
*/
public
function
delete
()
...
...
app/api/controller/Upload.php
View file @
5615cfc3
...
...
@@ -69,6 +69,7 @@ class Upload
return
json
([
'errno'
=>
0
,
'data'
=>
[
'name'
=>
$file
->
getOriginalName
(),
'url'
=>
$url
,
'alt'
=>
$image_name
,
]
...
...
@@ -77,8 +78,9 @@ class Upload
// 文件上传失败
return
json
([
'errno'
=>
1
,
'name'
=>
''
,
'data'
=>
[],
'msg'
=>
$file
->
getError
()
'msg'
=>
'上传失败!'
]);
}
}
catch
(
\Exception
$e
){
...
...
app/api/route/api.php
View file @
5615cfc3
...
...
@@ -55,6 +55,7 @@ Route::rule("tasks/receive","TaksReceives/receive"); // 用户领取操作
/***************************任务包相关 */
Route
::
rule
(
"taskPackage/add"
,
"TaskPackage/add"
);
// 发布任务
Route
::
rule
(
"taskPackage/list"
,
"TaskPackage/list"
);
// 所有任务列表
Route
::
rule
(
"taskPackage/delete"
,
"TaskPackage/delete"
);
// 删除任务列表
/***************************指标相关 */
Route
::
rule
(
"norm/add"
,
"Norm/add"
);
// 新增指标
...
...
@@ -62,6 +63,7 @@ Route::rule("norm/list","Norm/list"); // 指标列表
Route
::
rule
(
"norm/detail"
,
"Norm/detail"
);
// 指标详情
Route
::
rule
(
"norm/edit"
,
"Norm/edit"
);
// 指标详情
Route
::
rule
(
"norm/finalData"
,
"Norm/finalData"
);
// 返回最后的ID
Route
::
rule
(
"norm/delete"
,
"Norm/delete"
);
// 删除详情
/***************************指标领取相关 */
Route
::
rule
(
"normList/list"
,
"NormList/list"
);
// 指标待领取
...
...
runtime/session/sess_75f1472990e8c7cb747f128032bfb5ca
0 → 100644
View file @
5615cfc3
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_aed0a9a703105fef024f8acb001acb3b
0 → 100644
View file @
5615cfc3
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_b2b45fb0b1ecabc88f659ca396a1b9b1
0 → 100644
View file @
5615cfc3
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