SpecialSubject.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\special;
  12. use basic\ModelBasic;
  13. use traits\ModelTrait;
  14. /**专题分类
  15. * Class SpecialSubject
  16. * @package app\wap\model\special
  17. */
  18. class SpecialSubject extends ModelBasic
  19. {
  20. use ModelTrait;
  21. /**获取二级分类
  22. * @return \think\model\relation\HasMany
  23. */
  24. public function children()
  25. {
  26. return $this->hasMany('SpecialSubject', 'grade_id', 'id')->where(['is_del' => 0, 'is_show' => 1])->order('sort DESC,id DESC');
  27. }
  28. /**获取全部分类
  29. * @param int $type
  30. * @return array|false|\PDOStatement|string|\think\Collection
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. * @throws \think\exception\DbException
  34. */
  35. public static function wapSpecialCategoryAll($type = 0)
  36. {
  37. $model = self::where(['is_del' => 0, 'is_show' => 1]);
  38. if ($type == 1) {
  39. $model = $model->where('grade_id', 0);
  40. }
  41. $list = $model->order('sort desc,add_time desc')->field('id,name')->select();
  42. $list = count($list) > 0 ? $list->toArray() : [];
  43. return $list;
  44. }
  45. /**获取一级分类下的所以二级分类
  46. * @param int $grade_id
  47. */
  48. public static function subjectId($grade_id = 0)
  49. {
  50. return self::where(['is_del' => 0, 'is_show' => 1, 'grade_id' => $grade_id])->order('sort desc,add_time desc')->column('id');
  51. }
  52. }