<?php

namespace app\admin\model\books;

use app\admin\model\User;
use think\Model;


class SampleApply extends Model
{





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

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

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

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



    public function getUseToList()
    {
        return ['0' => __('教材用书'), '1' => __('学习参考'), '2' => __('其他')];
    }

    public function getStatusList()
    {
        return ['0' => __('未审核'), '1' => __('已寄出'), '2' => __('已拒绝')];
    }


    public function getUseToTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['use_to']) ? $data['use_to'] : '');
        $list = $this->getUseToList();
        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 book(){
        return $this->hasOne(Books::class,'id','books_id');
    }

    public function user(){
        return $this->hasOne(User::class,'id','user_id');
    }




}
