PageCategoryServices.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. declare (strict_types=1);
  12. namespace app\services\diy;
  13. use app\services\BaseServices;
  14. use app\dao\diy\PageCategoryDao;
  15. use crmeb\services\CacheService;
  16. /**
  17. * Class PageCategoryServices
  18. * @package app\services\diy
  19. */
  20. class PageCategoryServices extends BaseServices
  21. {
  22. protected $tree_page_category_key = 'tree_page_categroy';
  23. /**
  24. * PageCategoryServices constructor.
  25. * @param PageCategoryDao $dao
  26. */
  27. public function __construct(PageCategoryDao $dao)
  28. {
  29. $this->dao = $dao;
  30. }
  31. /**
  32. * 获取分类列表
  33. * @return bool|mixed|null
  34. */
  35. public function getCategroyList()
  36. {
  37. return CacheService::remember($this->tree_page_category_key, function () {
  38. return $this->getSonCategoryList();
  39. }, 86400);
  40. }
  41. /**
  42. * tree分类列表
  43. * @param int $pid
  44. * @param string $parent_name
  45. * @return array
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. */
  50. public function getSonCategoryList($pid = 0)
  51. {
  52. $list = $this->dao->getList(['pid' => $pid], 'id,pid,type,name');
  53. $arr = [];
  54. if ($list) {
  55. foreach ($list as $item) {
  56. $item['title'] = $item['name'];
  57. $item['expand'] = true;
  58. $item['children'] = $this->getSonCategoryList($item['id']);
  59. $arr [] = $item;
  60. }
  61. }
  62. return $arr;
  63. }
  64. }