Article.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\common\model;
  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. $xwhere = null;
  65. $xwhere['hidedata'] = 0;
  66. $xwhere['status'] = 1;
  67. $order = "sort desc,id desc";
  68. if(isset($where['cid']) && $where['cid']>0) $xwhere['cid'] = $where['cid'];
  69. if(isset($where['is_hot']) && $where['is_hot']==1) $xwhere['is_hotdata'] = $where['is_hot'];
  70. if(isset($where['is_rec']) && $where['is_rec']==1) $xwhere['is_recdata'] = $where['is_rec'];
  71. if(isset($where['ifyid']) && $where['ifyid']>0)
  72. {
  73. $ids = get_all_categories(ArticleCategory::lst(['cid'=>$where['cid']]),$where['ifyid']);
  74. $xwhere['article_category_id'] =['in',$ids];
  75. }
  76. if(isset($where['key']) && $where['key']!='') $xwhere['title|synopsis'] = ['like',"%{$where['key']}%"];
  77. if(isset($where['order']) && $where['order']!='') $order = $where['order'];
  78. $list = $model->where($xwhere)->order($order)->page($where['page'],$where['limit'])->select();
  79. $count = $model->where($xwhere)->count();
  80. return compact('count','list');
  81. }
  82. }