123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace app\admin\model\books;
- use think\Model;
- class Books extends Model
- {
- // 表名
- protected $name = 'books';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'book_type_text',
- 'is_new_recommend_text',
- 'createtime',
- 'updatetime',
- 'is_awards_text'
- ];
- public function getBookTypeList()
- {
- return ['0' => __('纸质书'), '1' => __('电子书')];
- }
- public function getIsNewRecommendList()
- {
- return ['0' => __('是'), '1' => __('否')];
- }
- public function getIsAwardsList()
- {
- return ['0' => __('是'), '1' => __('否')];
- }
- public function getIsSeriesList()
- {
- return ['0' => __('是'), '1' => __('否')];
- }
- public function getBookTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['book_type']) ? $data['book_type'] : '');
- $list = $this->getBookTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getIsNewRecommendTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['is_new_recommend']) ? $data['is_new_recommend'] : '');
- $list = $this->getIsNewRecommendList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getIsAwardsTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['is_awards']) ? $data['is_awards'] : '');
- $list = $this->getIsAwardsList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function file(){
- return $this->hasMany(BooksFile::class,'books_id','id')->where('is_deleted',1)->order('sort desc,id desc');
- }
- //课件
- public function coursewareFile(){
- return $this->hasMany(BooksFile::class,'books_id','id')->where('is_deleted',1)->where('type','0')->order('sort desc,id desc');
- }
- //资源
- public function resourceFile(){
- return $this->hasMany(BooksFile::class,'books_id','id')->where('is_deleted',1)->where('type','1')->order('sort desc,id desc');
- }
- //资料包
- public function packageFile(){
- return $this->hasMany(BooksFile::class,'books_id','id')->where('is_deleted',1)->where('type','2')->order('sort desc,id desc');
- }
- //样张
- public function specimenFile(){
- return $this->hasMany(BooksFile::class,'books_id','id')->where('is_deleted',1)->where('is_specimen','0')->order('sort desc,id desc');
- }
- }
|