ArticleCategory.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\article;
  12. use crmeb\traits\ModelTrait;
  13. use crmeb\basic\BaseModel;
  14. use think\Model;
  15. /**
  16. * TODO 文章分类Model
  17. * Class ArticleCategory
  18. * @package app\model\article
  19. */
  20. class ArticleCategory extends BaseModel
  21. {
  22. use ModelTrait;
  23. /**
  24. * 数据表主键
  25. * @var string
  26. */
  27. protected $pk = 'id';
  28. /**
  29. * 模型名称
  30. * @var string
  31. */
  32. protected $name = 'article_category';
  33. /**
  34. * 获取子集分类查询条件
  35. * @return \think\model\relation\HasMany
  36. */
  37. public function children()
  38. {
  39. return $this->hasMany(self::class, 'pid', 'id')->where(['hidden' => 0, 'is_del' => 0, 'status' => 1])->order('sort DESC,id DESC')->field('id,pid,title');
  40. }
  41. /**
  42. * 分类状态搜索器
  43. * @param Model $query
  44. * @param $value
  45. * @param $data
  46. */
  47. public function searchStatusAttr($query, $value, $data)
  48. {
  49. if ($value !== '') $query->where('status', $value);
  50. }
  51. /**
  52. * 分类名称搜索器
  53. * @param Model $query
  54. * @param $value
  55. * @param $data
  56. */
  57. public function searchTitleAttr($query, $value, $data)
  58. {
  59. $query->where('title', 'like', '%' . $value . '%');
  60. }
  61. /**
  62. * 隐藏搜索器
  63. * @param Model $query
  64. * @param $value
  65. * @param $data
  66. */
  67. public function searchHiddenAttr($query, $value, $data)
  68. {
  69. $query->where('hidden', $value);
  70. }
  71. /**
  72. * 删除搜索器
  73. * @param Model $query
  74. * @param $value
  75. * @param $data
  76. */
  77. public function searchIsDelAttr($query, $value, $data)
  78. {
  79. $query->where('is_del', $value);
  80. }
  81. /**
  82. * 上级搜索器
  83. * @param $query
  84. * @param $value
  85. */
  86. public function searchPidAttr($query, $value)
  87. {
  88. if ($value !== '') $query->where('pid', $value);
  89. }
  90. }