ServerInformation.php 3.9 KB
<?php

namespace App\Models\Devops;

use App\Models\Base;

/**
 * App\Models\Devops\ServerInformation
 *
 * @property int $id
 * @property string $type 服务器类型
 * @property string|null $ip 服务器ip
 * @property string|null $title 服务器标题
 * @property string $belong_to 服务器归属 1 - 公司 2 - 客户
 * @property string|null $sshpass SSH 密码
 * @property int|null $ports SSH 端口
 * @property string|null $other 其他信息 json格式
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property int|null $deleted 软删除 0 - 正常 1 - 软删除
 * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation query()
 * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereBelongTo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereDeleted($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereIp($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereOther($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation wherePorts($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereSshpass($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class ServerInformation extends Base
{

    protected $table = 'gl_server_information';

    // 软删除 0:正常 1:删除
    const DELETED_NORMAL = 0;
    const DELETED_DELETE = 1;


    /**
     * @param $num
     *
     * @return string
     */
    public function Service($num)
    {
        return $this->ServiceArray()[$num];
    }

    /**
     * @return array
     */
    public function ServiceArray()
    {
        return [
            1 => '阿里云',
            2 => '腾讯云',
            3 => 'linode',
            4 => '尊云',
            5 => '互联',
            6 => '其他',
            7 => 'Ramnode',
            8 => 'CN2-SSD美国',
            9 => '国内测试服务器',
        ];
    }

    public function ServiceStr($num)
    {
        return array_flip($this->ServiceArray())[$num];
    }

    /**
     * 字段信息
     * @return array
     */
    public function FieldsArray()
    {
        return [
            'type'      => '服务器类型',
            'ip'        => '服务器IP',
            'title'     => '服务器标题',
            'belong_to' => '服务器归属',
            'sshpass'   => 'SSH 密码',
            'ports'     => 'SSH 端口',
            'other'     => '其他信息 json格式',
        ];
    }

    /**
     * 服务器归属信息
     * @return array
     */
    public function BelongToArray()
    {
        return [
            1 => '公司',
            2 => '客户',
        ];
    }

    public function BelongToStr($num)
    {
        return array_flip($this->BelongToArray())[$num];
    }

    public function BelongTo($num)
    {
        return $this->BelongToArray()[$num];
    }

    /**
     * 返回服务器类型
     * @param $value
     *
     * @return string
     */
    public function getTypeAttribute($value)
    {
        return $this->Service($value);
    }

    /**
     * 返回服务器归属
     * @param $value
     *
     * @return string
     */
    public function getBelongToAttribute($value)
    {
        return $this->BelongTo($value);
    }
}