|
|
@ -8,13 +8,13 @@ class GoodsManager |
|
|
|
{ |
|
|
|
/** |
|
|
|
* @param $newFileIdArr |
|
|
|
* @param array $oldFileIdArr |
|
|
|
* @param $goodsModel |
|
|
|
* @param int $filetype |
|
|
|
* @return bool |
|
|
|
* @param array $oldFileIdArr |
|
|
|
* @param int $fileType |
|
|
|
* @return array |
|
|
|
* 保存新文件,删除不需要的文件操作 |
|
|
|
*/ |
|
|
|
public function saveFile($newFileIdArr, $goodsModel, $oldFileIdArr = [], $filetype = 1) |
|
|
|
public function saveFile($newFileIdArr, $goodsModel, $oldFileIdArr = [], $fileType = 1) |
|
|
|
{ |
|
|
|
//判断类名是否存在
|
|
|
|
if(!class_exists('\backend\logic\file\FileManager') || !class_exists('\common\models\ars\File')) { |
|
|
@ -22,30 +22,30 @@ class GoodsManager |
|
|
|
} |
|
|
|
|
|
|
|
//需要新建的文件id
|
|
|
|
$create_file_id_arr = array_diff($newFileIdArr, $oldFileIdArr); |
|
|
|
$createFileIdArr = array_diff($newFileIdArr, $oldFileIdArr); |
|
|
|
|
|
|
|
//创建文件
|
|
|
|
$class = new \backend\logic\file\FileManager(); |
|
|
|
$create_file_res = $class->saveTemFileToFile($create_file_id_arr, $goodsModel->id, $filetype); |
|
|
|
$createFileRes = $class->saveTemFileToFile($createFileIdArr, $goodsModel->id, $fileType); |
|
|
|
|
|
|
|
//需要删除的文件id
|
|
|
|
$del_file_id_arr = array_diff($oldFileIdArr, $newFileIdArr); |
|
|
|
$delFileIdArr = array_diff($oldFileIdArr, $newFileIdArr); |
|
|
|
|
|
|
|
//删除文件
|
|
|
|
$class->deleteFile($del_file_id_arr); |
|
|
|
$class->deleteFile($delFileIdArr); |
|
|
|
|
|
|
|
//记录第一张图片id
|
|
|
|
$first_file_id = 0; |
|
|
|
$firstFileId = 0; |
|
|
|
|
|
|
|
//查看修改数组是否为空
|
|
|
|
if (!$newFileIdArr[0]) { |
|
|
|
$first_file_id = null; |
|
|
|
$firstFileId = null; |
|
|
|
}else { |
|
|
|
if ($create_file_res['status']) { |
|
|
|
$first_file_id = $create_file_res['first_file_id']; |
|
|
|
if ($createFileRes['status']) { |
|
|
|
$firstFileId = $createFileRes['first_file_id']; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return ['status' => true, 'info' => '操作成功', 'first_file_id' => $first_file_id]; |
|
|
|
return ['status' => true, 'info' => '操作成功', 'first_file_id' => $firstFileId]; |
|
|
|
} |
|
|
|
} |