优化批量导入代码

dev
曾超新 5 years ago
parent 7e19e00fff
commit 1445ffa914
  1. 19
      frontend/controllers/FinanceController.php

@ -6335,10 +6335,12 @@ class FinanceController extends \frontend\controllers\UserBaseController
$PHPReader = new \PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($filename)) {
$errorMessage = "Can not read file.";
echo $errorMessage;
return;
$result['msg'] = $errorMessage;
return $result;
}
}
$tran = CarT::getDb()->beginTransaction();
try {
$PHPExcel = $PHPReader->load($filename);
$currentSheet = $PHPExcel->getSheet(0);
@ -6435,8 +6437,7 @@ class FinanceController extends \frontend\controllers\UserBaseController
$car_info->phone = $car_man_phone;
}
if(!$car_info->save(false)) {
var_dump($car_info->errors);
exit;
throw new \Exception(print_r($car_info->getErrors(), true));
}
$insert_total++;
@ -6493,14 +6494,20 @@ class FinanceController extends \frontend\controllers\UserBaseController
$car_info->phone = $car_man_phone;
}
if(!$car_info->save(false)) {
var_dump($car_info->errors);
exit;
throw new \Exception(print_r($car_info->getErrors(), true));
}
$insert_total++;
}
}
$tran->commit();
} catch (\Exception $e) {
$tran->rollBack();
$result['msg'] = $e->getMessage();
return $result;
}
$result['success'] = true;
$result['msg'] = '操作成功';

Loading…
Cancel
Save