<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%CALC_BE_LOG}}".
 *
 * @property string $ID
 * @property string $PERIOD_NUM 周期
 * @property string $TEXT 日志
 * @property int $CREATED_AT 创建时间
 */
class CalcRecord extends \common\components\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%CALC_BE_LOG}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['PERIOD_NUM', 'TEXT'], 'required'],
            [['PERIOD_NUM'], 'number'],
            [['ID'], 'unique'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'ID'         => 'ID',
            'PERIOD_NUM' => '周期数',
            'TEXT'       => '日志',
            'CREATED_AT' => '创建时间',
        ];
    }

    public static function record($periodNum, $text): bool
    {
        CalcRecord::insertOne([
            'PERIOD_NUM' => $periodNum,
            'TEXT'       => $text,
            'CREATED_AT' => time(),
        ]);
        return true;
    }
}
