Category.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. 'block' => __('Block'),
  28. ];
  29. return $typelist;
  30. }
  31. /**
  32. * 读取分类列表
  33. * @param string $type 指定类型
  34. * @param string $status 指定状态
  35. * @return array
  36. */
  37. public static function getCategoryArray($type = NULL, $status = NULL)
  38. {
  39. $list = collection(self::where(function($query) use($type, $status)
  40. {
  41. if (!is_null($type))
  42. {
  43. $query->where('type', '=', $type);
  44. }
  45. if (!is_null($status))
  46. {
  47. $query->where('status', '=', $status);
  48. }
  49. })->order('weigh', 'desc')->select())->toArray();
  50. return $list;
  51. }
  52. }