BtEvents.php 1.5 KB
<?php
/**
 * Created by PhpStorm.
 * User: zhl
 * Date: 2022/11/03
 * Time: 09:53
 */
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

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

    // 最大执行次数
    const MAX_TRIES_TIMES = 3;

    const STATUS_INIT = 0;
    const STATUS_FINISH = 1;
    const STATUS_ERROR = 9;

    const TYPE_CREATE_SITE = 1;
    const TYPE_DELETE_SITE = 2;
    const TYPE_CREATE_SSL = 3;
    const TYPE_RENEWAL_SSL = 4;
    const TYPE_HTTP_TO_HTTPS_OPEN = 5;
    const TYPE_HTTP_TO_HTTPS_CLOSE = 6;
    const TYPE_EVENT_CALLBACK = 99;

    /**
     * @return array
     */
    public static function typeMap()
    {
        return [
            self::TYPE_CREATE_SITE => '创建站点',
            self::TYPE_DELETE_SITE => '删除站点',
            self::TYPE_CREATE_SSL => '创建ssl证书',
            self::TYPE_RENEWAL_SSL => '续签ssl证书',
            self::TYPE_HTTP_TO_HTTPS_OPEN => '开启强制https',
            self::TYPE_HTTP_TO_HTTPS_CLOSE => '关闭强制https',
        ];
    }

    /**
     * @param $type
     * @param $param
     * @return mixed
     */
    public static function createBtEvent($type, $param, $start_at = '')
    {
        $start_at = $start_at ?: date('Y-m-d H:i:s');
        $event = new self();
        $event->type = $type;
        $event->param = $param;
        $event->start_at = $start_at;
        $event->save();
        return $event->id;
    }
}