<?php namespace app\admin\model; use think\Model; class OrderInvoice extends Model { // 表名 protected $name = 'order_invoice'; // 自动写入时间戳字段 protected $autoWriteTimestamp = 'int'; // 定义时间戳字段名 protected $createTime = 'createtime'; protected $updateTime = 'updatetime'; protected $deleteTime = false; // 追加属性 protected $append = [ 'invoice_status_text', 'invoice_type_text', 'invoice_head_text' ]; public function getInvoiceStatusList() { return ['1' => __('Invoice_status 1'), '2' => __('Invoice_status 2'), '3' => __('Invoice_status 3'), '4' => __('Invoice_status 4')]; } public function getInvoiceTypeList() { return ['1' => __('Invoice_type 1'), '2' => __('Invoice_type 2')]; } public function getInvoiceHeadList() { return ['1' => __('Invoice_head 1'), '2' => __('Invoice_head 2')]; } public function getInvoiceStatusTextAttr($value, $data) { $value = $value ? $value : (isset($data['invoice_status']) ? $data['invoice_status'] : ''); $list = $this->getInvoiceStatusList(); return isset($list[$value]) ? $list[$value] : ''; } public function getInvoiceTypeTextAttr($value, $data) { $value = $value ? $value : (isset($data['invoice_type']) ? $data['invoice_type'] : ''); $list = $this->getInvoiceTypeList(); return isset($list[$value]) ? $list[$value] : ''; } public function getInvoiceHeadTextAttr($value, $data) { $value = $value ? $value : (isset($data['invoice_head']) ? $data['invoice_head'] : ''); $list = $this->getInvoiceHeadList(); return isset($list[$value]) ? $list[$value] : ''; } public function user() { return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); } }