<?php

namespace app\admin\model\sos;

use think\Model;


class Rescue extends Model
{

    

    

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

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

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

    
    public function getWorkWeekList()
    {
        return ['1' => __('Work_week 1'), '2' => __('Work_week 2'), '3' => __('Work_week 3'), '4' => __('Work_week 4'), '5' => __('Work_week 5'), '6' => __('Work_week 6'), '7' => __('Work_week 7')];
    }

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


    public function getWorkWeekTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['work_week']) ? $data['work_week'] : '');
        $valueArr = explode(',', $value);
        $list = $this->getWorkWeekList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }


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

    protected function setWorkWeekAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }


}
