DomainInfo.php 3.9 KB
<?php

namespace App\Models\Domain;

use App\Helper\Arr;
use App\Models\Base;
use Illuminate\Support\Facades\Cache;

/**
 * Class DomainInfo
 *
 * @package App\Models\Aside\DomainLogic
 * @Author YiYuan-LIn
 * @Date : 2019/5/16
 * 域名信息模型
 */
class DomainInfo extends Base
{
    const SERVER_IP_301 = '43.135.137.172';
    const STATUS_ONE = 1;
    const STATUS_ZERO = 0;
    public $btAction = [
        'create_site' => '/site?action=AddSite',
    ];

    protected $table = 'gl_domain_info';

    // 软删除 0:正常 1:删除
    /** @var int 软删除 - 正常 */
    const DELETED_NORMAL = 0;
    /** @var int 软删除 - 删除 */
    const DELETED_DELETE = 1;

    protected $hidden = [
//        'created_at',
        'updated_at'
    ];

    /**
     * 字段信息
     * @return array
     */
    public function FieldsArray()
    {
        return [
            'domain'                 => '域名',
            'belong_to'              => '域名归属',
            'status'                 => '域名状态',
            'domain_start_time'      => '域名开始时间',
            'domain_end_time'        => '域名结束时间',
            'certificate_start_time' => '证书开始时间',
            'certificate_end_time'   => '证书结束时间',
        ];
    }


    /**
     * @remark :获取域名信息
     * @name   :getDomain
     * @author :lyh
     * @method :post
     * @time   :2023/9/4 17:05
     */
    public function getDomain($domain){
        $res_domain = Cache::get('domain_'.$domain);
        if(empty($res_domain)){
            $info = $this->read(['id'=>$domain]);
            if($info === false){
                return '';
            }
            $res_domain = 'https://'.$info['domain'].'/';
            Cache::put('domain_'.$domain,$res_domain,2 * 3600);
        }
        return $res_domain;
    }

    /**
     * @remark :根据项目id获取域名
     * @name   :getProjectIdDomain
     * @author :lyh
     * @method :post
     * @time   :2024/5/29 9:28
     */
    public function getProjectIdDomain($project_id){
        $info = $this->read(['project_id'=>$project_id],['domain']);
        if($info === false){
            return '';
        }
        return 'https://'.$info['domain'].'/';
    }

    /**
     * @remark :301跳转扩展字段
     * @name   :getExtendConfigAttribute
     * @author :lyh
     * @method :post
     * @time   :2023/11/6 15:36
     */
    public function getExtendConfigAttribute($value)
    {
        $value = Arr::s2a($value);
        return $value;
    }

    /**
     * @remark :域名列表设置
     * @name   :getOtherDomainAttribute
     * @author :lyh
     * @method :post
     * @time   :2023/11/6 15:39
     */
    public function getOtherDomainAttribute($value)
    {
        $value = Arr::s2a($value);
        return $value;
    }

    /**
     * 禁止访问国家
     * @param $value
     * @return array|mixed
     * @author Akun
     * @date 2024/07/01 17:05
     */
    public function getNotAllowCountryAttribute($value)
    {
        $value = Arr::s2a($value);
        return $value;
    }

    /**
     * 禁止访问ip
     * @param $value
     * @return array|mixed
     * @author Akun
     * @date 2024/07/01 17:05
     */
    public function getNotAllowIpAttribute($value)
    {
        $value = Arr::s2a($value);
        return $value;
    }

    /**
     * amp301跳转扩展字段
     * @param $value
     * @return array|mixed
     * @author Akun
     * @date 2024/12/03 17:26
     */
    public function getAmpExtendConfigAttribute($value)
    {
        $value = Arr::s2a($value);
        return $value;
    }

    public static function getCacheInfoByProjectId($project_id){
        $cache_key = 'DOMAIN_INFO_BY_PROJECT_ID_' . $project_id;
        $data = Cache::get($cache_key);
        if(!$data){
            $data = DomainInfo::where('project_id', $project_id)->first();
            if($data){
                Cache::put($cache_key, $data, 3600);
            }
        }
        return $data;
    }
}