Server : nginx/1.20.1
System : Linux iZ2ze9ojcl78uluczwag69Z 4.18.0-240.22.1.el8_3.x86_64 #1 SMP Thu Apr 8 19:01:30 UTC 2021 x86_64
User : www ( 1000)
PHP Version : 7.3.28
Disable Function : passthru,exec,system,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Directory :  /www/wwwroot/0531yanglao.com/app/common/model/
Upload File :
Current Directory [ Writeable ] Root Directory [ Writeable ]


Current File : /www/wwwroot/0531yanglao.com/app/common/model/Attachment.php
<?php
namespace app\common\model;

use app\common\utils\Upload;
use think\Model;

class Attachment extends BaseModel {
    
    protected $pk = 'aid';
    
    /*public static function onAfterDelete($model)
    {
        $filename = $model->getData('filename');
        if(!empty($filename)) {
             \Upload::delAttach($filename);
        }
    }*/

    /**
     * 附件删除
     * @param unknown $where    条件
     * @return bool
     */
    public static function del($filename)
    {
        if(empty($filename)) {
            return true;
        }
        try {
            $where = [];
            $where[] = ['filename|url', '=', $filename];
            $model = self::detail($where);
            Upload::delAttach($model->filename);
            $model->delete();
        }catch (\Exception $e){
            Log::add($e->getMessage());
            return false;
        }

        return true;
    }
    
    /**
     * 获取图片访问地址
     * @param unknown $value
     * @return string
     */
    public function getFilenameAttr($value)
    {
        return Upload::getUrl($value);
    }
    
    
    /**
     * 根据hash 更新table_id
     * @param unknown $hash
     * @param unknown $table_id
     */
    public static function updateTableId($hash , $table_id)
    {
        self::where('hash','in',$hash)->update(['table_id'=>$table_id]);
    }
    
    /**
     * 根据hash更新排序
     * @param unknown $hash
     */
    public static function updateSort($hash)
    {
        $hash = explode(',', $hash);
        foreach ($hash as $key=>$value)
        {
            self::where('hash',$value)->update(['sort'=>$key]);
        }
    }
}