fix bug import danh sách nhân viên với dữ liệu lớn

This commit is contained in:
dongpd 2020-10-20 09:18:48 +07:00
parent 5b24af3ad5
commit adffab016c
2 changed files with 38 additions and 12 deletions

View File

@ -216,14 +216,38 @@ class StaffController extends Controller {
$objReader = \PHPExcel_IOFactory::createReader($file_type); $objReader = \PHPExcel_IOFactory::createReader($file_type);
$objPHPExcel = $objReader->load($fileUploads); $objPHPExcel = $objReader->load($fileUploads);
$sheet_data = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); $sheet_data = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
Yii::$app->response->format = 'json'; foreach ($sheet_data as $key => $val) {
return [ if ($key > 1) {
"title" => Html::tag("i", "", ["class" => "fa fa-upload"]) . " Nhập", $parent = Department::findOne(["name" => $val["D"]]);
"form" => $this->renderPartial("import", [ $datas[] = [
"data" => $sheet_data, $val["A"],
"model" => new Staff() $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()
// ])
// ];
} }
} }

View File

@ -175,10 +175,11 @@ function btnUpload(mUrl, className, extension, fileSize) {
classes: 'btn btn-default file-paperclip-' + className, classes: 'btn btn-default file-paperclip-' + className,
fakeInputContent: '<span class=\'fa fa-upload\'></span> Nhập dữ liệu', fakeInputContent: '<span class=\'fa fa-upload\'></span> Nhập dữ liệu',
onUploaded: function (data) { onUploaded: function (data) {
data = JSON.parse(data); window.location.reload(true);
common.modalOpenFullScreen(data.form, data.title); // data = JSON.parse(data);
common.uploadBlock(false); // common.modalOpenFullScreen(data.form, data.title);
common.checkboxInit("staff-import"); // common.uploadBlock(false);
// common.checkboxInit("staff-import");
} }
}).addInstance('file' + className); }).addInstance('file' + className);
$(".file-paperclip-" + className).closest("div").attr("style", "display:inline-block;"); $(".file-paperclip-" + className).closest("div").attr("style", "display:inline-block;");
@ -205,6 +206,7 @@ function _import(e) {
window.location.reload(true); window.location.reload(true);
}, },
error: function (jqXHR, textStatus, errorThrown) { error: function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
common.modalBlock(false); common.modalBlock(false);
common.ajaxError(); common.ajaxError();
} }