HelpCategoryService.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/11/7
  6. * Time: 10:06
  7. */
  8. namespace App\Services\Content;
  9. use App\Repositories\HelpCategoryRepository;
  10. use App\Repositories\HelpRepository;
  11. class HelpCategoryService
  12. {
  13. protected $helpCategoryRepository;
  14. protected $helpRepository;
  15. /**
  16. * HelpCategoryService constructor.
  17. * @param $helpCategoryRepository
  18. */
  19. public function __construct(HelpCategoryRepository $helpCategoryRepository, HelpRepository $helpRepository)
  20. {
  21. $this->helpCategoryRepository = $helpCategoryRepository;
  22. $this->helpRepository = $helpRepository;
  23. }
  24. public function getCategories($where, $limit)
  25. {
  26. $lists = $this->helpCategoryRepository->getCategories($where, $limit);
  27. if ($lists->toArray()) {
  28. //获取大类下的所有help
  29. foreach ($lists as $k => $v) {
  30. $helps = $this->helpRepository->getHelpsByType($v->id);
  31. if ($helps->toArray()) {
  32. $lists[$k]->helps = $helps;
  33. } else {
  34. $lists[$k]->helps = array();
  35. }
  36. }
  37. }
  38. if (array_key_exists('id', $lists)) {
  39. return $lists[0];
  40. } else {
  41. return $lists;
  42. }
  43. }
  44. public function noHelpCategories($where, $limit)
  45. {
  46. $lists = $this->helpCategoryRepository->getCategories($where, $limit);
  47. if (array_key_exists('id', $lists)) {
  48. return $lists[0];
  49. } else {
  50. return $lists;
  51. }
  52. }
  53. public function getOneCategory($where)
  54. {
  55. return $this->helpCategoryRepository->getCategory($where);
  56. }
  57. }