|
@ -5,9 +5,11 @@ namespace backend\modules\file\logic\file; |
|
|
|
|
|
|
|
|
use backend\modules\file\models\ars\File; |
|
|
use backend\modules\file\models\ars\File; |
|
|
use backend\modules\file\models\ars\TemFile; |
|
|
use backend\modules\file\models\ars\TemFile; |
|
|
|
|
|
use Exception; |
|
|
use yii\web\HttpException; |
|
|
use yii\web\HttpException; |
|
|
use yii; |
|
|
use yii; |
|
|
use yii\web\ServerErrorHttpException; |
|
|
use yii\web\ServerErrorHttpException; |
|
|
|
|
|
use backend\modules\goods\logic\goods\GoodsManager; |
|
|
|
|
|
|
|
|
class FileManager |
|
|
class FileManager |
|
|
{ |
|
|
{ |
|
@ -124,4 +126,32 @@ class FileManager |
|
|
} |
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @param yii\base\Model|$dataModel //数据模型
|
|
|
|
|
|
* @param $fileIdStrName //表单中临时保存的文件id字符串组合(以,隔开)
|
|
|
|
|
|
* @param string $fileNameInModel //需要保存到数据库中的数据表字段名称
|
|
|
|
|
|
* @param $fileOldIdStr //数据库中已经保存的文件id字符串组合(以,隔开)
|
|
|
|
|
|
* @param File|$fileType //File模型中定义的own_type常量
|
|
|
|
|
|
* @return bool |
|
|
|
|
|
* @throws Exception |
|
|
|
|
|
* 数据模型保存文件操作 |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function saveFileInModel($dataModel, $fileIdStrName, $fileOldIdStr, $fileType, $fileNameInModel = '') |
|
|
|
|
|
{ |
|
|
|
|
|
if (is_array($dataModel)) { |
|
|
|
|
|
Yii::$app->session->setFlash('error', '数据模型不得为数组'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
$fileNewIdStr = $dataModel->$fileIdStrName; |
|
|
|
|
|
$dataModel->save(); |
|
|
|
|
|
$saveFileRes = GoodsManager::saveFile(explode(',', $fileNewIdStr), $dataModel, explode(',', $fileOldIdStr), $fileType); |
|
|
|
|
|
if ($fileNameInModel) { |
|
|
|
|
|
if ($saveFileRes['status']) { |
|
|
|
|
|
$dataModel->$fileNameInModel = $saveFileRes['first_file_id']; |
|
|
|
|
|
$dataModel->save(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
} |
|
|
} |