|
|
@ -3,6 +3,7 @@ |
|
|
|
|
|
|
|
namespace backend\logic\file; |
|
|
|
|
|
|
|
use common\models\ars\File; |
|
|
|
use common\models\ars\TemFile; |
|
|
|
|
|
|
|
class FileManager |
|
|
@ -48,4 +49,64 @@ class FileManager |
|
|
|
} |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param $imgIdStr |
|
|
|
* @param $ownId |
|
|
|
* @param $ownType |
|
|
|
* @return array |
|
|
|
* 根据临时文件id(字符串)将临时文件保存在文件中 |
|
|
|
*/ |
|
|
|
public function saveTemFileToFile($temFIleIdStr, $ownId, $ownType) |
|
|
|
{ |
|
|
|
if(!$temFIleIdStr || !$ownId) { |
|
|
|
return ['status' => false, 'info' => '参数错误']; |
|
|
|
} |
|
|
|
|
|
|
|
$img_id_arr = explode(',', $temFIleIdStr); |
|
|
|
$i = 1; |
|
|
|
$first_file_id = 0; |
|
|
|
foreach ($img_id_arr as $key => $value) { |
|
|
|
$tem_file = TemFile::findOne($key); |
|
|
|
|
|
|
|
if(!$tem_file) { |
|
|
|
return ['status' => false, 'info' => '存在查找不到的文件']; |
|
|
|
} |
|
|
|
|
|
|
|
$res = self::saveNewFile($tem_file, $ownId, $ownType); |
|
|
|
if(!$res['status']) { |
|
|
|
return ['status' => false, 'info' => '存在文件保存失败']; |
|
|
|
} |
|
|
|
if($i == 1) { |
|
|
|
$first_file_id = $res['file_id']; |
|
|
|
} |
|
|
|
|
|
|
|
$i++; |
|
|
|
} |
|
|
|
|
|
|
|
return ['status' => true, 'info' => '保存成功', 'first_file_id' => $first_file_id]; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param $temFile |
|
|
|
* @param $ownId |
|
|
|
* @param $ownType |
|
|
|
* @return bool |
|
|
|
* 创建新的文件 |
|
|
|
*/ |
|
|
|
private function saveNewFile($temFile, $ownId, $ownType) |
|
|
|
{ |
|
|
|
$new_file = new File(); |
|
|
|
$new_file->name = $temFile->name; |
|
|
|
$new_file->type = $temFile->type; |
|
|
|
$new_file->own_id = $ownId; |
|
|
|
$new_file->own_type = $ownType; |
|
|
|
$new_file->alias = $temFile->alias; |
|
|
|
$new_file->path = $temFile->path; |
|
|
|
if($new_file->save()) { |
|
|
|
return ['status' => true, 'file_id' => $new_file->id]; |
|
|
|
} else { |
|
|
|
return ['status' => false]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |