Category.php 1.2 KB

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