ServerConfig.php 1.7 KB
<?php
/**
 * Created by PhpStorm.
 * User: zhl
 * Date: 2023/4/17
 * Time: 10:04
 */

namespace App\Models;

/**
 * 服务账户信息
 * Class ServeConfig
 * @package App\Models
 */
class ServerConfig extends Base
{
    /**
     * @var string
     */
    protected $table = 'gl_server_config';

    /**
     * @var array
     */
    protected $guarded = ['updated_at'];

    const UPDATED_AT = null;


    /**
     * 1:服务器, 2:MySQL, 3:Redis
     */
    const TYPE_SERVER = 1;
    const TYPE_MYSQL = 2;
    const TYPE_REDIS = 3;

    /**
     * @return string[]
     * @author zbj
     * @date 2023/4/23
     */
    public static function typeMap(){
        return [
            self::TYPE_SERVER => '服务器',
            self::TYPE_MYSQL => 'MySQL',
//            self::TYPE_REDIS => 'Redis',
        ];
    }

    /**
     * 用户名加密
     * @param $value
     */
    public function setUserAttribute($value)
    {
        $this->attributes['user'] = encrypt($value);
    }

    /**
     * 密码加密
     * @param $value
     */
    public function setPasswordAttribute($value)
    {
        $this->attributes['password'] = encrypt($value);
    }

    /**
     * 端口加密
     * @param $value
     */
    public function setPortAttribute($value)
    {
        $this->attributes['Port'] = encrypt($value);
    }

    /**
     * @return mixed
     */
    public function getUserAttribute($value)
    {
        return decrypt($value);
    }

    /**
     * @return mixed
     */
    public function getPasswordAttribute($value)
    {
        return decrypt($value);
    }

    /**
     * @return mixed
     */
    public function getPortAttribute($value)
    {
        return decrypt($value);
    }

}