'timestamp', 'free_etime' => 'timestamp' ]; // 追加属性 protected $append = [ 'type_text' ]; protected static function init() { self::afterInsert(function ($row) { $pk = $row->getPk(); $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]); }); } public function getTypeList() { return ['1' => '书籍', '2' => '跳转URL', '3' => '专题']; } public function getTypeTextAttr($value, $data) { $value = $value ? $value : $data['type']; $list = $this->getTypeList(); return isset($list[$value]) ? $list[$value] : ''; } public function manageblock() { return $this->belongsTo('ManageBlock', 'block_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function book() { return $this->belongsTo('Book', 'book_id', 'id', [], 'LEFT')->setEagerlyType(0); } }