更新异常捕获

This commit is contained in:
2024-10-31 16:11:17 +08:00
parent 5e50e8f900
commit 1b276b1087
2 changed files with 36 additions and 25 deletions

View File

@@ -446,32 +446,40 @@ class DrugController extends BaseAdminController
*/
public function actionExportReal()
{
$request = \Yii::$app->request;
try {
$request = \Yii::$app->request;
if ($request->isPost) {
$post = \Yii::$app->request->post();
//设置最大执行时间
ini_set("max_execution_time", "360");
$file = UploadedFile::getInstanceByName('file');
if ($file->size > 5 * 1024 * 1024) {
return ['excel文件不能超过5M!'];
if ($request->isPost) {
$post = \Yii::$app->request->post();
//设置最大执行时间
ini_set("max_execution_time", "360");
$file = UploadedFile::getInstanceByName('file');
if ($file->size > 5 * 1024 * 1024) {
return ['excel文件不能超过5M!'];
}
//文件名
$filename = date('His') . md5($file->getBaseName()) . mt_rand(1000, 9999) . '.' . $file->getExtension();
//保存文件
$file->saveAs($filename);
// $fullFileName = $absolute_path . $filename;
$data = Excel::import($filename, [
'setFirstRecordAsKeys' => true,
'getOnlySheet' => 'Sheet1',
]);
$ImportForm = new ImportForm();
$ImportForm->attributes = $post;
return $ImportForm->ExportRealDrug($data);
} else {
throw new Exception('请求方式错误');
}
} catch (\Exception $e) {
return ['error' => $e->getMessage()];
} finally {
if (file_exists($filename)) {
unlink($filename);
}
//文件名
$filename = date('His') . md5($file->getBaseName()) . mt_rand(1000, 9999) . '.' . $file->getExtension();
//保存文件
$file->saveAs($filename);
// $fullFileName = $absolute_path . $filename;
$data = Excel::import($filename, [
'setFirstRecordAsKeys' => true,
'getOnlySheet' => 'Sheet1',
]);
$ImportForm = new ImportForm();
$ImportForm->attributes = $post;
return $ImportForm->ExportRealDrug($data);
} else {
throw new Exception('请求方式错误');
}
}
}

View File

@@ -638,7 +638,10 @@ class WareController extends BaseAdminController
return ['修改成功'];
}
// Excel导入批量修改商品价格
/**
* Excel导入批量修改商品价格
* @return array|array[]|string[]|void
*/
public function actionExcelUpdatePrice()
{
try {