TeacherCategpry.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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\admin\model\educational;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use service\UtilService as Util;
  15. use app\admin\model\educational\Teacher;
  16. /**
  17. * 老师分类 Model
  18. * Class TeacherCategpry
  19. * @package app\admin\model\educational
  20. */
  21. class TeacherCategpry extends ModelBasic
  22. {
  23. use ModelTrait;
  24. /**
  25. * 全部老师分类
  26. */
  27. public static function taskCategoryAll($type = 0)
  28. {
  29. $model = self::where('is_del', 0);
  30. if ($type == 1) {
  31. $model = $model->where('pid', 0);
  32. }
  33. $list = $model->order('sort desc,add_time desc')->select();
  34. $list = count($list) > 0 ? $list->toArray() : [];
  35. $list = Util::sortListTier($list);
  36. return $list;
  37. }
  38. /**
  39. * 老师分类列表
  40. */
  41. public static function getAllList($where)
  42. {
  43. $data = self::setWhere($where)->column('id,pid');
  44. $list = [];
  45. foreach ($data as $ket => $item) {
  46. $cate = self::where('id', $ket)->find();
  47. if ($cate) {
  48. $cate = $cate->toArray();
  49. if ($item > 0) {
  50. $cate['sum'] = Teacher::where('is_del', 0)->where('pid', $ket)->count();
  51. } else {
  52. $pids = self::categoryId($ket);
  53. $cate['sum'] = Teacher::where('is_del', 0)->where('pid', 'in', $pids)->count();
  54. }
  55. array_push($list, $cate);
  56. unset($cate);
  57. }
  58. if ($item > 0 && !array_key_exists($item, $data)) {
  59. $cate = self::where('id', $item)->find();
  60. if ($cate) {
  61. $cate = $cate->toArray();
  62. $pids = self::categoryId($item);
  63. $cate['sum'] = Teacher::where('is_del', 0)->where('pid', 'in', $pids)->count();
  64. array_push($list, $cate);
  65. }
  66. unset($cate);
  67. }
  68. }
  69. return $list;
  70. }
  71. public static function setWhere($where)
  72. {
  73. $model = self::order('sort desc,add_time desc')->where('is_del', 0);
  74. if ($where['pid']) $model = $model->where('id', $where['pid']);
  75. if ($where['title'] != '') $model = $model->where('title', 'like', "%$where[title]%");
  76. return $model;
  77. }
  78. /**获取一个分类下的所有分类ID
  79. * @param int $pid
  80. */
  81. public static function categoryId($pid = 0)
  82. {
  83. $data = self::where('is_del', 0)->where('pid', $pid)->column('id');
  84. array_push($data, $pid);
  85. return $data;
  86. }
  87. }