AlarmMonitoring.php 1.6 KB
<?php

namespace app\admin\model\reservoir\hkws;

use think\Model;


class AlarmMonitoring extends Model
{

    

    

    // 表名
    protected $name = 'reservoir_hkws_alarm_monitoring';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'alarm_type_text',
        'status_text'
    ];
    

    
    public function getAlarmTypeList()
    {
        return ['LINE_CROSSING_DETECTION' => __('Line_crossing_detection'), 'REGION_ENTRANCE_DETECTION' => __('Region_entrance_detection'), 'INTRUSION_DETECTION' => __('Intrusion_detection')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }


    public function getAlarmTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['alarm_type']) ? $data['alarm_type'] : '');
        $list = $this->getAlarmTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function reservoirlist()
    {
        return $this->belongsTo('app\admin\model\reservoir\Reservoirlist', 'reservoir_list_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}