Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
aic_duty_strategy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yinxiaoling
aic_duty_strategy
Commits
6570e01f
Commit
6570e01f
authored
May 15, 2020
by
yinxiaoling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
下载失败数据接口
parent
e1b44d3c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
10 deletions
+60
-10
StrategySetController.php
app/Http/Controllers/strategy/StrategySetController.php
+57
-9
StrategyService.php
app/Service/StrategyService.php
+1
-1
api.php
routes/api.php
+2
-0
No files found.
app/Http/Controllers/strategy/StrategySetController.php
View file @
6570e01f
...
...
@@ -79,22 +79,70 @@ class StrategySetController extends Controller
//项目列表
public
function
getProjectsList
(){
$projectInfo
=
[[
'sn'
=>
'projects|a3a4259352c8e964ad6ea6c5ee8a7208'
,
'name'
=>
'liuy-转人工测试'
]];
$projectInfo
=
[[
'sn'
=>
'projects|a3a4259352c8e964ad6ea6c5ee8a7208'
,
'name'
=>
'liuy-转人工测试'
]
,[
'sn'
=>
'projects|a3a4259352c8e964ad6ea6c5ee8a7208'
,
'name'
=>
'liuy-转人工测试'
]
];
return
$this
->
successWithInfo
([
'data'
=>
$projectInfo
]);
}
//下载模板及下载导入失败excel数据
public
function
downloadModel
(
Request
$request
,
StrategyService
$StrategyService
){
$excelFile
=
$request
->
filename
;
if
(
!
empty
(
$excelFile
)){
//下载失败导入数据
}
else
{
//下载模板
$excelName
=
"策略任务数据导入模板"
;
$datas
[
0
][
0
]
=
"姓名"
;
$datas
[
0
][
1
]
=
"*手机号码"
;
$datas
[
0
][
2
]
=
"值班日期"
;
$StrategyService
->
storeExcelStyle
(
$excelName
,
$datas
,
''
,
''
,
1
);
}
public
function
downloadFailExcel
(
Request
$request
){
$excelFile
=
$request
->
filename
;
if
(
empty
(
$excelFile
)){
return
$this
->
errorWithInfo
(
'表单验证失败'
,
401
);
}
$url
=
storage_path
()
.
"
\\
exports
\\
"
.
$excelFile
.
'.xlsx'
;
try
{
if
(
!
file_exists
(
$url
)){
return
$this
->
errorWithInfo
(
'文件不存在,下载失败111'
,
401
);
}
$cont
=
fopen
(
$url
,
'r'
);
$fcontent
=
fread
(
$cont
,
filesize
(
$url
));
fclose
(
$cont
);
//发送mp3文件MIME 头
header
(
'Content-Type:application/vnd.ms-excel'
);
// 发送下载附件头.
header
(
"Content-disposition: attachment; filename=
\"
"
.
$url
.
"
\"
"
);
header
(
'Content-transfer-encoding: binary'
);
return
$fcontent
;
}
catch
(
\Exception
$e
){
return
$this
->
errorWithInfo
(
'下载异常'
,
401
);
}
}
//导入excel数据
public
function
importExcelData
(
Request
$request
,
StrategyService
$StrategyService
){
$validator
=
Validator
::
make
(
$request
->
all
(),
[
'strategy_sn'
=>
'required'
,
'upload'
=>
'required'
]);
if
(
$validator
->
fails
())
{
return
$this
->
errorWithInfo
(
'表单验证失败'
,
401
);
}
$strategySn
=
$request
->
strategy_sn
;
if
(
isset
(
$request
->
upload
)
&&
!
empty
(
$request
->
upload
)){
//excel文件上传
$excelData
=
$StrategyService
->
validUploadExcel
(
$request
,
'upload'
,
8388608
);
//限制最大上传文件8M
if
(
isset
(
$excelData
[
'code'
])){
return
$this
->
errorWithInfo
(
$excelData
[
'msg'
],
401
);
}
//验证excel数据格式及不合格数据原因
$excelDataValid
=
$StrategyService
->
validExcelData
(
$excelData
,
$params
[
'day_type'
]);
extract
(
$excelDataValid
);
unset
(
$params
[
'upload'
]);
}
else
{
return
$this
->
errorWithInfo
(
'请选择导入文件'
,
401
);
}
}
}
app/Service/StrategyService.php
View file @
6570e01f
...
...
@@ -106,7 +106,7 @@ class StrategyService
$failFile
=
$this
->
storeExcelStyle
(
$failExcelName
,
$failData
,
''
,
'import'
);
//$failDataFile = $failExcelName.'.xlsx';
if
(
$failFile
){
$failDataFile
=
$failExcelName
.
'.xlsx'
;
$failDataFile
=
$failExcelName
;
}
else
{
//失败数据写入失败
Log
::
channel
(
'api'
)
->
error
(
'错误文件excel写入失败'
);
}
...
...
routes/api.php
View file @
6570e01f
...
...
@@ -26,6 +26,8 @@ Route::group(['middleware' => 'check.apikey','namespace'=>'strategy'], function
Route
::
get
(
'strategy/downloadModel'
,
'StrategySetController@downloadModel'
)
->
name
(
'strategy.downloadModel'
);
//导出模板
Route
::
get
(
'strategy/downloadFailExcel'
,
'StrategySetController@downloadFailExcel'
)
->
name
(
'strategy.downloadFailExcel'
);
//下载失败导入excel数据
Route
::
apiResource
(
'strategySet'
,
StrategySetController
::
class
);
});
...
...
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