Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
liexin_supplier
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cb471566
authored
Jul 27, 2022
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修改上传格式
parent
50d2dfea
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
10 additions
and
18 deletions
app/Http/Controllers/Api/SupplierExaminationApiController.php
app/Http/Services/SupplierExaminationService.php
public/data/import_supplier_examination_template.xlsx
public/data/supplier_examination 副本.xlsx
resources/views/script/SupplierExaminationListScript.blade.php
app/Http/Controllers/Api/SupplierExaminationApiController.php
View file @
cb471566
...
@@ -129,7 +129,7 @@ class SupplierExaminationApiController extends Controller
...
@@ -129,7 +129,7 @@ class SupplierExaminationApiController extends Controller
if
(
$file
->
isValid
())
{
if
(
$file
->
isValid
())
{
$ext
=
$file
->
getClientOriginalExtension
();
$ext
=
$file
->
getClientOriginalExtension
();
$realPath
=
$file
->
getRealPath
();
$realPath
=
$file
->
getRealPath
();
if
(
$ext
!=
'
csv
'
)
{
if
(
$ext
!=
'
xlsx
'
)
{
$this
->
response
(
-
1
,
'上传格式错误'
);
$this
->
response
(
-
1
,
'上传格式错误'
);
}
}
// 上传文件
// 上传文件
...
...
app/Http/Services/SupplierExaminationService.php
View file @
cb471566
...
@@ -53,23 +53,12 @@ class SupplierExaminationService
...
@@ -53,23 +53,12 @@ class SupplierExaminationService
ini_set
(
'memory_limit'
,
-
1
);
ini_set
(
'memory_limit'
,
-
1
);
try
{
try
{
$content
=
file_get_contents
(
$filePath
);
$fileType
=
mb_detect_encoding
(
$content
,
array
(
'UTF-8'
,
'GBK'
,
'LATIN1'
,
'BIG5'
));
Excel
::
load
(
$filePath
,
function
(
$reader
)
{
Excel
::
load
(
$filePath
,
function
(
$reader
)
{
$
result
=
$reader
->
getSheet
(
0
)
->
toArray
();
$
data
=
$reader
->
getSheet
(
0
)
->
toArray
();
$header
=
$
result
[
0
];
$header
=
$
data
[
0
];
if
(
!
$this
->
checkImportCsvHeader
(
$header
))
{
if
(
!
$this
->
checkImportCsvHeader
(
$header
))
{
throw
new
\Exception
(
'文件不是标准上传模板,请核对后再上传'
);
throw
new
\Exception
(
'文件不是标准上传模板,请核对后再上传'
);
}
}
},
$fileType
);
$valueBinder
=
new
CsvValueBinder
();
$data
=
Excel
::
setValueBinder
(
$valueBinder
)
->
load
(
$filePath
,
$fileType
)
->
get
();
if
(
empty
(
$data
))
{
throw
new
\Exception
(
'上传数据不能为空'
);
}
$data
=
$data
->
toArray
();
$dataMd5
=
md5
(
json_encode
(
$data
));
$dataMd5
=
md5
(
json_encode
(
$data
));
if
(
SupplierExaminationModel
::
where
(
'data_md5'
,
$dataMd5
)
->
exists
())
{
if
(
SupplierExaminationModel
::
where
(
'data_md5'
,
$dataMd5
)
->
exists
())
{
throw
new
\Exception
(
'该文件已经上传过,请选择其它文件'
);
throw
new
\Exception
(
'该文件已经上传过,请选择其它文件'
);
...
@@ -81,7 +70,10 @@ class SupplierExaminationService
...
@@ -81,7 +70,10 @@ class SupplierExaminationService
//拼装数据插入校验,校验完成插入数据库
//拼装数据插入校验,校验完成插入数据库
$examineData
=
[];
$examineData
=
[];
foreach
(
$data
as
$index
=>
$item
)
{
foreach
(
$data
as
$index
=>
$item
)
{
$lineNo
=
$index
+
2
;
if
(
$index
==
0
)
{
continue
;
}
$lineNo
=
$index
+
1
;
$item
=
array_map
(
function
(
$value
)
{
$item
=
array_map
(
function
(
$value
)
{
return
trim
(
$value
);
return
trim
(
$value
);
},
$item
);
},
$item
);
...
@@ -180,17 +172,17 @@ class SupplierExaminationService
...
@@ -180,17 +172,17 @@ class SupplierExaminationService
}
}
$examineData
=
collect
(
$examineData
);
$examineData
=
collect
(
$examineData
);
foreach
(
$examineData
->
chunk
(
50
)
as
$chunk
)
{
foreach
(
$examineData
->
chunk
(
50
)
as
$chunk
)
{
SupplierExaminationModel
::
insert
(
$chunk
->
toArray
());
SupplierExaminationModel
::
insert
(
$chunk
->
toArray
());
}
}
return
true
;
return
true
;
});
return
true
;
}
catch
(
\Exception
$exception
)
{
}
catch
(
\Exception
$exception
)
{
return
$exception
->
getMessage
();
return
$exception
->
getMessage
();
}
finally
{
}
finally
{
unlink
(
$filePath
);
unlink
(
$filePath
);
}
}
}
}
private
function
checkImportCsvHeader
(
$header
)
private
function
checkImportCsvHeader
(
$header
)
...
...
public/data/import_supplier_examination_template.xlsx
0 → 100644
View file @
cb471566
No preview for this file type
public/data/supplier_examination 副本.xlsx
0 → 100644
View file @
cb471566
No preview for this file type
resources/views/script/SupplierExaminationListScript.blade.php
View file @
cb471566
...
@@ -207,7 +207,7 @@
...
@@ -207,7 +207,7 @@
elem
:
'#import_supplier_examination'
,
//绑定元素
elem
:
'#import_supplier_examination'
,
//绑定元素
url
:
'/api/supplier_examination/ImportSupplierExamination'
,
//上传接口
url
:
'/api/supplier_examination/ImportSupplierExamination'
,
//上传接口
auto
:
true
,
auto
:
true
,
exts
:
'
csv
'
,
exts
:
'
xlsx
'
,
before
:
function
(
obj
)
{
//obj参数包含的信息,跟 choose回调完全一致,可参见上文。
before
:
function
(
obj
)
{
//obj参数包含的信息,跟 choose回调完全一致,可参见上文。
layer
.
msg
(
'上传中'
,
{
icon
:
16
});
//上传loading
layer
.
msg
(
'上传中'
,
{
icon
:
16
});
//上传loading
},
},
...
...
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