<?php

namespace app\admin\model\books;

use think\Model;


class Contribute extends Model
{





    // 表名
    protected $name = 'contribute';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

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

    // 追加属性
    protected $append = [
        'manuscript_status_text',
        'last_publish_time_text',
        'funds_status_text'
    ];



    public function getManuscriptStatusList()
    {
        return ['0' => __('待启动'), '1' => __('编写中'), '2' => __('已截稿')];
    }

    public function getFundsStatusList()
    {
        return ['0' => __('无经费'), '1' => __('三万以内'), '2' => __('五万以内'), '3' => __('五万以上')];
    }


    public function getManuscriptStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['manuscript_status']) ? $data['manuscript_status'] : '');
        $list = $this->getManuscriptStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getLastPublishTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['last_publish_time']) ? $data['last_publish_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getFundsStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['funds_status']) ? $data['funds_status'] : '');
        $list = $this->getFundsStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setLastPublishTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
