FileManager.php 2.42 KB
<?php

namespace common\helpers;

/**
 * 极办公系统	文件资源管理器
 * Class FileManager
 * @package app\common\helpers
 */
class FileManager
{
    private static $VOICE_ROOT_PATH     = 'call_voice/'; // 录音文件路径
    private static $TEMP_ROOT_PATH      = 'tmp/'; // 临时目录
    private static $INVOICE_ROOT_PATH   = 'invoice/'; // 电子发票

    public static function getUrl($path)
    {
        if(empty($path)) {
            return '';
        }

        return FileServiceHelper::getUrl($path);
    }

    /**
     * 添加上传图片
     * @param $tmpPath
     * @param $savePath
     */
    public static function add($tmpPath, $savePath)
    {
        return FileServiceHelper::add($tmpPath, $savePath);
    }

    /**
     * 替换图片
     * @param $oldPath
     * @param $newPath
     * @param $tmpPath
     */
    public static function replace($oldPath, $newPath, $tmpPath)
    {
        return FileServiceHelper::replace($oldPath, $newPath, $tmpPath);
    }

    /**
     * 移动图片存放位置
     * @param $oldPath
     * @param $newPath
     * @return mixed
     */
    public static function move($oldPath, $newPath)
    {
        FileServiceHelper::move($oldPath, $newPath);
    }

    /**
     * 删除旧图片
     * @param $path
     */
    public static function delete($path){
        FileServiceHelper::delete($path);
    }


    /**
     * 获取电子发票pdf文件存储路径
     * @param $sid
     * @param string $suffix
     * @return string
     */
    public static function getInvoicePdfPath($sid, $suffix = "pdf")
    {
        $imageName = $sid . '.' . $suffix;
        $basePath = self::$INVOICE_ROOT_PATH . date("Ymd");
        $savePath =  $basePath . '/' . $imageName;
        return $savePath;
    }

    /** 组织声音文件的路径
     * @param $orderId
     * @param $recordId
     * @param string $suffix
     * @return string
     */
    public static function getOrderCallVoice($orderId, $recordId, $suffix = "wav")
    {
        $fileName = $recordId . '.' . $suffix;
        $basePath = self::$VOICE_ROOT_PATH  . $orderId;
        $savePath =  $basePath . '/' . $fileName;
        return $savePath;
    }

    /** 删除临时语音文件
     * @param $tmpPath
     */
    public static function deleteLocalTmpVoice($tmpPath)
    {
        if (is_file($tmpPath)) {
            if (unlink($tmpPath)) {
                return true;
            }
        }
        return false;
    }
}