Commit f295994c authored by zhuwei's avatar zhuwei

1

parent 9dd5bcac
...@@ -748,4 +748,41 @@ class StoreFeeService ...@@ -748,4 +748,41 @@ class StoreFeeService
} }
dump($data); dump($data);
} }
/**
* 门店考勤列表-批量上传
* @param $file_path
* @return string
*/
public function readStoreFee($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
...@@ -37,6 +37,34 @@ class ReadExcel extends Basic ...@@ -37,6 +37,34 @@ class ReadExcel extends Basic
$path = $_FILES['excel']['tmp_name']; $path = $_FILES['excel']['tmp_name'];
// $file = $_FILES['upload']['tmp_name'][0]; // $file = $_FILES['upload']['tmp_name'][0];
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$reader->setReadDataOnly(true);
$spreadsheet = "";
try {
$spreadsheet = $reader->load($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 = 1; $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);
dump($path); dump($path);
......
...@@ -575,4 +575,28 @@ class StoreFee extends Basic ...@@ -575,4 +575,28 @@ class StoreFee extends Basic
} }
return $this->response($code, $msg); return $this->response($code, $msg);
} }
/**
* 门店考勤列表-批量上传
* @return \think\Response
*/
public function readStoreFee()
{
header('Access-Control-Allow-Origin:*');
set_time_limit(0);
$file = $_FILES['file'];
$type = request()->param('type');
$uploadFileService = new UploadFileService();
$uploadResult = $uploadFileService->upload($file, $type, 15000000, ['xls', 'xlsx']);
if ($uploadResult["code"] == 200) {
$path = $_FILES['excel']['tmp_name'];
$result = $this->service_->readStoreFee($path);
return $this->response("200", "excel上传成功", $uploadResult["msg"]);
} else {
return $this->response("101", $uploadResult["msg"]);
}
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment