DataDownloadCategpry.php 3.2 KB

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