<?php namespace app\admin\model; use think\Model; class Agreement extends Model { // 表名 protected $name = 'agreement'; // 自动写入时间戳字段 protected $autoWriteTimestamp = 'int'; // 定义时间戳字段名 protected $createTime = 'createtime'; protected $updateTime = 'updatetime'; protected $deleteTime = false; // 追加属性 protected $append = [ 'status_text', 'refind_status_text', 'EXP_time_text' ]; public function getStatusList() { return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4')]; } public function getRefindStatusList() { return ['0' => __('Refind_status 0'), '1' => __('Refind_status 1'), '2' => __('Refind_status 2'), '3' => __('Refind_status 3')]; } public function getStatusTextAttr($value, $data) { $value = $value ? $value : (isset($data['status']) ? $data['status'] : ''); $list = $this->getStatusList(); return isset($list[$value]) ? $list[$value] : ''; } public function getRefindStatusTextAttr($value, $data) { $value = $value ? $value : (isset($data['refind_status']) ? $data['refind_status'] : ''); $list = $this->getRefindStatusList(); return isset($list[$value]) ? $list[$value] : ''; } public function getExpTimeTextAttr($value, $data) { $value = $value ? $value : (isset($data['EXP_time']) ? $data['EXP_time'] : ''); return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } protected function setExpTimeAttr($value) { return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); } public function user() { return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function seller() { return $this->belongsTo('Seller', 'seller_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function batterycode() { return $this->belongsTo('BatteryCode', 'battery_id', 'id', [], 'LEFT')->setEagerlyType(0); } }