72 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace app\common\model;
 | 
						|
 | 
						|
use think\Model;
 | 
						|
 | 
						|
class ManystoreAttachment extends BaseModel
 | 
						|
{
 | 
						|
 | 
						|
    // 开启自动写入时间戳字段
 | 
						|
    protected $autoWriteTimestamp = 'int';
 | 
						|
    // 定义时间戳字段名
 | 
						|
    protected $createTime = 'createtime';
 | 
						|
    protected $updateTime = 'updatetime';
 | 
						|
    // 定义字段类型
 | 
						|
    protected $type = [
 | 
						|
    ];
 | 
						|
    protected $append = [
 | 
						|
        'thumb_style'
 | 
						|
    ];
 | 
						|
 | 
						|
    public function setUploadtimeAttr($value)
 | 
						|
    {
 | 
						|
        return is_numeric($value) ? $value : strtotime($value);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * 获取云储存的缩略图样式字符
 | 
						|
     */
 | 
						|
    public function getThumbStyleAttr($value, $data)
 | 
						|
    {
 | 
						|
        if (!isset($data['storage']) || $data['storage'] == 'local') {
 | 
						|
            return '';
 | 
						|
        } else {
 | 
						|
            $config = get_addon_config($data['storage']);
 | 
						|
            if ($config && isset($config['thumbstyle'])) {
 | 
						|
                return $config['thumbstyle'];
 | 
						|
            }
 | 
						|
        }
 | 
						|
        return '';
 | 
						|
    }
 | 
						|
 | 
						|
    public static function getMimetypeList()
 | 
						|
    {
 | 
						|
        $data = [
 | 
						|
            "image/*"        => __("Image"),
 | 
						|
            "audio/*"        => __("Audio"),
 | 
						|
            "video/*"        => __("Video"),
 | 
						|
            "text/*"         => __("Text"),
 | 
						|
            "application/*"  => __("Application"),
 | 
						|
            "zip,rar,7z,tar" => __("Zip"),
 | 
						|
        ];
 | 
						|
        return $data;
 | 
						|
    }
 | 
						|
 | 
						|
    protected static function init()
 | 
						|
    {
 | 
						|
        // 如果已经上传该资源,则不再记录
 | 
						|
        self::beforeInsert(function ($model) {
 | 
						|
            if (self::where('url', '=', $model['url'])->where(array('shop_id'=>$model['shop_id']))->where('storage', $model['storage'])->find()) {
 | 
						|
                return false;
 | 
						|
            }
 | 
						|
        });
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    public function user()
 | 
						|
    {
 | 
						|
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
 | 
						|
    }
 | 
						|
}
 |