<?php

namespace app\admin\model;

use think\Model;


class Wenzhenorder extends Model
{

    

    

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

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

    // 追加属性
    protected $append = [
        'ordertype_text',
        'book_time_text',
        'status_text',
        'cancel_time_text',
        'pay_time_text',
        'accept_time_text',
        'video_time_text',
        'finish_time_text',
        'feedback_time_text',
        'refund_status_text',
        'comefrom_text'
    ];
    

    
    public function getOrdertypeList()
    {
        return ['1' => __('Ordertype 1'), '2' => __('Ordertype 2')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '3' => __('Status 3'), '10' => __('Status 10'), '13' => __('Status 13'), '16' => __('Status 16'), '18' => __('Status 18'), '20' => __('Status 20'), '22' => __('Status 22'), '25' => __('Status 25'), '30' => __('Status 30')];
    }

    public function getRefundStatusList()
    {
        return ['0' => __('Refund_status 0'), '1' => __('Refund_status 1'), '2' => __('Refund_status 2'), '3' => __('Refund_status 3')];
    }

    public function getComefromList()
    {
        return ['1' => __('Comefrom 1'), '2' => __('Comefrom 2')];
    }


    public function getOrdertypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['ordertype']) ? $data['ordertype'] : '');
        $list = $this->getOrdertypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getBookTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['book_time']) ? $data['book_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $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 getCancelTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cancel_time']) ? $data['cancel_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


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


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


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


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


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


    public function getRefundStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['refund_status']) ? $data['refund_status'] : '');
        $list = $this->getRefundStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

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

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

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

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

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

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

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

    public function getComefromTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['comefrom']) ? $data['comefrom'] : '');
        $list = $this->getComefromList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function doctor()
    {
        return $this->belongsTo('Doctor', 'doctor_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
