<?php

namespace app\common\model;

use support\think\Model;

class GamePeriod extends Model
{
    protected $name = 'game_record';

    protected $autoWriteTimestamp = true;

    protected $type = [
        'create_time'     => 'integer',
        'update_time'     => 'integer',
        'period_start_at' => 'integer',
        'status'          => 'integer',
        'draw_mode'       => 'integer',
        'result_number'   => 'integer',
    ];

    /**
     * 后台表单 datetime 可能提交字符串，入库前转为 Unix 时间戳
     * ThinkPHP 修改器签名为 (mixed $value, array $data)
     */
    public function setPeriodStartAtAttr($value, $data = [])
    {
        if ($value === null || $value === '') {
            return 0;
        }
        if (is_int($value)) {
            return $value;
        }
        if (is_string($value)) {
            $t = strtotime($value);
            if ($t !== false) {
                return $t;
            }
        }
        return 0;
    }
}
