Browse Source

fix:修复数据模型保存文件操作删除图片失败问题

antshop
linyaostalker 5 years ago
parent
commit
8d39cc14c8
  1. 12
      backend/modules/file/logic/file/FileManager.php

12
backend/modules/file/logic/file/FileManager.php

@ -140,15 +140,15 @@ class FileManager
public static function saveFileInModel($dataModel, $fileIdStrName, $fileOldIdStr, $fileType, $fileNameInModel = '') public static function saveFileInModel($dataModel, $fileIdStrName, $fileOldIdStr, $fileType, $fileNameInModel = '')
{ {
if (is_array($dataModel)) { if (is_array($dataModel)) {
Yii::$app->session->setFlash('error', '数据模型不得为数组');
return false;
throw new ServerErrorHttpException('数据模型不得为数组');
} }
$fileNewIdStr = $dataModel->$fileIdStrName;
$dataModel->save(); $dataModel->save();
$saveFileRes = GoodsManager::saveFile(explode(',', $fileNewIdStr), $dataModel, explode(',', $fileOldIdStr), $fileType);
if ($fileNameInModel && $saveFileRes['status'] && $saveFileRes['first_file_id']) {
$saveFileRes = GoodsManager::saveFile(explode(',', $dataModel->$fileIdStrName), $dataModel, explode(',', $fileOldIdStr), $fileType);
if ($fileNameInModel && $saveFileRes['status'] && $saveFileRes['first_file_id'] !== 0) {
$dataModel->$fileNameInModel = $saveFileRes['first_file_id']; $dataModel->$fileNameInModel = $saveFileRes['first_file_id'];
$dataModel->save();
if (!$dataModel->save()) {
throw new ServerErrorHttpException('dataModel保存失败');
}
} }
return true; return true;
} }

Loading…
Cancel
Save