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
a86ffc53
Commit
a86ffc53
authored
Apr 17, 2024
by
cwy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
指标详情修改完成
parent
f0ccd835
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1309 additions
and
26 deletions
+1309
-26
app/api/business/CommonBus.php
+18
-0
app/api/controller/ExcelFile.php
+13
-26
app/api/controller/ExcelFileqqqqqq.php
+1114
-0
app/api/controller/Norm.php
+138
-0
app/api/route/api.php
+1
-0
app/common/model/mysql/NormReceives.php
+25
-0
No files found.
app/api/business/CommonBus.php
View file @
a86ffc53
...
...
@@ -61,6 +61,24 @@ class CommonBus extends BaseBus
}
/**
* 根据条件查询多条信息分页
* 示例:['id'=>1,'name'=>'测试']
* @return array|false
*/
public
function
getConditionalQueryAllPaging
(
$where
,
$page
,
$limit
)
{
try
{
$info
=
$this
->
model
->
getConditionalQueryAllPaging
(
$where
,
$page
,
$limit
);
if
(
empty
(
$info
)){
return
false
;
}
return
$info
->
toArray
();
}
catch
(
\Exception
$e
)
{
exception
(
$e
,
$this
->
className
.
'.getConditionalQueryAll'
);
}
}
/**
* 获取多个数据
* @return void
*/
...
...
app/api/controller/ExcelFile.php
View file @
a86ffc53
...
...
@@ -238,6 +238,12 @@ class ExcelFile extends BaseController
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
);
$spreadsheet
=
IOFactory
::
load
(
'storage/'
.
$savename
);
$objWorksheet
=
$spreadsheet
->
getSheet
(
0
);
// 只允许读取第一页,多页请分开文档
$res
=
$this
->
importFormat
(
$objWorksheet
);
$taskInfo
=
Db
::
name
(
'task_package'
)
->
where
(
'id'
,
$task_id
)
->
find
();
$normInfo
=
Db
::
name
(
'norm'
)
->
where
(
'id'
,
$norm_id
)
->
find
();
if
(
empty
(
$taskInfo
)){
...
...
@@ -248,26 +254,16 @@ class ExcelFile extends BaseController
$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
){
return
returnResult
(
config
(
"config.code.error"
),
'文件第'
.
(
$sheetsIndex
+
1
)
.
'页,'
.
$res
[
'message'
]);
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
if
(
empty
(
$res
[
'data'
])){
$res
[
'message'
]
=
'表格内容为空'
;
return
returnResult
(
config
(
"config.code.error"
),
'文件第'
.
(
$sheetsIndex
+
1
)
.
'页,'
.
$res
[
'message'
]);
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
$num
+=
$res
[
'num'
];
// 开启数据库事务
$control
=
0
;
$user_id
=
1
;
//用户ID
$normExtendSql
=
[];
// 指标自定义
// 展时端自定义
...
...
@@ -291,7 +287,6 @@ class ExcelFile extends BaseController
array_push
(
$extendValue
,[
$kk
[
'value'
]]);
}
}
// 用户填写端自定义
foreach
(
$value
[
'userData'
]
as
$kk
){
if
(
in_array
(
$kk
[
'name'
],
$extendUserName
)){
...
...
@@ -332,10 +327,7 @@ class ExcelFile extends BaseController
'extend_value'
=>
$kk
[
'value'
],
'extend_type'
=>
1
];
$sqlInser
=
Db
::
name
(
'norm_list_extend'
)
->
insertGetId
(
$arr
);
if
(
empty
(
$sqlInser
)){
$control
++
;
}
Db
::
name
(
'norm_list_extend'
)
->
insertGetId
(
$arr
);
}
// 指标领取
...
...
@@ -364,8 +356,6 @@ 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
);
if
(
empty
(
$norm_collects_id
)){
...
...
@@ -421,24 +411,21 @@ class ExcelFile extends BaseController
];
array_push
(
$normExtendSql
,
$normExtendArr
);
}
foreach
(
$normExtendSql
as
$value
){
// 指标扩展信息
$sqlInser
=
Db
::
name
(
'norm_extend'
)
->
insertGetId
(
$value
);
$sqlInser
=
Db
::
name
(
'norm_extend'
)
->
insertAll
(
$normExtendSql
);
if
(
empty
(
$sqlInser
)){
$control
++
;
}
}
}
// 文件格式化有问题
if
(
$res
[
'status'
]
==
0
||
$control
>
0
){
if
(
$control
>
0
){
$res
[
'message'
]
=
'
文件第'
.
$sheetsIndex
.
'页入库错误
!'
;
$res
[
'message'
]
=
'
数据无法入库
!'
;
}
Db
::
rollback
();
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
else
{
Db
::
commit
();
return
returnResult
(
config
(
"config.code.success"
),
'导入成功,共'
.
$sheetsIndex
.
'页'
.
$num
.
"行"
,
''
);
return
returnResult
(
config
(
"config.code.success"
),
$res
[
'message'
]
,
''
);
}
}
catch
(
\Exception
$e
){
Db
::
rollback
();
...
...
app/api/controller/ExcelFileqqqqqq.php
0 → 100644
View file @
a86ffc53
<?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
ExcelFileqqqqqq
extends
BaseController
{
/**
* 导入指标格式化文件数据
* @param $file //excel文件地址
* @return array|void
*/
public
function
importFormat
(
$objWorksheet
)
{
try
{
$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'
=>
''
,
//图片路径
'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
);
}
}
if
(
$error
!=
0
){
$message
=
"第"
.
$num
.
"行数据错误,原因["
.
$errorInfo
.
"],请检查!"
;
return
[
'data'
=>
$list
,
'message'
=>
$message
,
'status'
=>
0
,
'num'
=>
$num
];
}
else
{
$message
=
"导入成功,共读取"
.
$num
.
"行!"
;
return
[
'data'
=>
$list
,
'message'
=>
$message
,
'status'
=>
1
,
'num'
=>
$num
];
}
}
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
);
$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'
]);
}
$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
){
return
returnResult
(
config
(
"config.code.error"
),
'文件第'
.
(
$sheetsIndex
+
1
)
.
'页,'
.
$res
[
'message'
]);
}
if
(
empty
(
$res
[
'data'
])){
$res
[
'message'
]
=
'表格内容为空'
;
return
returnResult
(
config
(
"config.code.error"
),
'文件第'
.
(
$sheetsIndex
+
1
)
.
'页,'
.
$res
[
'message'
]);
}
$num
+=
$res
[
'num'
];
// 开启数据库事务
$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
);
if
(
empty
(
$norm_list_id
)){
$control
++
;
}
// 指标列表扩展
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
];
$sqlInser
=
Db
::
name
(
'norm_list_extend'
)
->
insertGetId
(
$arr
);
if
(
empty
(
$sqlInser
)){
$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
[
'not_collectible'
],
'not_collectible_remarks'
=>
$value
[
'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
[
'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
);
if
(
empty
(
$norm_collects_id
)){
$control
++
;
}
// 用户填写扩展
$info
=
Db
::
name
(
'norm_list_extend'
)
->
where
(
'norm_list_id'
,
$norm_list_id
)
->
find
();
if
(
empty
(
$info
)){
$control
++
;
}
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
,
];
$sqlInser
=
Db
::
name
(
'norm_collects_extend'
)
->
insertGetId
(
$arr
);
if
(
empty
(
$sqlInser
)){
$control
++
;
}
}
}
//======================处理指标扩展
// 处理指标展示端自定义扩展
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
);
}
foreach
(
$normExtendSql
as
$value
){
// 指标扩展信息
$sqlInser
=
Db
::
name
(
'norm_extend'
)
->
insertGetId
(
$value
);
if
(
empty
(
$sqlInser
)){
$control
++
;
}
}
}
// 文件格式化有问题
if
(
$res
[
'status'
]
==
0
||
$control
>
0
){
if
(
$control
>
0
){
$res
[
'message'
]
=
'文件第'
.
$sheetsIndex
.
'页入库错误!'
;
}
Db
::
rollback
();
return
returnResult
(
config
(
"config.code.error"
),
$res
[
'message'
]);
}
else
{
Db
::
commit
();
return
returnResult
(
config
(
"config.code.success"
),
'导入成功,共'
.
$sheetsIndex
.
'页'
.
$num
.
"行"
,
''
);
}
}
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:CW1'
)
->
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
,
'审核状态'
);
$col
=
'A'
;
$column
=
[
'A'
];
for
(
$coli
=
0
;
$coli
<
100
;
$coli
++
)
{
$col
=
$this
->
excelColPlus
(
$col
);
array_push
(
$column
,
$col
);
}
// 遍历标题数组,设置每个单元格的值
foreach
(
$title
as
$columns
=>
$val
)
{
// 'A1', 'B1', 'C1', ...
$cell
=
$column
[
$columns
]
.
'1'
;
// 设置单元格的值
$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
++
;
}
$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'
);
}
}
// 求$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/Norm.php
View file @
a86ffc53
...
...
@@ -221,6 +221,144 @@ class Norm
public
function
detail
()
{
$id
=
input
(
"param.id"
);
$page
=
input
(
"param.page"
)
?
input
(
"param.page"
)
:-
1
;
$limit
=
input
(
"param.limit"
)
?
input
(
"param.limit"
)
:
10
;
if
(
empty
(
$id
)){
return
returnResult
(
config
(
"config.code.error"
),
'填写信息错误,请检查!'
);
}
$normBus
=
new
CommonBus
(
'NormBus'
);
// 通过公共业务初始化指标类
$data
=
[];
// 指标详情
$res
=
$normBus
->
getConditionalQuery
([
'id'
=>
$id
]);
// 指标扩展详情
$data
[
'addItem'
]
=
$res
;
$normExtendBus
=
new
CommonBus
(
'NormExtendBus'
);
$res
=
$normExtendBus
->
getConditionalQueryAll
([
'norm_id'
=>
$id
]);
$data
[
'custom'
]
=
$res
;
// 领取信息
$NormReceivesBus
=
new
CommonBus
(
'NormReceivesBus'
);
// 通过公共业务初始化指标类
if
(
$page
==
-
1
){
$data
[
'receivesList'
]
=
$NormReceivesBus
->
getConditionalQueryAll
([
'norm_id'
=>
$id
]);
}
else
{
$list
=
$NormReceivesBus
->
getConditionalQueryAllPaging
([
'norm_id'
=>
$id
],
$page
,
$limit
);
// var_dump($list);
$data
[
'receivesList'
]
=
$list
[
'data'
];
$data
[
'total'
]
=
$list
[
'total'
];
}
if
(
!
empty
(
$data
[
'receivesList'
])){
foreach
(
$data
[
'receivesList'
]
as
$index
=>
$vlues
){
$TaskPackageBus
=
new
CommonBus
(
'TaskPackageBus'
);
// 通过公共业务初始化指标类
$data
[
'receivesList'
][
$index
][
'task_info'
]
=
$TaskPackageBus
->
getConditionalQuery
([
'id'
=>
$vlues
[
'task_id'
]]);
$NormListBus
=
new
CommonBus
(
'NormListBus'
);
// 通过公共业务初始化指标类
$data
[
'receivesList'
][
$index
][
'norm_list_info'
]
=
$NormListBus
->
getConditionalQuery
([
'id'
=>
$vlues
[
'norm_list_id'
]]);
$NormListExtendBus
=
new
CommonBus
(
'NormListExtendBus'
);
// 通过公共业务初始化指标类
$data
[
'receivesList'
][
$index
][
'norm_list_extend'
]
=
$NormListExtendBus
->
getConditionalQueryAll
([
'norm_list_id'
=>
$vlues
[
'norm_list_id'
]]);
$NormCollectsBus
=
new
CommonBus
(
'NormCollectsBus'
);
// 通过公共业务初始化指标类
$collectsInfo
=
$NormCollectsBus
->
getConditionalQuery
([
'norm_receive_id'
=>
$vlues
[
'id'
]]);
if
(
$collectsInfo
){
$NormCollectsExtendBus
=
new
CommonBus
(
'NormCollectsExtendBus'
);
// 通过公共业务初始化指标类
$normCollectsExtend
=
$NormCollectsExtendBus
->
getConditionalQueryAll
([
'norm_collects_id'
=>
$collectsInfo
[
'id'
]]);
$data
[
'receivesList'
][
$index
][
'refer_type'
]
=
$collectsInfo
[
'refer_type'
];
$data
[
'receivesList'
][
$index
][
'remark'
]
=
$collectsInfo
[
'remark'
];
$data
[
'receivesList'
][
$index
][
'imgPath'
]
=
$collectsInfo
[
'imgPath'
];
$data
[
'receivesList'
][
$index
][
'fileListPdf'
]
=
$collectsInfo
[
'fileListPdf'
];
$data
[
'receivesList'
][
$index
][
'file_name'
]
=
$collectsInfo
[
'file_name'
];
$data
[
'receivesList'
][
$index
][
'normCollectsExtend'
]
=
$normCollectsExtend
;
}
else
{
$normExtendBus
=
new
CommonBus
(
'NormExtendBus'
);
$res
=
$normExtendBus
->
getConditionalQueryAll
([
'norm_id'
=>
$id
,
'user_filled'
=>
1
]);
$data
[
'receivesList'
][
$index
][
'refer_type'
]
=
''
;
$data
[
'receivesList'
][
$index
][
'remark'
]
=
''
;
$data
[
'receivesList'
][
$index
][
'imgPath'
]
=
''
;
$data
[
'receivesList'
][
$index
][
'fileListPdf'
]
=
$collectsInfo
[
'fileListPdf'
];
$data
[
'receivesList'
][
$index
][
'file_name'
]
=
$collectsInfo
[
'file_name'
];
$data
[
'receivesList'
][
$index
][
'normCollectsExtend'
]
=
$res
;
}
}
}
if
(
$data
){
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.success"
),
$data
);
}
else
{
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.null_data"
),[]);
}
}
/**
* 返回指标完整详情信息
* @return \josn
*/
public
function
whole
()
{
$id
=
input
(
"param.id"
);
$page
=
input
(
"param.page"
)
?
input
(
"param.page"
)
:-
1
;
$limit
=
input
(
"param.limit"
)
?
input
(
"param.limit"
)
:
10
;
if
(
empty
(
$id
)){
return
returnResult
(
config
(
"config.code.error"
),
'填写信息错误,请检查!'
);
}
$normBus
=
new
CommonBus
(
'NormBus'
);
// 通过公共业务初始化指标类
$data
=
[];
// 指标详情
$res
=
$normBus
->
getConditionalQuery
([
'id'
=>
$id
]);
// 指标扩展详情
$data
[
'addItem'
]
=
$res
;
$normExtendBus
=
new
CommonBus
(
'NormExtendBus'
);
$res
=
$normExtendBus
->
getConditionalQueryAll
([
'norm_id'
=>
$id
]);
$data
[
'custom'
]
=
$res
;
// 领取信息
$NormReceivesBus
=
new
CommonBus
(
'NormReceivesBus'
);
// 通过公共业务初始化指标类
if
(
$page
==
-
1
){
$data
[
'receivesList'
]
=
$NormReceivesBus
->
getConditionalQueryAll
([
'norm_id'
=>
$id
]);
}
else
{
$list
=
$NormReceivesBus
->
getConditionalQueryAllPaging
([
'norm_id'
=>
$id
],
$page
,
$limit
);
// var_dump($list);
$data
[
'receivesList'
]
=
$list
[
'data'
];
$data
[
'total'
]
=
$list
[
'total'
];
}
if
(
!
empty
(
$data
[
'receivesList'
])){
foreach
(
$data
[
'receivesList'
]
as
$index
=>
$vlues
){
$TaskPackageBus
=
new
CommonBus
(
'TaskPackageBus'
);
// 通过公共业务初始化指标类
$data
[
'receivesList'
][
$index
][
'task_info'
]
=
$TaskPackageBus
->
getConditionalQuery
([
'id'
=>
$vlues
[
'task_id'
]]);
$NormListBus
=
new
CommonBus
(
'NormListBus'
);
// 通过公共业务初始化指标类
$data
[
'receivesList'
][
$index
][
'norm_list_info'
]
=
$NormListBus
->
getConditionalQuery
([
'id'
=>
$vlues
[
'norm_list_id'
]]);
$NormListExtendBus
=
new
CommonBus
(
'NormListExtendBus'
);
// 通过公共业务初始化指标类
$data
[
'receivesList'
][
$index
][
'norm_list_extend'
]
=
$NormListExtendBus
->
getConditionalQueryAll
([
'norm_list_id'
=>
$vlues
[
'norm_list_id'
]]);
$NormCollectsBus
=
new
CommonBus
(
'NormCollectsBus'
);
// 通过公共业务初始化指标类
$collectsInfo
=
$NormCollectsBus
->
getConditionalQuery
([
'norm_receive_id'
=>
$vlues
[
'id'
]]);
if
(
$collectsInfo
){
$NormCollectsExtendBus
=
new
CommonBus
(
'NormCollectsExtendBus'
);
// 通过公共业务初始化指标类
$normCollectsExtend
=
$NormCollectsExtendBus
->
getConditionalQueryAll
([
'norm_collects_id'
=>
$collectsInfo
[
'id'
]]);
$data
[
'receivesList'
][
$index
][
'refer_type'
]
=
$collectsInfo
[
'refer_type'
];
$data
[
'receivesList'
][
$index
][
'remark'
]
=
$collectsInfo
[
'remark'
];
$data
[
'receivesList'
][
$index
][
'imgPath'
]
=
$collectsInfo
[
'imgPath'
];
$data
[
'receivesList'
][
$index
][
'fileListPdf'
]
=
$collectsInfo
[
'fileListPdf'
];
$data
[
'receivesList'
][
$index
][
'file_name'
]
=
$collectsInfo
[
'file_name'
];
$data
[
'receivesList'
][
$index
][
'normCollectsExtend'
]
=
$normCollectsExtend
;
}
else
{
$normExtendBus
=
new
CommonBus
(
'NormExtendBus'
);
$res
=
$normExtendBus
->
getConditionalQueryAll
([
'norm_id'
=>
$id
,
'user_filled'
=>
1
]);
$data
[
'receivesList'
][
$index
][
'refer_type'
]
=
''
;
$data
[
'receivesList'
][
$index
][
'remark'
]
=
''
;
$data
[
'receivesList'
][
$index
][
'imgPath'
]
=
''
;
$data
[
'receivesList'
][
$index
][
'fileListPdf'
]
=
$collectsInfo
[
'fileListPdf'
];
$data
[
'receivesList'
][
$index
][
'file_name'
]
=
$collectsInfo
[
'file_name'
];
$data
[
'receivesList'
][
$index
][
'normCollectsExtend'
]
=
$res
;
}
}
}
if
(
$data
){
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.success"
),
$data
);
}
else
{
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.null_data"
),[]);
}
}
/**
* 返回指标详情
* @return \josn
*/
public
function
detail1
()
{
$id
=
input
(
"param.id"
);
if
(
empty
(
$id
)){
return
returnResult
(
config
(
"config.code.error"
),
'填写信息错误,请检查!'
);
}
...
...
app/api/route/api.php
View file @
a86ffc53
...
...
@@ -61,6 +61,7 @@ Route::rule("taskPackage/delete","TaskPackage/delete"); // 删除任务列表
Route
::
rule
(
"norm/add"
,
"Norm/add"
);
// 新增指标
Route
::
rule
(
"norm/list"
,
"Norm/list"
);
// 指标列表
Route
::
rule
(
"norm/detail"
,
"Norm/detail"
);
// 指标详情
Route
::
rule
(
"norm/whole"
,
"Norm/whole"
);
// 指标完整详情信息
Route
::
rule
(
"norm/edit"
,
"Norm/edit"
);
// 指标详情
Route
::
rule
(
"norm/finalData"
,
"Norm/finalData"
);
// 返回最后的ID
Route
::
rule
(
"norm/delete"
,
"Norm/delete"
);
// 删除详情
...
...
app/common/model/mysql/NormReceives.php
View file @
a86ffc53
...
...
@@ -145,6 +145,31 @@ class NormReceives extends Model
}
/**
* 根据用户条件返回多条信息分页
* @param $where //查询条件
* @return UserInfo|array|false|Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*
*/
public
function
getConditionalQueryAllPaging
(
$where
,
$page
,
$limit
)
{
try
{
return
$this
->
with
([
'userInfo'
=>
function
(
$query
){
$query
->
field
(
"id,name"
);
},
])
->
where
(
$where
)
->
paginate
([
'list_rows'
=>
$limit
,
'page'
=>
$page
]);
}
catch
(
\Exception
$e
){
exception
(
$e
,
'mysql.NormReceives.getFindModel'
);
}
}
/**
* 根据条件获取多个值
* @param $where
* @return Menu[]|array|\think\Collection|void
...
...
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