ArticleCategoryController.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\v1\publics;
  12. use app\services\article\ArticleCategoryServices;
  13. use crmeb\services\CacheService;
  14. /**
  15. * 文章分类类
  16. * Class ArticleCategoryController
  17. * @package app\controller\api\publics
  18. */
  19. class ArticleCategoryController
  20. {
  21. protected $services;
  22. public function __construct(ArticleCategoryServices $services)
  23. {
  24. $this->services = $services;
  25. }
  26. /**
  27. * 文章分类列表
  28. * @return mixed
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. * @throws \think\exception\DbException
  32. */
  33. public function lst()
  34. {
  35. $cateInfo = CacheService::get('ARTICLE_CATEGORY', function () {
  36. $cateInfo = $this->services->getArticleCategory();
  37. array_unshift($cateInfo, ['id' => 0, 'title' => '热门']);
  38. return $cateInfo;
  39. });
  40. return app('json')->successful($cateInfo);
  41. }
  42. }