ArticleCategory.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class ArticleCategory extends Model
  5. {
  6. // 表名
  7. protected $name = 'article_category';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'status_text',
  17. 'hidden_text'
  18. ];
  19. public function getStatusList()
  20. {
  21. return ['0' => __('Status 0'), '1' => __('Status 1')];
  22. }
  23. public function getHiddenList()
  24. {
  25. return ['0' => __('Hidden 0'), '1' => __('Hidden 1')];
  26. }
  27. public function getStatusTextAttr($value, $data)
  28. {
  29. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  30. $list = $this->getStatusList();
  31. return isset($list[$value]) ? $list[$value] : '';
  32. }
  33. public function getHiddenTextAttr($value, $data)
  34. {
  35. $value = $value ? $value : (isset($data['hidden']) ? $data['hidden'] : '');
  36. $list = $this->getHiddenList();
  37. return isset($list[$value]) ? $list[$value] : '';
  38. }
  39. public static function lst($where)
  40. {
  41. $model = new self;
  42. $model =$model->where('hidden',0)->where('status',1);
  43. if(isset($where['cid']) && $where['cid']>0) $model->where('cid',$where['cid']);
  44. if(isset($where['pid']) && $where['pid']>0) $model->where('pid',$where['pid']);
  45. return $model->order("sort desc,id asc")->select();
  46. }
  47. }