JobfairController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php
  2. namespace App\Http\Controllers\Statistics;
  3. use App\Http\Controllers\Statistics\StatisticsBaseController;
  4. use Illuminate\Http\Request;
  5. use App\Services\Statistics\CompanyService;
  6. use App\Services\Statistics\ResumeService;
  7. use App\Services\Statistics\JobfairService;
  8. use App\Services\Statistics\JobsService;
  9. use App\Services\Statistics\CategoryService;
  10. class JobfairController extends StatisticsBaseController
  11. {
  12. protected $resumeService;
  13. protected $jobfairService;
  14. protected $companyService;
  15. protected $jobsService;
  16. protected $categoryService;
  17. /**
  18. * DemandController constructor.
  19. */
  20. public function __construct(JobfairService $jobfairService, ResumeService $resumeService, CompanyService $companyService, JobsService $jobsService, CategoryService $categoryService)
  21. {
  22. $this->jobfairService = $jobfairService;
  23. $this->resumeService = $resumeService;
  24. $this->companyService = $companyService;
  25. $this->jobsService = $jobsService;
  26. $this->categoryService = $categoryService;
  27. }
  28. public function index(Request $request)
  29. {
  30. $subsite_id = session('caiqing_susbite_id');
  31. if ($subsite_id === null) {
  32. $subsite_id = -1;
  33. }
  34. //时间过滤
  35. $date_aprams = $this->getDateDetail($request->all());
  36. $start_time = $date_aprams['start_date']?date('Y-m-d H:i:s', strtotime($date_aprams['start_date'])):$date_aprams['start_date'];
  37. $end_time = date('Y-m-d H:i:s', strtotime($date_aprams['end_date'].' +1 day')-1);
  38. //举办结束时间在当前时间段中的所有招聘会
  39. if ($subsite_id != -1) {
  40. $jobfairs_where[] = ['subsite_id','=',$subsite_id];
  41. }
  42. $jobfairs_where[] = ['holddate_end','>=',strtotime($start_time)];
  43. $jobfairs_where[] = ['holddate_end','<=',strtotime($end_time)];
  44. $jobfair_ids = $this->jobfairService->getJobfairIds($jobfairs_where);
  45. //招聘企业数 - 举办结束时间在当前时间段中的所有招聘会的所有审核通过的企业数量
  46. //$jobfair_company_where = ['audit'=>1];
  47. $jobfair_company_where = [['audit','<>',3]];
  48. $company_nums = $this->jobfairService->getCompanyCount($jobfair_company_where, ['jobfair_id'=>$jobfair_ids]);
  49. //招聘岗位数 - 举办结束时间在当前时间段中的所有招聘会的所有审核通过的职位数量
  50. if (config('aix.companyset.comset.show_set.jobs_display')==1) {
  51. $job_where[] = array('audit','=',1);
  52. } else {
  53. $job_where[] = array('audit','<>',3);
  54. }
  55. $jobs_nums = $this->jobfairService->getJobsCount($job_where, ['jobfair_id'=>$jobfair_ids]);
  56. //招聘会需求总数
  57. $jobs_amounts = $this->jobfairService->getJobsAmount($job_where, ['jobfair_id'=>$jobfair_ids]);
  58. //统计招聘会进场个人用户信息(一个个人用户同一场招聘会进出多次统计成一次)
  59. //性别分布
  60. $sex_arr = $this->getPersonSexNums($jobfair_ids);
  61. //学历分布(统计有学历信息的数据)
  62. $edu_arr = $this->getPersonEducationNums($jobfair_ids);
  63. //年龄分布 - 后台读取年龄分类
  64. $wage_cates = $this->categoryService->getCategories(['AIX_age'=>100]);
  65. $age_names = [];
  66. if (array_has($wage_cates, 'AIX_age') && $wage_cates['AIX_age']) {
  67. foreach ($wage_cates['AIX_age'] as $k => $v) {
  68. $age_names[] = $v['demand'];
  69. }
  70. }
  71. $age_data = [];
  72. foreach ($age_names as $k => $v) {
  73. $age_arr = explode('-', $v);
  74. $max_age = 0;
  75. $min_age = 0;
  76. if (count($age_arr) == 1 && stristr($v, '以下')) {
  77. $max_age = (int)$age_arr[0];
  78. } else {
  79. $min_age = (int)$age_arr[0];
  80. }
  81. if (array_has($age_arr, 1)) {
  82. $max_age = (int)$age_arr[1];
  83. }
  84. if ($min_age>0 && $max_age>0) {
  85. $age_num = $this->getPersonAgeNums([date('Y')-$max_age,date('Y')-$min_age], $jobfair_ids);
  86. } elseif ($min_age==0 && $max_age>0) {
  87. $age_num = $this->getPersonAgeNums([date('Y')-$max_age, 0], $jobfair_ids);
  88. } elseif ($min_age>0 && $max_age==0) {
  89. $age_num = $this->getPersonAgeNums([0, date('Y')-$min_age], $jobfair_ids);
  90. }
  91. $age_data[$v] = $age_num;
  92. }
  93. //详细数据-职位大类top10 需求人数+求职人数 按需求人数排序
  94. $topclass_data = $this->jobsService->getJobsTopclass($job_where, ['jobfair_id'=>$jobfair_ids], 'sum(amount) as num, topclass', ['topclass'], 'sum(amount) desc', 10);
  95. //获取求职登记人数
  96. $member_where = [
  97. ['utype','=',2],
  98. ['status','=',1],
  99. ['created_at','>=',$start_time],
  100. ['created_at','<=',$end_time]
  101. ];
  102. if ($subsite_id !='-1') {
  103. $member_where[] = ['subsite_id','=',$subsite_id];
  104. }
  105. $resume_where = [];
  106. if (config('aix.personal_set.per_set.show_set.resume_display')=='1') {
  107. $resume_where[] = array('audit','=','2');
  108. } else {
  109. $resume_where[] = array('audit','<>','0');
  110. }
  111. $resume_fields = "count(id) as num,substring_index(intention_jobs_id,'.',1) as class";
  112. $resume_group = "class";
  113. $personal_nums = $this->resumeService->getResumeNumByClass($resume_where, $member_where, $resume_fields, $resume_group);
  114. if ($topclass_data) {
  115. $i =1;
  116. foreach ($topclass_data as $k => $v) {
  117. if (array_has($personal_nums, $k)) {
  118. $topclass_data[$k]['resume_num'] = $personal_nums[$k];
  119. } else {
  120. $topclass_data[$k]['resume_num'] = 0;
  121. }
  122. $topclass_data[$k]['order'] = $i;
  123. $i++;
  124. }
  125. }
  126. $return_data = [
  127. 'date_aprams' => $date_aprams,
  128. 'action_name' => app('request')->route()->getName(),
  129. 'jobfair_num' => count($jobfair_ids),
  130. 'company_nums' => $company_nums,
  131. 'jobs_nums' => $jobs_nums,
  132. 'jobs_amounts' => $jobs_amounts,
  133. 'sex_arr' => $sex_arr,
  134. 'edu_arr' => $edu_arr,
  135. 'age_data' => $age_data,
  136. 'topclass_data' => $topclass_data
  137. ];
  138. return view('statistics.app.jobfair.index', $return_data);
  139. }
  140. public function getPersonEducationNums($jobfair_ids)
  141. {
  142. //获取uid>0的学历信息
  143. $where = [
  144. ['s.type','=',1],
  145. ['s.uid','>',0]
  146. ];
  147. $field = 's.uid,s.jobfairid,s.sex,s.idcard,m.education,m.education_cn';
  148. $edu_rst1 = $this->jobfairService->getSignPersonEducations('uid', $where, ['s.jobfairid'=>$jobfair_ids], ['s.jobfairid', 's.uid'], $field);
  149. $data1 = $edu_rst1->groupBy('education')->toArray();
  150. $education_data = [];
  151. if ($data1) {
  152. foreach ($data1 as $k => $v) {
  153. $education_data[$k] = count($v);
  154. }
  155. }
  156. //获取uid=0,idcard注册过简历的用户的学历分组信息
  157. $where2 = [
  158. ['s.type','=',1],
  159. ['s.uid','=',0]
  160. ];
  161. $field2 = 's.uid,s.jobfairid,s.sex,s.idcard,m.education,m.education_cn';
  162. $edu_rst2 = $this->jobfairService->getSignPersonEducations('idcard', $where2, ['s.jobfairid'=>$jobfair_ids], ['s.jobfairid', 's.idcard'], $field);
  163. $data2 = $edu_rst2->groupBy('education')->toArray();
  164. if ($data1) {
  165. foreach ($data2 as $k => $v) {
  166. $k = (int)$k;
  167. if (array_has($education_data, $k)) {
  168. $education_data[$k] = count($v) + (int)$education_data[$k];
  169. } else {
  170. $education_data[$k] = count($v);
  171. }
  172. }
  173. }
  174. //获取学历名称
  175. $cate_filter = ['AIX_education'=>100];
  176. $cates = $this->companyService->getCategories($cate_filter);
  177. $edu_arr = [];
  178. foreach ($cates['AIX_education'] as $k => $v) {
  179. $edu_arr[$v['id']] = ['name'=>$v['demand']];
  180. if ($education_data && array_has($education_data, $v['id'])) {
  181. $edu_arr[$v['id']]['value'] = $education_data[$v['id']];
  182. } else {
  183. $edu_arr[$v['id']]['value'] = 0;
  184. }
  185. }
  186. $edu_arr['0'] = ['name'=>'无学历信息', 'value'=>array_has($education_data, '0')?$education_data[0]:0];
  187. return $edu_arr;
  188. }
  189. public function getPersonSexNums($jobfair_ids)
  190. {
  191. $sex_rst1 = $this->jobfairService->getPersonNums([['uid','>',0],['type','=',1]], ['jobfairid'=>$jobfair_ids], ['jobfairid', 'uid']);
  192. $sex_group = $sex_rst1->groupBy('sex');
  193. $sex_data = [];
  194. if ($sex_group) {
  195. foreach ($sex_group as $k => $v) {
  196. $val = $v->toArray();
  197. $sex_data[$val[0]['sex']] = $v->count();
  198. }
  199. }
  200. //2.统计uid=0,idcard有值的次数
  201. $sex_rst2 = $this->jobfairService->getPersonNums([['uid','=',0],['type','=',1]], ['jobfairid'=>$jobfair_ids], ['jobfairid', 'idcard']);
  202. $sex_group2 = $sex_rst2->groupBy('sex');
  203. if ($sex_group2) {
  204. foreach ($sex_group2 as $k => $v) {
  205. $val = $v->toArray();
  206. if (array_has($sex_data, $val[0]['sex'])) {
  207. $sex_data[$val[0]['sex']] = $v->count() + (int)$sex_data[$val[0]['sex']];
  208. } else {
  209. $sex_data[$val[0]['sex']] = $v->count();
  210. }
  211. }
  212. }
  213. $sex_name = ['男', '女'];
  214. $sex_arr['男'] = array_has($sex_data, '1')?$sex_data['1']:0;
  215. $sex_arr['女'] = array_has($sex_data, '2')?$sex_data['2']:0;
  216. return $sex_arr;
  217. }
  218. public function getPersonAgeNums($age_arr, $jobfair_ids)
  219. {
  220. $min_age = $age_arr[0];
  221. $max_age = $age_arr[1];
  222. if ($max_age>0 && $min_age>0) {
  223. $age_where1[] = ['birthday', '>=', $min_age];
  224. $age_where1[] = ['birthday', '<=', $max_age];
  225. } elseif ($max_age==0) {
  226. $age_where1[] = ['birthday', '>=', $min_age];
  227. } elseif ($min_age ==0) {
  228. $age_where1[] = ['birthday', '<=', $max_age];
  229. }
  230. $age_where1[] = ['uid', '>', '0'];
  231. $age_where1[] = ['type','=',1];
  232. $age_rst1 = $this->jobfairService->getPersonNums($age_where1, ['jobfairid'=>$jobfair_ids], ['jobfairid', 'uid'])->count();
  233. if ($max_age>0 && $min_age>0) {
  234. $age_where2[] = ['birthday', '>=', $min_age];
  235. $age_where2[] = ['birthday', '<=', $max_age];
  236. } elseif ($max_age==0) {
  237. $age_where2[] = ['birthday', '>=', $min_age];
  238. } elseif ($min_age ==0) {
  239. $age_where2[] = ['birthday', '<=', $max_age];
  240. }
  241. $age_where2[] = ['uid', '=', '0'];
  242. $age_where2[] = ['type','=',1];
  243. $age_rst2 = $this->jobfairService->getPersonNums($age_where2, ['jobfairid'=>$jobfair_ids], ['jobfairid', 'idcard'])->count();
  244. $total_num = (int)$age_rst1 + (int)$age_rst2;
  245. return $total_num;
  246. }
  247. }