Commit 269618f8 authored by zhuwei's avatar zhuwei

1

parent ba20c0db
...@@ -582,14 +582,22 @@ class CostParameter extends Basic ...@@ -582,14 +582,22 @@ class CostParameter extends Basic
{ {
header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Origin:*');
set_time_limit(0); set_time_limit(0);
$params = $this->params;
if(!checkTimeData($params['setting_date'])){
return $this->response("101", '非法时间');
}
$file = $_FILES['file']; $file = $_FILES['file'];
$type = request()->param('type'); $type = request()->param('type');
$uploadFileService = new UploadFileService(); $uploadFileService = new UploadFileService();
$uploadResult = $uploadFileService->upload($file, $type, 15000000, ['xls', 'xlsx']); $uploadResult = $uploadFileService->upload($file, $type, 15000000, ['xls', 'xlsx']);
if ($uploadResult["code"] == 200) { if ($uploadResult["code"] == 200) {
$path = $_FILES['excel']['tmp_name']; $path = $_FILES['excel']['tmp_name'];
$result = $this->saveExcelData($path); $result = $this->saveExcelData($path,$params['setting_date']);
return $this->response("200", "excel上传成功", $uploadResult["msg"]); if ($result["code"] == 200) {
return $this->response("200", "excel导入成功");
} else {
return $this->response("101", $result["msg"]);
}
} else { } else {
return $this->response("101", $uploadResult["msg"]); return $this->response("101", $uploadResult["msg"]);
} }
...@@ -599,13 +607,13 @@ class CostParameter extends Basic ...@@ -599,13 +607,13 @@ class CostParameter extends Basic
* 保存数据 * 保存数据
* @param $path * @param $path
* @param $setting_date * @param $setting_date
* @return bool * @return array
*/ */
public function saveExcelData($path,$setting_date) public function saveExcelData($path,$setting_date)
{ {
$list = $this->readExcel($path); $list = $this->readExcel($path);
if(!$list) if(!$list)
return false; return ["code"=>101,"msg"=> "空excel"];
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
$f_params['c.store_id'] = $v['id']; $f_params['c.store_id'] = $v['id'];
$f_params['c.setting_date'] = $setting_date; $f_params['c.setting_date'] = $setting_date;
...@@ -635,16 +643,15 @@ class CostParameter extends Basic ...@@ -635,16 +643,15 @@ class CostParameter extends Basic
$this->saveStoreData($save_params); $this->saveStoreData($save_params);
} }
} }
return true; return ["code"=>200,"msg"=> "成功"];
}
}
/** /**
* 门店考勤列表-批量上传 * 门店考勤列表-批量上传
* @param $file_path * @param $file_path
* @return string * @return array
*/ */
public function readExcel($file_path) public function readExcel($file_path)
{ {
...@@ -654,18 +661,14 @@ class CostParameter extends Basic ...@@ -654,18 +661,14 @@ class CostParameter extends Basic
try { try {
$spreadsheet = $reader->load($file_path); $spreadsheet = $reader->load($file_path);
} catch (\Exception $exception) { } catch (\Exception $exception) {
return "找不到文件路径"; return ["code"=>101,"msg"=> "找不到文件路径"];
} }
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$highestRow = $sheet->getHighestRow(); // 最大行数 $highestRow = $sheet->getHighestRow(); // 最大行数
$highestColumn = $sheet->getHighestColumn(); // 最大列数 if ($highestRow <= 2) {
$highestColumn = "AB"; return ["code"=>101,"msg"=> "Excel没有任何数据"];
// 把下标变成数字,如A-Z分别对应1-26,AA对应27,AB对应28,以此类推 }
$highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highestColumn);
/* if($highestRow <= 2){ // 因为students.xlsx表格数据是从第三行开始的
exit('Excel没有任何数据');
}*/
$data = array(); $data = array();
for ($row = 0; $row <= $highestRow; $row++) { for ($row = 0; $row <= $highestRow; $row++) {
for ($row = 1; $row <= $highestRow; $row++) { for ($row = 1; $row <= $highestRow; $row++) {
......
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