Books.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\admin\model\books;
  3. use think\Model;
  4. class Books extends Model
  5. {
  6. // 表名
  7. protected $name = 'books';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'book_type_text',
  17. 'is_new_recommend_text',
  18. 'createtime',
  19. 'updatetime',
  20. 'is_awards_text'
  21. ];
  22. public function getBookTypeList()
  23. {
  24. return ['0' => __('纸质书'), '1' => __('电子书')];
  25. }
  26. public function getIsNewRecommendList()
  27. {
  28. return ['0' => __('是'), '1' => __('否')];
  29. }
  30. public function getIsAwardsList()
  31. {
  32. return ['0' => __('是'), '1' => __('否')];
  33. }
  34. public function getIsSeriesList()
  35. {
  36. return ['0' => __('是'), '1' => __('否')];
  37. }
  38. public function getBookTypeTextAttr($value, $data)
  39. {
  40. $value = $value ? $value : (isset($data['book_type']) ? $data['book_type'] : '');
  41. $list = $this->getBookTypeList();
  42. return isset($list[$value]) ? $list[$value] : '';
  43. }
  44. public function getIsNewRecommendTextAttr($value, $data)
  45. {
  46. $value = $value ? $value : (isset($data['is_new_recommend']) ? $data['is_new_recommend'] : '');
  47. $list = $this->getIsNewRecommendList();
  48. return isset($list[$value]) ? $list[$value] : '';
  49. }
  50. public function getIsAwardsTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['is_awards']) ? $data['is_awards'] : '');
  53. $list = $this->getIsAwardsList();
  54. return isset($list[$value]) ? $list[$value] : '';
  55. }
  56. public function file(){
  57. return $this->hasMany(BooksFile::class,'books_id','id')->where('is_deleted',1)->order('sort desc,id desc');
  58. }
  59. //课件
  60. public function coursewareFile(){
  61. return $this->hasMany(BooksFile::class,'books_id','id')->where('is_deleted',1)->where('type','0')->order('sort desc,id desc');
  62. }
  63. //资源
  64. public function resourceFile(){
  65. return $this->hasMany(BooksFile::class,'books_id','id')->where('is_deleted',1)->where('type','1')->order('sort desc,id desc');
  66. }
  67. //资料包
  68. public function packageFile(){
  69. return $this->hasMany(BooksFile::class,'books_id','id')->where('is_deleted',1)->where('type','2')->order('sort desc,id desc');
  70. }
  71. //样张
  72. public function specimenFile(){
  73. return $this->hasMany(BooksFile::class,'books_id','id')->where('is_deleted',1)->where('is_specimen','0')->order('sort desc,id desc');
  74. }
  75. }