You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.1 KiB
67 lines
2.1 KiB
<?php
|
|
/**
|
|
* raingad IM [ThinkPHP6]
|
|
* @author xiekunyu <raingad@foxmail.com>
|
|
*/
|
|
namespace app\enterprise\model;
|
|
|
|
use app\BaseModel;
|
|
class File extends BaseModel
|
|
{
|
|
protected $pk="file_id";
|
|
|
|
// 同步彻底删除文件
|
|
public static function syncDelFile($file_id)
|
|
{
|
|
if ($file_id) {
|
|
$file = new self();
|
|
$item = $file->where('file_id', $file_id)->find();
|
|
$Emoji = Emoji::where(['file_id'=>$file_id,'delete_time'=>0])->find();
|
|
if ($Emoji) {
|
|
return false;
|
|
}
|
|
$PostsFile = PostsFile::where(['file_id'=>$file_id,'delete_time'=>0])->find();
|
|
if ($PostsFile) {
|
|
return false;
|
|
}
|
|
$Message = Message::where(['file_id' => $file_id])->find();
|
|
if ($Message) {
|
|
return false;
|
|
}
|
|
if ($item) {
|
|
// 删除文件
|
|
$filename_dir = root_path();
|
|
$file_path = $filename_dir . 'public/' . ltrim($item->src,'/');
|
|
if (file_exists($file_path)) {
|
|
unlink($file_path);
|
|
}
|
|
|
|
// 删除图片
|
|
$compress_img = $item->compress_img;
|
|
if ($compress_img) {
|
|
$img_path = $filename_dir . 'public/' . ltrim($compress_img,'/');
|
|
if (file_exists($img_path)) {
|
|
unlink($img_path);
|
|
}
|
|
}
|
|
|
|
// 删除图片数据
|
|
$file->where('file_id', $file_id)->delete();
|
|
self::againDelete($file_id, $item->src);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
protected static function againDelete($file_id,$src)
|
|
{
|
|
$existsFilePath = public_path() . '/' . ltrim($src,'/');
|
|
if (!file_exists($existsFilePath)) {
|
|
File::where('file_id', $file_id)->delete();
|
|
Emoji::where(['file_id'=>$file_id])->delete();
|
|
PostsFile::where(['file_id'=>$file_id])->delete();
|
|
Message::where(['file_id'=>$file_id])->delete();
|
|
}
|
|
}
|
|
}
|