BookCollect.php 897 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class BookCollect extends Model
  5. {
  6. // 表名
  7. protected $table = 'book_collect';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. // 追加属性
  14. protected $append = [
  15. 'type_text'
  16. ];
  17. public function getTypeList()
  18. {
  19. return ['1' => __('Type 1'),'2' => __('Type 2'),'3' => __('Type 3')];
  20. }
  21. public function getTypeTextAttr($value, $data)
  22. {
  23. $value = $value ? $value : $data['type'];
  24. $list = $this->getTypeList();
  25. return isset($list[$value]) ? $list[$value] : '';
  26. }
  27. public function book()
  28. {
  29. return $this->belongsTo('Book', 'book_id', 'id')->setEagerlyType(0);
  30. }
  31. }