Order.php 2.3 KB
<?php

namespace app\admin\model\verification;

use think\Model;


class Order extends Model
{

    

    

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

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

    // 追加属性
    protected $append = [
        'type_text',
        'paytime_text',
        'refundtime_text'
    ];
    

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


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


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


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

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

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


    public function store()
    {
        return $this->belongsTo('Store', 'verification_store_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function coupon()
    {
        return $this->belongsTo('Coupon', 'verification_coupon_ids', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function activity()
    {
        return $this->belongsTo('Activity', 'verification_activity_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


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