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);
$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()
// ])
// ];
}
}

View File

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