Article.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\admin\model\article;
  3. use think\Model;
  4. class Article extends Model
  5. {
  6. // 表名
  7. protected $name = 'article';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'hidedata_text',
  17. 'is_hotdata_text',
  18. 'is_recdata_text',
  19. 'status_text'
  20. ];
  21. public function getHidedataList()
  22. {
  23. return ['0' => __('Hidedata 0'), '1' => __('Hidedata 1')];
  24. }
  25. public function getIsHotdataList()
  26. {
  27. return ['0' => __('Is_hotdata 0'), '1' => __('Is_hotdata 1')];
  28. }
  29. public function getIsRecdataList()
  30. {
  31. return ['0' => __('Is_recdata 0'), '1' => __('Is_recdata 1')];
  32. }
  33. public function getStatusList()
  34. {
  35. return ['0' => __('Status 0'), '1' => __('Status 1')];
  36. }
  37. public function getHidedataTextAttr($value, $data)
  38. {
  39. $value = $value ? $value : (isset($data['hidedata']) ? $data['hidedata'] : '');
  40. $list = $this->getHidedataList();
  41. return isset($list[$value]) ? $list[$value] : '';
  42. }
  43. public function getIsHotdataTextAttr($value, $data)
  44. {
  45. $value = $value ? $value : (isset($data['is_hotdata']) ? $data['is_hotdata'] : '');
  46. $list = $this->getIsHotdataList();
  47. return isset($list[$value]) ? $list[$value] : '';
  48. }
  49. public function getIsRecdataTextAttr($value, $data)
  50. {
  51. $value = $value ? $value : (isset($data['is_recdata']) ? $data['is_recdata'] : '');
  52. $list = $this->getIsRecdataList();
  53. return isset($list[$value]) ? $list[$value] : '';
  54. }
  55. public function getStatusTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  58. $list = $this->getStatusList();
  59. return isset($list[$value]) ? $list[$value] : '';
  60. }
  61. public static function lst($where)
  62. {
  63. $model = new self;
  64. $model =$model->where('hidedata',0)->where('status',1);
  65. if(iset($where['cid']) && $where['cid']>0) $model->where('cid',$where['cid']);
  66. if(iset($where['is_hot']) && $where['is_hot']==1) $model->where('is_hotdata',$where['is_hot']);
  67. if(iset($where['is_rec']) && $where['is_rec']==1) $model->where('is_recdata',$where['is_rec']);
  68. if(iset($where['ifyid']) && $where['ifyid']>0)
  69. {
  70. $ids = get_all_categories(ArticleCategory::lst(['cid'=>$where['cid']]));
  71. $model = $model->wherein('article_category_id',$ids);
  72. }
  73. if(iset($where['key']) && $where['key']!='') $model->whereLike('title',"%{$where['key']}%");
  74. return $model->order('sort desc,releasetime desc')->page($where['page'],$where['limit'])->select()->toArray();
  75. }
  76. }