<?php namespace app\admin\model; use think\Model; class Order extends Model { // 表名 protected $name = 'order'; // 自动写入时间戳字段 protected $autoWriteTimestamp = 'int'; // 定义时间戳字段名 protected $createTime = 'createtime'; protected $updateTime = 'updatetime'; protected $deleteTime = false; // 追加属性 protected $append = [ 'order_status_text', 'invoice_status_text' ]; public function getOrderStatusList() { return ['0' => __('Order_status 0'), '1' => __('Order_status 1'), '2' => __('Order_status 2'), '3' => __('Order_status 3')]; } public function getInvoiceStatusList() { return ['0' => __('Invoice_status 0'), '1' => __('Invoice_status 1'), '2' => __('Invoice_status 2'), '3' => __('Invoice_status 3')]; } public function getOrderStatusTextAttr($value, $data) { $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : ''); $list = $this->getOrderStatusList(); return isset($list[$value]) ? $list[$value] : ''; } 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 user() { return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); } }