ResumeService.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. namespace App\Services\Statistics;
  3. use App\Exceptions\ResponseException;
  4. use App\Repositories\ResumeRepository;
  5. use App\Repositories\PersonalJobsApplyRepository;
  6. use App\Repositories\CategoryJobsRepository;
  7. use App\Repositories\MemberInfoRepository;
  8. use Illuminate\Support\Facades\Cache;
  9. class ResumeService
  10. {
  11. protected $resumeRepository;
  12. protected $personalJobsApplyRepository;
  13. protected $categoryJobsRepository;
  14. public function __construct(ResumeRepository $resumeRepository, PersonalJobsApplyRepository $personalJobsApplyRepository, CategoryJobsRepository $categoryJobsRepository)
  15. {
  16. $this->resumeRepository = $resumeRepository;
  17. $this->personalJobsApplyRepository = $personalJobsApplyRepository;
  18. $this->categoryJobsRepository = $categoryJobsRepository;
  19. }
  20. public function getValidResumeNum($where)
  21. {
  22. return $this->resumeRepository->getResumesCount($where);
  23. }
  24. public function getResumeNum($where, $member_where = [])
  25. {
  26. $rst = $this->resumeRepository->getResumeNum($where, $member_where);
  27. return $rst;
  28. }
  29. public function getApplyNumGroup($where, $group_by, $subsite_id)
  30. {
  31. $rst = $this->personalJobsApplyRepository->getApplyNumGroup($where, $group_by, $subsite_id);
  32. return $rst->pluck('count(id)', 'DATE(created_at)')->toArray();
  33. }
  34. public function getApplyNum($where, $company_where)
  35. {
  36. return $this->personalJobsApplyRepository->getApplyNum($where, $company_where);
  37. }
  38. public function getApplyNumByGroup($where, $company_where, $fields, $group_by, $order_by = '')
  39. {
  40. return $this->personalJobsApplyRepository->getApplyNumByGroup($where, $company_where, $fields, $group_by, $order_by);
  41. }
  42. public function getApplyNumByCompanyGroup($where, $company_where, $fields, $group_by, $order_by = '', $limit = '')
  43. {
  44. $rst = $this->personalJobsApplyRepository->getApplyNumByCompanyGroup($where, $company_where, $fields, $group_by, $order_by, $limit);
  45. $list = [];
  46. if ($rst->isNotEmpty()) {
  47. foreach ($rst as $k => $v) {
  48. $list[$k]['count'] = $v->count;
  49. $list[$k]['company_id'] = $v->company_id;
  50. $company = $v->companys;
  51. $list[$k]['company_name'] = $company->companyname;
  52. }
  53. }
  54. return $list;
  55. }
  56. public function getResumeNumGroup($where, $group_by)
  57. {
  58. $rst = $this->resumeRepository->getResumeNumGroup($where, $group_by);
  59. return $rst->pluck('count(id)', 'DATE(created_at)')->toArray();
  60. }
  61. //获取职位分类信息
  62. public function getJobsCategoryInfo()
  63. {
  64. $result = Cache::get('jobs_cate_list');
  65. if (null === $result) {
  66. $result = $this->categoryJobsRepository->jobsCateInfoCache();
  67. Cache::put('jobs_cate_list', $result, '86400');
  68. }
  69. return $result;
  70. }
  71. public function dealJobCategory($data)
  72. {
  73. $cates = $this->getJobsCategoryInfo();
  74. if ($data) {
  75. foreach ($data as $k => $v) {
  76. $cate_ids = explode('.', $v['cate']);
  77. if (array_has($cates['id'], $cate_ids[1])) {
  78. $data[$k]['cate_name'] = $cates['id'][$cate_ids[1]]['name'];
  79. } else {
  80. $data[$k]['cate_name'] = '';
  81. }
  82. }
  83. }
  84. return $data;
  85. }
  86. public function getAvgWageByEducation($where, $member_where, $fields, $group_by, $order_by = '', $limit = '')
  87. {
  88. $rst = $this->resumeRepository->getAvgWageByGroup($where, $member_where, $fields, $group_by, $order_by, $limit);
  89. return $rst->toArray();
  90. }
  91. public function getResumeNumByClass($where, $member_where, $fields, $group_by, $limit = '', $order_by = '')
  92. {
  93. $rst = $this->resumeRepository->getNumByClassGroup($where, $member_where, $fields, $group_by, $limit = '', $order_by = '');
  94. return $rst->pluck('num', 'class')->toArray();
  95. }
  96. public function getResumeNumByClassGroup($where, $member_where, $fields, $group_by, $order_by = '', $limit = '')
  97. {
  98. $top_arr = [];
  99. $second_arr = [];
  100. $top_name_arr = [];
  101. $second_name_arr = [];
  102. $cates = $this->getJobsCategoryInfo();
  103. $cates = $cates['id'];
  104. $rst = $this->resumeRepository->getResumeNumByClassGroup($where, $member_where, $fields, $group_by, $order_by, $limit);
  105. if ($rst) {
  106. $top_arr = $rst['topClass'];
  107. $second_arr = $rst['secondClass'];
  108. }
  109. if ($top_arr && $cates) {
  110. foreach ($top_arr as $k => $v) {
  111. if ($limit && count($top_name_arr) < $limit) {
  112. if (array_has($cates, $k)) {
  113. $top_name_arr[$k] = $cates[$k]['name'];
  114. } else {
  115. $top_name_arr[$k] = '';
  116. }
  117. } else {
  118. break;
  119. }
  120. }
  121. }
  122. if ($second_arr && $cates) {
  123. foreach ($second_arr as $k => $v) {
  124. if ($limit && count($second_name_arr) < $limit) {
  125. if (array_has($cates, $k)) {
  126. $second_name_arr[$k] = $cates[$k]['name'];
  127. } else {
  128. $second_name_arr[$k] = '';
  129. }
  130. } else {
  131. break;
  132. }
  133. }
  134. }
  135. return ['top_arr'=>$top_arr,'second_arr'=>$second_arr,'top_name_arr'=>$top_name_arr,'second_name_arr'=>$second_name_arr];
  136. }
  137. public function getResumeNumsByGroup($where, $member_where, $fields, $group_by, $order_by)
  138. {
  139. $rst = $this->resumeRepository->getAvgWageByGroup($where, $member_where, $fields, $group_by, $order_by);
  140. return $rst->pluck('num', 'create_month')->toArray();
  141. }
  142. public function getResumeNumsGroup($where, $member_where, $fields, $group_by, $order_by = '')
  143. {
  144. $rst = $this->resumeRepository->getAvgWageByGroup($where, $member_where, $fields, $group_by, $order_by);
  145. return $rst;
  146. }
  147. public function getResumeNumsByEducationGroup($start_time, $end_time, $subsite_id)
  148. {
  149. $resume_where = [
  150. ['r.created_at', '<=', $end_time],
  151. ['r.created_at', '>=', $start_time],
  152. ];
  153. if (config('aix.personal_set.per_set.show_set.resume_display')=='1') {
  154. $resume_where[] = array('r.audit','=','2');
  155. } else {
  156. $resume_where[] = array('r.audit','<>','0');
  157. }
  158. $member_where = array(
  159. ['m.utype','=',2],
  160. ['m.status','=',1]
  161. );
  162. if ($subsite_id != -1) {
  163. $member_where[] = ['m.subsite_id','=',$subsite_id];
  164. }
  165. $resume_fields = 'count(r.id) as num, mu.education';
  166. $where = "r.deleted_at is null and m.deleted_at is null";
  167. $rst = $this->resumeRepository->getResumeNumByEducationGroup($where, $resume_where, $member_where, $resume_fields, 'mu.education', 'mu.education asc');
  168. return $rst->pluck('num', 'education')->toArray();
  169. }
  170. public function getResumeNumsByAgeGroup($subsite_id, $start_time, $end_time, $ages, $age_text)
  171. {
  172. //简历查询条件
  173. $resume_where = [
  174. ['r.created_at', '<=', $end_time],
  175. ['r.created_at', '>=', $start_time],
  176. ];
  177. if (config('aix.personal_set.per_set.show_set.resume_display')=='1') {
  178. $resume_where[] = array('r.audit','=','2');
  179. } else {
  180. $resume_where[] = array('r.audit','<>','0');
  181. }
  182. $member_where = array(
  183. ['m.utype','=',2],
  184. ['m.status','=',1]
  185. );
  186. if ($subsite_id != -1) {
  187. $member_where[] = ['m.subsite_id','=',$subsite_id];
  188. }
  189. $where = "r.deleted_at is null and m.deleted_at is null AND mu.deleted_at is null";
  190. $resume_fields = 'count(r.id) as num, mu.birthday';
  191. $group = '';
  192. $age_data = [];
  193. foreach ($ages as $k => $v) {
  194. $map = [];
  195. $max_birth = date('Y') - $v['min_age'];
  196. $min_birth = 0;
  197. if ($v['max_age']) {
  198. $min_birth = date('Y') - $v['max_age'];
  199. }
  200. $map[] = ['mu.birthday', '<=', $max_birth];
  201. if ($min_birth && $max_birth) {
  202. $map[] = ['mu.birthday', '>=', $min_birth];
  203. }
  204. $resume_count = $this->resumeRepository->getResumeNumsByAgeGroup($where, $resume_where, $member_where, $map, $resume_fields, $group);
  205. $age_data[$age_text[$k]] = $resume_count;
  206. }
  207. return $age_data;
  208. }
  209. public function getResumeApplyGroup($where, $order_fileds, $apply_group, $apply_order, $limit = '')
  210. {
  211. return $this->personalJobsApplyRepository->getResumeApplyGroup($where, $order_fileds, $apply_group, $apply_order, $limit);
  212. }
  213. public function getResumeBySexGroup($subsite_id, $start_time, $end_time)
  214. {
  215. //简历查询条件
  216. $resume_where = array();
  217. if (config('aix.personal_set.per_set.show_set.resume_display')=='1') {
  218. $resume_where[] = array('r.audit','=','2');
  219. } else {
  220. $resume_where[] = array('r.audit','<>','0');
  221. }
  222. $resume_where[] = ['r.created_at','>=',$start_time];
  223. $resume_where[] = ['r.created_at','<=',$end_time];
  224. $member_where = array(array('m.utype','2',1),);
  225. if ($subsite_id != -1) {
  226. $member_where[] = array('m.subsite_id','=',$subsite_id);
  227. }
  228. $info_where = [];
  229. $field = 'count(r.id) as num, mu.sex,if (mu.sex=1,"男","女") as sex_cn';
  230. $group = 'mu.sex';
  231. $rst = $this->resumeRepository->getResumeNumByGroup($resume_where, $member_where, $info_where, $field, $group);
  232. return $rst;
  233. }
  234. }