<?php

namespace app\model\app;

use support\Model;

/**
 * @property integer $id ID (主键)
 * @property string $title 标题
 * @property string $content 内容 (包含 HTML)
 * @property integer $status 状态 0禁用 1启用
 * @property string $status_text 状态文本
 * @property integer $createtime 创建时间
 * @property integer $updatetime 更新时间
 */
class Announcement extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'announcements';  // 表名

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';  // 主键

    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = true;  // 不使用自动时间戳

    /**
     * 可以赋值字段
     *
     * @var array
     */
    protected $fillable = [
        'title',
        'content',
        'status',
        'status_text',
        'createtime',
        'updatetime',
    ];

    /**
     * 字段类型
     *
     * @var array
     */
    protected $casts = [
        'createtime' => 'integer',
        'updatetime' => 'integer',
        'status' => 'integer',
    ];

    /**
     * 获取创建时间的格式化值
     *
     * @param mixed $value
     * @return string
     */
    public function getCreatetimeAttribute($value)
    {
        return date('Y-m-d H:i:s', $value);
    }

    /**
     * 获取更新时间的格式化值
     *
     * @param mixed $value
     * @return string
     */
    public function getUpdatetimeAttribute($value)
    {
        return date('Y-m-d H:i:s', $value);
    }

    /**
     * 获取状态文本
     *
     * @param mixed $value
     * @return string
     */
    public function getStatusTextAttribute($value)
    {
        return $value ?? '未设置';
    }
}
/**
 * CREATE TABLE `announcements` (
  `id` INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY COMMENT 'ID (主键)',
  `title` VARCHAR(255) NOT NULL COMMENT '标题',
  `content` TEXT NOT NULL COMMENT '内容 (包含 HTML)',
  `status` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '状态 0禁用 1启用',
  `status_text` VARCHAR(255) DEFAULT NULL COMMENT '状态文本',
  `createtime` INT(11) UNSIGNED NOT NULL COMMENT '创建时间',
  `updatetime` INT(11) UNSIGNED DEFAULT NULL COMMENT '更新时间',
  KEY `status` (`status`), 
  KEY `createtime` (`createtime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='公告表';

 */