<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class SplitModel extends Model
{
    protected $suffix = null;

    public function serializeDate(\DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    //设置表后缀
    public function setSuffix($suffix)
    {
        $this->suffix = $suffix;
        if ($suffix !== null) {
            $this->table = $this->getTable().'_'.$suffix;
        }
    }

    //设置表后缀-静态方法
    public static function suffix($suffix)
    {
        $instance = new static;
        $instance->setSuffix($suffix);
        return $instance->newQuery();
    }

    public static function getMonthSuffix()
    {
        $year = date("Y");
        $month = date("m");
        return $year.$month;
    }
}
