<?php

namespace app\admin\model\school\activity\order;

use think\Model;
use traits\model\SoftDelete;

class OrderCode extends Model
{

    use SoftDelete;

    

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

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

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

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


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


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

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


    public function order()
    {
        return $this->belongsTo(Order::class, 'activity_order_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('app\common\model\User', 'verification_user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
