BtSites.php 1.4 KB
<?php
/**
 * Created by PhpStorm.
 * User: zhl
 * Date: 2022/11/1
 * Time: 15:44
 */
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * Class BtSites
 * @package App\Models
 */
class BtSites extends Model
{
    /**
     * @var string $table
     */
    protected $table = 'bt_sites';

    const IS_DEL_FALSE = 0;
    const IS_DEL_TRUE = 1;

    const STATUS_OPEN = 1;
    const STATUS_CLOSE = 2;

    /**
     * @param $domain
     * @param $site_id
     * @param $ssl_open
     * @param $ssl_status
     * @param $ssl_auto
     * @param $ssl_auto_day
     * @return BtSites
     */
    public static function createBtSite($domain, $site_id, $ssl_open, $ssl_status, $ssl_auto, $ssl_auto_day)
    {
        $site = self::where(['domain' => $domain])->fisrt();
        if (empty($site)) {
            $site = new self();
        }
        $site->domain = $domain;
        $site->site_id = $site_id;
        $site->ssl_open = $ssl_open;
        $site->ssl_status = $ssl_status;
        $site->ssl_auto = $ssl_auto;
        $site->ssl_auto_day = $ssl_auto_day;
        $site->status = self::STATUS_OPEN;
        $site->is_del = self::IS_DEL_FALSE;
        $site->save();
        return $site;
    }

    /**
     * @param $domain
     * @return mixed
     */
    public static function getSiteByDomain($domain)
    {
        return self::where(['domain' => $domain, 'is_del' => self::IS_DEL_FALSE])->fisrt();
    }
}