Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
b53f8a89
Commit
b53f8a89
authored
Aug 20, 2019
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
7b9064f1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
107 additions
and
23 deletions
+107
-23
StoreFeeService.php
application/api_broker/service/StoreFeeService.php
+33
-0
UploadFileService.php
application/api_broker/service/UploadFileService.php
+25
-21
StoreFee.php
application/index/controller/StoreFee.php
+17
-0
ImportExcelUntil.php
application/index/untils/ImportExcelUntil.php
+31
-2
route.php
application/route.php
+1
-0
No files found.
application/api_broker/service/StoreFeeService.php
View file @
b53f8a89
...
...
@@ -703,4 +703,36 @@ class StoreFeeService
$fCostModel
=
new
FStoreCost
();
return
$fCostModel
->
findByOne
(
"id"
,
[
"setting_date"
=>
$setting_date
]);
}
public
function
importStoreFee
(
$file_path
)
{
$reader
=
new
\PhpOffice\PhpSpreadsheet\Reader\Xlsx
();
$reader
->
setReadDataOnly
(
true
);
$spreadsheet
=
""
;
try
{
$spreadsheet
=
$reader
->
load
(
$file_path
);
}
catch
(
\Exception
$exception
)
{
return
"找不到文件路径"
;
}
$sheet
=
$spreadsheet
->
getActiveSheet
();
$highestRow
=
$sheet
->
getHighestRow
();
// 最大行数
$highestColumn
=
$sheet
->
getHighestColumn
();
// 最大列数
$highestColumn
=
"AB"
;
// 把下标变成数字,如A-Z分别对应1-26,AA对应27,AB对应28,以此类推
$highestColumnIndex
=
\PhpOffice\PhpSpreadsheet\Cell\Coordinate
::
columnIndexFromString
(
$highestColumn
);
/* if($highestRow <= 2){ // 因为students.xlsx表格数据是从第三行开始的
exit('Excel没有任何数据');
}*/
$data
=
array
();
for
(
$row
=
0
;
$row
<=
$highestRow
;
$row
++
)
{
$tempData
[
'name'
]
=
$sheet
->
getCellByColumnAndRow
(
1
,
$row
)
->
getValue
();
$tempData
[
'chinese'
]
=
$sheet
->
getCellByColumnAndRow
(
2
,
$row
)
->
getValue
();
$tempData
[
'math'
]
=
$sheet
->
getCellByColumnAndRow
(
3
,
$row
)
->
getValue
();
$tempData
[
'English'
]
=
$sheet
->
getCellByColumnAndRow
(
4
,
$row
)
->
getValue
();
$data
[]
=
$tempData
;
}
dump
(
$data
);
}
}
\ No newline at end of file
application/api_broker/service/UploadFileService.php
View file @
b53f8a89
<?php
namespace
app\api_broker\service
;
/**
* Created by PhpStorm.
...
...
@@ -20,26 +21,25 @@ class UploadFileService
* @param array $ext
* @return array
*/
public
function
upload
(
$_upload_file
,
$type
,
$size
=
15000000
,
$ext
=
[
'jpg'
,
'png'
,
'jpeg'
,
'xlsx'
,
'doc'
,
'docx'
,
'pdf'
,
'ppt'
,
'pptx'
,
'xls'
,
'gif'
,
'mp4'
,
'video/mp4'
])
public
function
upload
(
$_upload_file
,
$type
,
$size
=
15000000
,
$ext
=
[
'jpg'
,
'png'
,
'jpeg'
,
'xlsx'
,
'doc'
,
'docx'
,
'pdf'
,
'ppt'
,
'pptx'
,
'xls'
,
'gif'
,
'mp4'
,
'video/mp4'
])
{
/**
*
upload($_FILE['file'])
array(2) {
[0] => array(3) {
["code"] => int(200)
["img_path"] => string(19) "201807021804140.jpg"
["img_ext"] => string(3) "jpg"
}
[1] => array(3) {
["code"] => int(200)
["img_path"] => string(20) "2018070218041401.jpg"
["img_ext"] => string(3) "jpg"
}
}
* upload($_FILE['file'])
*
*
* array(2) {
* [0] => array(3) {
* ["code"] => int(200)
* ["img_path"] => string(19) "201807021804140.jpg"
* ["img_ext"] => string(3) "jpg"
* }
* [1] => array(3) {
* ["code"] => int(200)
* ["img_path"] => string(20) "2018070218041401.jpg"
* ["img_ext"] => string(3) "jpg"
* }
* }
*/
$check
=
$this
->
checkUploadFile
(
$_upload_file
,
$size
,
$ext
);
...
...
@@ -108,6 +108,10 @@ class UploadFileService
$path
.=
'static/user_id_card/'
;
$internet_path
=
''
;
break
;
case
'excel_import'
:
$path
.=
'static/excel/'
;
$internet_path
=
''
;
break
;
default
:
$data
[
'code'
]
=
101
;
$data
[
'msg'
]
=
"上传图片类型错误"
;
...
...
@@ -121,14 +125,14 @@ class UploadFileService
if
(
is_array
(
$_upload_file
[
'tmp_name'
]))
{
foreach
(
$_upload_file
[
'tmp_name'
]
as
$k
=>
$v
)
{
$name_str
.=
mt_rand
(
10
,
10000
);
$name_str
.=
mt_rand
(
10
,
10000
);
$_file
=
new
File
(
$v
);
$file_info
=
pathinfo
(
$_upload_file
[
'name'
][
$k
]);
$info
=
$_file
->
validate
(
$valid_date
)
->
move
(
$path
,
$name_str
.
'.'
.
$file_info
[
'extension'
]);
if
(
$info
)
{
$data
[
'code'
]
=
200
;
$data
[
"msg"
][
$k
][
'img_path'
]
=
$date
.
'/'
.
$info
->
getSaveName
();
//生成的图片路径
$data
[
"msg"
][
$k
][
'img_path'
]
=
$date
.
'/'
.
$info
->
getSaveName
();
//生成的图片路径
$data
[
"msg"
][
$k
][
'internet_img_name'
]
=
$internet_path
.
$data
[
"msg"
][
$k
][
'img_path'
];
$data
[
"msg"
][
$k
][
'img_ext'
]
=
$info
->
getExtension
();
$data
[
"msg"
][
$k
][
'imgformer_name'
]
=
$file_info
[
'basename'
];
...
...
@@ -139,13 +143,13 @@ class UploadFileService
}
}
else
{
$name_str
.=
mt_rand
(
10
,
1000
);
$name_str
.=
mt_rand
(
10
,
1000
);
$_file
=
new
File
(
$_upload_file
[
'tmp_name'
]);
$file_info
=
pathinfo
(
$_upload_file
[
'name'
]);
$info
=
$_file
->
validate
(
$valid_date
)
->
move
(
$path
,
$name_str
.
'.'
.
$file_info
[
'extension'
]);
if
(
$info
)
{
$data
[
'code'
]
=
200
;
$data
[
"msg"
][
'img_path'
]
=
$date
.
'/'
.
$info
->
getSaveName
();
//生成的图片路径
$data
[
"msg"
][
'img_path'
]
=
$date
.
'/'
.
$info
->
getSaveName
();
//生成的图片路径
$data
[
"msg"
][
'internet_img_name'
]
=
$internet_path
.
$data
[
"msg"
][
'img_path'
];
$data
[
"msg"
][
'img_ext'
]
=
$info
->
getExtension
();
$data
[
"msg"
][
'imgformer_name'
]
=
$file_info
[
'basename'
];
...
...
application/index/controller/StoreFee.php
View file @
b53f8a89
...
...
@@ -12,6 +12,7 @@ namespace app\index\controller;
use
app\api_broker\service\PushMessageService
;
use
app\api_broker\service\RedisCacheService
;
use
app\api_broker\service\StoreFeeService
;
use
app\api_broker\service\UploadFileService
;
use
app\api_broker\validate\StoreFeeValidate
;
use
app\index\extend\Basic
;
use
app\model\AAgents
;
...
...
@@ -120,6 +121,22 @@ class StoreFee extends Basic
}
}
public
function
importStoreFee
()
{
header
(
'Access-Control-Allow-Origin:*'
);
set_time_limit
(
0
);
$file
=
$_FILES
[
'file'
];
$type
=
request
()
->
param
(
'type'
);
//excel_import
$uploadFileService
=
new
UploadFileService
();
$uploadResult
=
$uploadFileService
->
upload
(
$file
,
$type
,
15000000
,
[
'xls'
,
'xlsx'
]);
if
(
$uploadResult
[
"code"
]
==
200
)
{
$result
=
$this
->
service_
->
importStoreFee
(
$uploadResult
[
"msg"
]);
return
$this
->
response
(
"200"
,
"excel上传成功"
,
$uploadResult
[
"msg"
]);
}
else
{
return
$this
->
response
(
"101"
,
$uploadResult
[
"msg"
]);
}
}
/**
* 新增办公室
* @return \think\Response
...
...
application/index/untils/ImportExcelUntil.php
View file @
b53f8a89
...
...
@@ -14,9 +14,9 @@ class ImportExcelUntil
$reader
=
new
\PhpOffice\PhpSpreadsheet\Reader\Xlsx
();
$reader
->
setReadDataOnly
(
true
);
$spreadsheet
=
""
;
try
{
try
{
$spreadsheet
=
$reader
->
load
(
$file_path
);
}
catch
(
\Exception
$exception
)
{
}
catch
(
\Exception
$exception
)
{
return
"找不到文件路径"
;
}
...
...
@@ -39,4 +39,32 @@ class ImportExcelUntil
}
dump
(
$data
);
}
public
function
uploadExcel
(
$_FILES
)
{
if
(
!
empty
(
$_FILES
[
'excel'
][
'name'
]))
{
$fileName
=
$_FILES
[
'excel'
][
'name'
];
//得到文件全名
$dotArray
=
explode
(
'.'
,
$fileName
);
//把文件名安.区分,拆分成数组
$type
=
end
(
$dotArray
);
if
(
$type
!=
"xls"
&&
$type
!=
"xlsx"
)
{
return
"不是Excel文件,请重新上传!"
;
}
//取数组最后一个元素,得到文件类型
$path
=
ROOT_PATH
.
'public/static/excel/'
;
$uploadDir
=
$path
.
date
(
"Y-m-d"
)
.
'/'
;
//设置文件保存目录 注意包含
if
(
!
file_exists
(
$uploadDir
))
{
mkdir
(
$uploadDir
,
0777
,
true
);
}
$path
=
$uploadDir
.
md5
(
uniqid
(
rand
()))
.
'.'
.
$type
;
//产生随机文件名
//下面必须是tmp_name 因为是从临时文件夹中移动
move_uploaded_file
(
$_FILES
[
'excel'
][
'tmp_name'
],
$path
);
//从服务器临时文件拷贝到相应的文件夹下
if
(
!
file_exists
(
$path
))
{
return
"上传文件丢失!"
.
$_FILES
[
'excel'
][
'error'
];
}
else
{
return
[
"path"
=>
$path
];
}
}
}
}
\ No newline at end of file
application/route.php
View file @
b53f8a89
...
...
@@ -559,6 +559,7 @@ Route::group('index', [
'getStoreOffice'
=>
[
'index/Store/getStoreOffice'
,
[
'method'
=>
'GET'
]],
//获取费用承担办公室
'creationStoreFee'
=>
[
'index/StoreFee/creationStoreFee'
,
[
'method'
=>
'POST|GET'
]],
'getStoreFeeDetail'
=>
[
'index/StoreFee/getStoreFeeDetail'
,
[
'method'
=>
'POST|GET'
]],
'importStoreFee'
=>
[
'index/StoreFee/importStoreFee'
,
[
'method'
=>
'POST'
]],
'getStoreCostParameterList'
=>
[
'index/CostParameter/getStoreCostParameterList'
,
[
'method'
=>
'POST|GET'
]],
'editCostParameter'
=>
[
'index/CostParameter/editCostParameter'
,
[
'method'
=>
'POST|GET'
]],
...
...
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