Browse Source

根据代码规范修改

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
e26fb486f0
  1. 52
      backend/logic/file/FileManager.php

52
backend/logic/file/FileManager.php

@ -26,7 +26,7 @@ class FileManager
/** /**
* @param $array * @param $array
* @param $keyword * @param $keyword
* @return bool|int|string
* @return array
* 根据文件拓展名在$extension中查找对应的文件类型,若不存在则返回false * 根据文件拓展名在$extension中查找对应的文件类型,若不存在则返回false
*/ */
public function searchType($array, $keyword) public function searchType($array, $keyword)
@ -42,11 +42,11 @@ class FileManager
} }
/** /**
* @param $imgIdStr
* @param $temFIleIdArr
* @param $ownId * @param $ownId
* @param $ownType * @param $ownType
* @return array * @return array
* 根据临时文件id(字符串)将临时文件保存在文件中
* 根据临时文件id将临时文件保存在文件中
*/ */
public function saveTemFileToFile($temFIleIdArr, $ownId, $ownType) public function saveTemFileToFile($temFIleIdArr, $ownId, $ownType)
{ {
@ -54,47 +54,44 @@ class FileManager
return ['status' => false, 'info' => '参数错误']; return ['status' => false, 'info' => '参数错误'];
} }
$i = 1;
$first_file_id = 0;
$firstFileId = 0;
foreach ($temFIleIdArr as $key => $value) { foreach ($temFIleIdArr as $key => $value) {
$tem_file = TemFile::findOne($value);
$temFile = TemFile::findOne($value);
if(!$tem_file) {
if(!$temFile) {
return ['status' => false, 'info' => '存在查找不到的文件']; return ['status' => false, 'info' => '存在查找不到的文件'];
} }
$res = self::saveNewFile($tem_file, $ownId, $ownType);
$res = self::saveNewFile($temFile, $ownId, $ownType);
if(!$res['status']) { if(!$res['status']) {
return ['status' => false, 'info' => '存在文件保存失败']; return ['status' => false, 'info' => '存在文件保存失败'];
} }
if($i == 1) {
$first_file_id = $res['file_id'];
if($key == 0) {
$firstFileId = $res['file_id'];
} }
$i++;
} }
return ['status' => true, 'info' => '保存成功', 'first_file_id' => $first_file_id];
return ['status' => true, 'info' => '保存成功', 'first_file_id' => $firstFileId];
} }
/** /**
* @param $temFile * @param $temFile
* @param $ownId * @param $ownId
* @param $ownType * @param $ownType
* @return bool
* @return array
* 创建新的文件 * 创建新的文件
*/ */
private function saveNewFile($temFile, $ownId, $ownType) 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, 'info' => '操作成功', 'file_id' => $new_file->id];
$newFile = new File();
$newFile->name = $temFile->name;
$newFile->type = $temFile->type;
$newFile->own_id = $ownId;
$newFile->own_type = $ownType;
$newFile->alias = $temFile->alias;
$newFile->path = $temFile->path;
if($newFile->save()) {
return ['status' => true, 'info' => '操作成功', 'file_id' => $newFile->id];
} else { } else {
return ['status' => false, 'info' => '操作失败']; return ['status' => false, 'info' => '操作失败'];
} }
@ -102,16 +99,17 @@ class FileManager
/** /**
* @param $fileIdArr * @param $fileIdArr
* @return array
* 删除file表中的文件 * 删除file表中的文件
*/ */
public function deleteFile($fileIdArr) public function deleteFile($fileIdArr)
{ {
if($fileIdArr){ if($fileIdArr){
foreach ($fileIdArr as $key => $value) { foreach ($fileIdArr as $key => $value) {
$file_model = File::findOne($value);
if($file_model){
$file_model->is_delete = File::IS_DELETE_YES;
if($file_model->save()){
$fileModel = File::findOne($value);
if($fileModel){
$fileModel->is_delete = File::IS_DELETE_YES;
if($fileModel->save()){
return ['status' => false, 'info' => '操作失败']; return ['status' => false, 'info' => '操作失败'];
} }
} }

Loading…
Cancel
Save