Category.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. /**
  5. * 分类模型
  6. */
  7. class Category Extends Model
  8. {
  9. // 开启自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. // 定义字段类型
  15. protected $type = [
  16. ];
  17. /**
  18. * 读取分类类型
  19. * @return array
  20. */
  21. public static function getTypeList()
  22. {
  23. $typelist = [
  24. 'default' => __('Default'),
  25. 'page' => __('Page'),
  26. 'article' => __('Article'),
  27. ];
  28. return $typelist;
  29. }
  30. /**
  31. * 读取分类列表
  32. * @param string $type 指定类型
  33. * @param string $status 指定状态
  34. * @return array
  35. */
  36. public static function getCategoryArray($type = NULL, $status = NULL)
  37. {
  38. $list = collection(self::where(function($query) use($type, $status)
  39. {
  40. if (!is_null($type))
  41. {
  42. $query->where('type', '=', $type);
  43. }
  44. if (!is_null($status))
  45. {
  46. $query->where('status', '=', $status);
  47. }
  48. })->order('weigh', 'desc')->select())->toArray();
  49. return $list;
  50. }
  51. }