CompanyService.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Services\Statistics;
  3. use App\Exceptions\ResponseException;
  4. use App\Repositories\CompanyRepository;
  5. use App\Repositories\CategoryRepository;
  6. use Illuminate\Support\Facades\Cache;
  7. class CompanyService
  8. {
  9. protected $companyRepository;
  10. protected $categoryRepository;
  11. /**
  12. * CompanyService constructor.
  13. */
  14. public function __construct(CompanyRepository $companyRepository, CategoryRepository $categoryRepository)
  15. {
  16. $this->companyRepository = $companyRepository;
  17. $this->categoryRepository = $categoryRepository;
  18. }
  19. //获取指定条件的企业数量
  20. public function getCompanyNums($where)
  21. {
  22. $time_condition = [];
  23. if (array_has($where, 'time_condition')) {
  24. $time_condition = $where['time_condition'];
  25. unset($where['time_condition']);
  26. }
  27. return $this->companyRepository->getCompanyNumByTime($where, $time_condition);
  28. }
  29. public function getCategories($filter_data = array())
  30. {
  31. $list = array();
  32. if ($filter_data) {
  33. $cates = $this->categoryRepository->getCategories();
  34. if ($cates) {
  35. foreach ($cates as $key => $val) {
  36. if ($key == 'AIX_wage') {
  37. foreach ($val as $k => $v) {
  38. if (config('aix.system.site_other.site_other.site_salary') == 1) {
  39. $cates[$key][$k]['demand'] = $v['k_demand'];
  40. } else {
  41. $cates[$key][$k]['demand'] = $v['c_demand'];
  42. }
  43. }
  44. }
  45. }
  46. }
  47. foreach ($filter_data as $k => $v) {
  48. if (array_key_exists($k, $cates)) {
  49. $list[$k] = array_slice($cates[$k], 0, 3);
  50. if ($v) {
  51. $list[$k] = array_slice($cates[$k], 0, $v, true);
  52. } else {
  53. $list[$k] = $cates[$k];
  54. }
  55. } else {
  56. $list[$k] = array();
  57. }
  58. }
  59. }
  60. return $list;
  61. }
  62. public function getCompanyNumsGroup($where, $fields, $group_by)
  63. {
  64. $rst = $this->companyRepository->getCompanyNumsByGroup($where, $fields, $group_by);
  65. return $rst->toArray();
  66. }
  67. }