fix bug import danh sách nhân viên với dữ liệu lớn
This commit is contained in:
@@ -216,14 +216,38 @@ class StaffController extends Controller {
|
||||
$objReader = \PHPExcel_IOFactory::createReader($file_type);
|
||||
$objPHPExcel = $objReader->load($fileUploads);
|
||||
$sheet_data = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
|
||||
Yii::$app->response->format = 'json';
|
||||
return [
|
||||
"title" => Html::tag("i", "", ["class" => "fa fa-upload"]) . " Nhập",
|
||||
"form" => $this->renderPartial("import", [
|
||||
"data" => $sheet_data,
|
||||
"model" => new Staff()
|
||||
])
|
||||
];
|
||||
foreach ($sheet_data as $key => $val) {
|
||||
if ($key > 1) {
|
||||
$parent = Department::findOne(["name" => $val["D"]]);
|
||||
$datas[] = [
|
||||
$val["A"],
|
||||
$val["B"],
|
||||
$val["C"],
|
||||
$parent ? $parent->code : 1,
|
||||
in_array($val["E"], ["M", "F"]) ? $val["E"] : "M",
|
||||
$val["F"] !== "" ? date_format(date_create_from_format('d/m/Y', $val["F"]), 'U') : 0,
|
||||
$val["G"],
|
||||
$val["H"],
|
||||
$val["I"] !== "" ? date_format(date_create_from_format('d/m/Y', $val["I"]), 'U') : 0,
|
||||
$val["J"],
|
||||
time(),
|
||||
time(),
|
||||
time()
|
||||
];
|
||||
}
|
||||
}
|
||||
$model = new Staff();
|
||||
$model->multiCreate($datas);
|
||||
common::insertSystemLogs(["action" => "import", "description" => "Nhập dữ liệu: " . count($datas) . " nhân viên mới", "type" => Yii::$app->controller->id]);
|
||||
return true;
|
||||
// Yii::$app->response->format = 'json';
|
||||
// return [
|
||||
// "title" => Html::tag("i", "", ["class" => "fa fa-upload"]) . " Nhập",
|
||||
// "form" => $this->renderPartial("import", [
|
||||
// "data" => $sheet_data,
|
||||
// "model" => new Staff()
|
||||
// ])
|
||||
// ];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user