CategoryService.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Services\Statistics;
  3. use App\Repositories\CategoryRepository;
  4. use App\Repositories\CategoryDistrictRepository;
  5. use Illuminate\Support\Facades\Cache;
  6. use Illuminate\Support\Facades\DB;
  7. class CategoryService
  8. {
  9. protected $categoryRepository;
  10. protected $categoryDistrictRepository;
  11. /**
  12. * CategoryService constructor.
  13. */
  14. public function __construct(CategoryRepository $categoryRepository, CategoryDistrictRepository $categoryDistrictRepository)
  15. {
  16. $this->categoryRepository = $categoryRepository;
  17. $this->categoryDistrictRepository = $categoryDistrictRepository;
  18. }
  19. public function getDistricts()
  20. {
  21. return $this->categoryDistrictRepository->getAllDistricts();
  22. }
  23. public function getCategories($filter_data = array())
  24. {
  25. $list = array();
  26. if ($filter_data) {
  27. $cates = $this->categoryRepository->getCategories();
  28. if ($cates) {
  29. foreach ($cates as $key => $val) {
  30. if ($key == 'AIX_wage') {
  31. foreach ($val as $k => $v) {
  32. if (config('aix.system.site_other.site_other.site_salary') == 1) {
  33. $cates[$key][$k]['demand'] = $v['k_demand'];
  34. } else {
  35. $cates[$key][$k]['demand'] = $v['c_demand'];
  36. }
  37. }
  38. }
  39. }
  40. }
  41. foreach ($filter_data as $k => $v) {
  42. if (array_key_exists($k, $cates)) {
  43. $list[$k] = array_slice($cates[$k], 0, 3);
  44. if ($v) {
  45. $list[$k] = array_slice($cates[$k], 0, $v, true);
  46. } else {
  47. $list[$k] = $cates[$k];
  48. }
  49. } else {
  50. $list[$k] = array();
  51. }
  52. }
  53. }
  54. return $list;
  55. }
  56. }