BooksFile.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\admin\model\books;
  3. use think\Model;
  4. class BooksFile extends Model
  5. {
  6. // 表名
  7. protected $name = 'books_file';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'type_text',
  17. 'is_specimen_text',
  18. 'is_deleted_text'
  19. ];
  20. public function getTypeList()
  21. {
  22. return ['0' => __('课件'), '1' => __('资源'),'3' => __('电子书')];
  23. }
  24. public function getIsSpecimenList()
  25. {
  26. return ['0' => __('是'), '1' => __('否')];
  27. }
  28. public function getIsDeletedList()
  29. {
  30. return ['0' => __('是'), '1' => __('否')];
  31. }
  32. public function getTypeTextAttr($value, $data)
  33. {
  34. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  35. $list = $this->getTypeList();
  36. return isset($list[$value]) ? $list[$value] : '';
  37. }
  38. public function getIsSpecimenTextAttr($value, $data)
  39. {
  40. $value = $value ? $value : (isset($data['is_specimen']) ? $data['is_specimen'] : '');
  41. $list = $this->getIsSpecimenList();
  42. return isset($list[$value]) ? $list[$value] : '';
  43. }
  44. public function getIsDeletedTextAttr($value, $data)
  45. {
  46. $value = $value ? $value : (isset($data['is_deleted']) ? $data['is_deleted'] : '');
  47. $list = $this->getIsDeletedList();
  48. return isset($list[$value]) ? $list[$value] : '';
  49. }
  50. }