<?php

namespace app\model;


use app\BaseModel;
use think\db\Query;
use think\model\relation\HasOne;


class SysOperateRecord extends BaseModel
{

    protected $name = "sys_operate_record";
    protected $pk = "id";

    public function operateUser(): HasOne
    {
        return $this->hasOne(SysUser::class, 'user_id', 'operate_user_id')->field('user_id,nickname,avatar,username,status');
    }

    public function request(): HasOne
    {
        return $this->hasOne(SysRequestRecord::class, 'context_id', 'context_id');
    }



    public function searchCreateTimeAttr(Query $query, array $value, array $data): void
    {
        $value = array_filter($value);
        count($value) >= 2 && $query->whereBetweenTime('create_time', $value[0], $value[1]);
    }
}