123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace app\admin\model\article;
- use think\Model;
- class Article extends Model
- {
-
-
- // 表名
- protected $name = 'article';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = false;
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'hidedata_text',
- 'is_hotdata_text',
- 'is_recdata_text',
- 'status_text'
- ];
-
-
- public function getHidedataList()
- {
- return ['0' => __('Hidedata 0'), '1' => __('Hidedata 1')];
- }
- public function getIsHotdataList()
- {
- return ['0' => __('Is_hotdata 0'), '1' => __('Is_hotdata 1')];
- }
- public function getIsRecdataList()
- {
- return ['0' => __('Is_recdata 0'), '1' => __('Is_recdata 1')];
- }
- public function getStatusList()
- {
- return ['0' => __('Status 0'), '1' => __('Status 1')];
- }
- public function getHidedataTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['hidedata']) ? $data['hidedata'] : '');
- $list = $this->getHidedataList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getIsHotdataTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['is_hotdata']) ? $data['is_hotdata'] : '');
- $list = $this->getIsHotdataList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getIsRecdataTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['is_recdata']) ? $data['is_recdata'] : '');
- $list = $this->getIsRecdataList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public static function lst($where)
- {
- $model = new self;
- $model =$model->where('hidedata',0)->where('status',1);
- if(iset($where['cid']) && $where['cid']>0) $model->where('cid',$where['cid']);
- if(iset($where['is_hot']) && $where['is_hot']==1) $model->where('is_hotdata',$where['is_hot']);
- if(iset($where['is_rec']) && $where['is_rec']==1) $model->where('is_recdata',$where['is_rec']);
- if(iset($where['ifyid']) && $where['ifyid']>0)
- {
- $ids = get_all_categories(ArticleCategory::lst(['cid'=>$where['cid']]));
- $model = $model->wherein('article_category_id',$ids);
- }
- if(iset($where['key']) && $where['key']!='') $model->whereLike('title',"%{$where['key']}%");
- return $model->order('sort desc,releasetime desc')->page($where['page'],$where['limit'])->select()->toArray();
- }
- }
|