CategoryService.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. <?php
  2. namespace App\Services\Common;
  3. use App\Models\CategoryJobs;
  4. use App\Repositories\CategoryDistrictRepository;
  5. use App\Repositories\CategoryGroupRepository;
  6. use App\Repositories\CategoryJobsRepository;
  7. use App\Repositories\CategoryMajorRepository;
  8. use App\Repositories\CategoryRepository;
  9. use Illuminate\Support\Facades\Cache;
  10. use Illuminate\Support\Facades\DB;
  11. class CategoryService
  12. {
  13. /**
  14. * @var CategoryMajorRepository
  15. */
  16. protected $CategoryMajorRepository;
  17. protected $CategoryJobsRepository;
  18. protected $CategoryDistrictRepository;
  19. protected $CategoryGroupRepository;
  20. protected $CategoryRepository;
  21. const DEFAULT_CITY = '9.107';
  22. const DIS_CITY = '9.107.1119';
  23. const DIS_HAN = '黄浦区';
  24. /**
  25. * CategoryService constructor.
  26. * @param CategoryMajorRepository $CategoryMajorRepository
  27. * @param CategoryJobsRepository $CategoryJobsRepository
  28. * @param CategoryDistrictRepository $CategoryDistrictRepository
  29. * @param CategoryGroupRepository $CategoryGroupRepository
  30. * @param CategoryRepository $CategoryRepository
  31. */
  32. public function __construct(CategoryMajorRepository $CategoryMajorRepository, CategoryJobsRepository $CategoryJobsRepository, CategoryDistrictRepository $CategoryDistrictRepository, CategoryGroupRepository $CategoryGroupRepository, CategoryRepository $CategoryRepository)
  33. {
  34. $this->CategoryMajorRepository = $CategoryMajorRepository;
  35. $this->CategoryJobsRepository = $CategoryJobsRepository;
  36. $this->CategoryDistrictRepository = $CategoryDistrictRepository;
  37. $this->CategoryGroupRepository = $CategoryGroupRepository;
  38. $this->CategoryRepository = $CategoryRepository;
  39. }
  40. /**
  41. * 获取专业--职位--地区--其他信息。
  42. */
  43. public function getCategory()
  44. {
  45. if (Cache::has('aix_category')) {
  46. return Cache::get('aix_category');
  47. } else {
  48. /**
  49. * 专业
  50. */
  51. $major = $this->CategoryMajorRepository->getCategoryById();
  52. $major_V = [];
  53. foreach ($major as $k => $v) {
  54. $major_V[] = $v['id'].','.$v['name'];
  55. }
  56. $major_par = [];
  57. foreach ($major as $key => $val) {
  58. $major_list = $this->CategoryMajorRepository->getCategoryById($val['id']);
  59. $imp = [];
  60. foreach ($major_list as $key1 => $val1) {
  61. $imp[] = implode(',', $val1);
  62. }
  63. $major_par[$val['id']] = implode('`', $imp);
  64. }
  65. /**
  66. * 职位信息
  67. */
  68. $jobs = $this->CategoryJobsRepository->getCategoryById();
  69. $jobs_V = [];
  70. foreach ($jobs as $k => $v) {
  71. $jobs_V[] = $v['id'].','.$v['name'];
  72. }
  73. $jobs_par = [];
  74. foreach ($jobs as $key => $val) {
  75. $jobs_list = $this->CategoryJobsRepository->getCategoryById($val['id']);
  76. $kl = [];
  77. foreach ($jobs_list as $key1 => $val1) {
  78. $arr = explode(',', implode(',', $val1));
  79. $kl[] = $arr[0].','.$arr[1];
  80. $jobs_k = $this->CategoryJobsRepository->getCategoryById($val1['id']);
  81. $kmd = [];
  82. foreach ($jobs_k as $key2 => $val2) {
  83. $kmd[] = implode(',', $val2);
  84. }
  85. $jobs_par[$val1['id']] = implode('`', $kmd);
  86. }
  87. $jobs_par[$val['id']] = implode('`', $kl);
  88. }
  89. /**
  90. * 地区信息。
  91. */
  92. $district = $this->CategoryDistrictRepository->getCategoryById();
  93. $district_V = [];
  94. $district_s = [];
  95. foreach ($district as $k => $v) {
  96. $district_V[] = $v['id'].','.$v['name'];
  97. $district_s[] = $v['spell'].','.$v['name'];
  98. }
  99. $district_par = [];
  100. $district_par_person = [];
  101. foreach ($district as $key => $val) {
  102. $district_list = $this->CategoryDistrictRepository->getCategoryById($val['id']);
  103. $kl = [];
  104. foreach ($district_list as $key1 => $val1) {
  105. $arr = explode(',', implode(',', $val1));
  106. $kl[] = $arr[0].','.$arr[1];
  107. $district_k = $this->CategoryDistrictRepository->getCategoryById($val1['id']);
  108. $kmd = [];
  109. $kmd_person = [];
  110. foreach ($district_k as $key2 => $val2) {
  111. $kmd[] = implode(',', $val2);
  112. $kmd_person[] = implode(',', $val2);
  113. }
  114. array_unshift($kmd, '0,不限,'.$val1['id'].',buxian');
  115. $district_par[$val1['id']] = implode('`', $kmd);
  116. $district_par_person[$val1['id']] = implode('`', $kmd_person);
  117. }
  118. $district_par[$val['id']] = implode('`', $kl);
  119. $district_par_person[$val['id']] = implode('`', $kl);
  120. }
  121. /**
  122. * 其他信息。
  123. */
  124. $Groups = $this->CategoryGroupRepository->getCategoryGroup();
  125. $Groups_arr = array_column($Groups, 'alias');
  126. $category = $this->CategoryRepository->getCategoryInfo($Groups_arr);
  127. $category_V = [];
  128. foreach ($Groups_arr as $k => $v) {
  129. foreach ($category as $k1 => $v1) {
  130. if ($v==$v1['alias']) {
  131. $category_V[$v][] = $v1['id'].','.$v1['demand'];
  132. }
  133. }
  134. }
  135. Cache::put('aix_category', ['major'=>['first'=>$major_V,'sec'=>$major_par],'jobs'=>['first'=>$jobs_V,'sec'=>$jobs_par],'district'=>['first'=>$district_V,'sec'=>$district_par_person,'spell'=>$district_s,'person'=>$district_par],'other'=>$category_V], 86400);
  136. return ['major'=>['first'=>$major_V,'sec'=>$major_par],'jobs'=>['first'=>$jobs_V,'sec'=>$jobs_par],'district'=>['first'=>$district_V,'sec'=>$district_par_person,'spell'=>$district_s,'person'=>$district_par],'other'=>$category_V];
  137. }
  138. }
  139. /**
  140. * 根据行业获取分类。
  141. */
  142. public function getCategoryByTrade($trade_arr)
  143. {
  144. $where = '';
  145. if (!empty($trade_arr)) {
  146. foreach ($trade_arr as $key => $val) {
  147. $where .= "name LIKE '%" . $val . "%' OR ";
  148. }
  149. }
  150. if ($where != '') {
  151. $where = substr($where, 0, strlen($where) - 3);
  152. }
  153. return CategoryJobs::whereRaw($where)->pluck('name')->toArray();
  154. }
  155. /**
  156. * [spell_assembly 数组转字符串]
  157. * @param [array] $data [被转换的数组]
  158. * @param string $p [间隔字符]
  159. * @return [string] [处理结果]
  160. */
  161. public function spellAssembly($data, $p = ',', $s = '"')
  162. {
  163. foreach ($data as $key => $val) {
  164. $arr[] = $s.$val['spell'].','.$val['name'].$s;
  165. }
  166. $arr = implode($p, $arr);
  167. if (!$s) {
  168. return '"'.$arr.'"';
  169. }
  170. return $arr;
  171. }
  172. public function getCategoryJobs($id)
  173. {
  174. return $this->CategoryJobsRepository->find($id);
  175. }
  176. //获取地标地段(找工作)
  177. public function getCitys($default_distinct = null)
  178. {
  179. if (!$default_distinct) {
  180. $default_distinct = config('aix.system.site_other.site_other.district');
  181. $subsites = Cache::get('subsites_list');
  182. if ($subsites) {
  183. if (get_subsite_id() > 0) {
  184. if ($subsites[get_subsite_id()]['district']) {
  185. $default_distinct = $subsites[get_subsite_id()]['district'];
  186. }
  187. }
  188. }
  189. }
  190. if ($default_distinct) { //后台设置默认地区
  191. //获取所有地区信息
  192. $city_cates = Cache::get('city_cate_list_'.get_subsite_id());
  193. if (null === $city_cates) {
  194. $city_cates = $this->CategoryDistrictRepository->cityCateCache();
  195. Cache::put('city_cate_list_'.get_subsite_id(), $city_cates, '86400');
  196. }
  197. //获取所有地区搜索缓存
  198. $city_searchs = Cache::get('city_search_list_'.get_subsite_id());
  199. if ($city_searchs === null) {
  200. $city_searchs = $this->CategoryDistrictRepository->citySearchCache();
  201. Cache::put('city_search_list_'.get_subsite_id(), $city_searchs, '86400');
  202. }
  203. if (!strpos($default_distinct, ".")) {
  204. //$result['select'] = $city_cates['id'][$default_distinct];
  205. if (preg_match('/^(\d{1,10},)*(\d{1,10})$/', $default_distinct)) {
  206. $result['select'] = $city_cates['id'][$default_distinct];
  207. } else {
  208. $result['select'] = $city_cates['spell'][$default_distinct];
  209. }
  210. $citycategory = $city_searchs[$result['select']['id']];
  211. $temp = $result['select']['id'];
  212. $city = explode('_', $citycategory);
  213. } else {
  214. $citycategory = $default_distinct;
  215. $city = explode('.', $default_distinct);
  216. if (array_has($city, 2) && array_get($city, 2)) {
  217. $result['select'] = $city_cates['id'][$city[2]];
  218. $temp = $city[2];
  219. } elseif (array_has($city, 1) && array_get($city, 1)) {
  220. $result['select'] = $city_cates['id'][$city[1]];
  221. $temp = $city[1];
  222. } else {
  223. $result['select'] = $city_cates['id'][$city[0]];
  224. $temp = $city[0];
  225. }
  226. }
  227. $result['select']['citycategory'] = $city_cates['id'][$result['select']['id']]['spell'];
  228. if (/*!Cache::get('subsite_id') && */$city[1]) {
  229. $result['list'] = $this->CategoryDistrictRepository->getDistrictCache($city[1]);
  230. if (!$result['list']) {
  231. $result['list'] = $this->CategoryDistrictRepository->getDistrictCache($city[0]);
  232. }
  233. foreach ($result['list'] as $key => $val) {
  234. $result['list'][$key] = array('id'=>$key,'name'=>$val,'citycategory'=>$city_cates['id'][$key]['spell']);
  235. }
  236. $result['parent'] = $city_cates['id'][$city[1]];
  237. $result['parent']['citycategory'] = $city_cates['id'][$result['parent']['id']]['spell'];
  238. } else if (/*!Cache::get('subsite_id') &&*/ $city[1]=='0') {
  239. $result['list'] = $this->CategoryDistrictRepository->getDistrictCache($city[0]);
  240. foreach ($result['list'] as $key => $val) {
  241. $result['list'][$key] = array('id'=>$key,'name'=>$val,'citycategory'=>$city_cates['id'][$key]['spell']);
  242. }
  243. $result['parent'] = $city_cates['id'][$city[0]];
  244. $result['parent']['citycategory'] = $city_cates['id'][$result['parent']['id']]['spell'];
  245. }
  246. return $result;
  247. }
  248. return false;
  249. }
  250. public function getCategories($filter_data = array())
  251. {
  252. $list = array();
  253. if ($filter_data) {
  254. $cates = $this->CategoryRepository->getCategories();
  255. if ($cates) {
  256. foreach ($cates as $key => $val) {
  257. if ($key == 'AIX_wage') {
  258. foreach ($val as $k => $v) {
  259. if (config('aix.system.site_other.site_other.site_salary') == 1) {
  260. $cates[$key][$k]['demand'] = $v['demand'];
  261. } else {
  262. $cates[$key][$k]['demand'] = $v['demand'];
  263. }
  264. }
  265. }
  266. }
  267. }
  268. foreach ($filter_data as $k => $v) {
  269. if (array_key_exists($k, $cates)) {
  270. $list[$k] = array_slice($cates[$k], 0, 3);
  271. if ($v) {
  272. $list[$k] = array_slice($cates[$k], 0, $v, true);
  273. } else {
  274. $list[$k] = $cates[$k];
  275. }
  276. } else {
  277. $list[$k] = array();
  278. }
  279. }
  280. }
  281. return $list;
  282. }
  283. public function getCitySpell()
  284. {
  285. $content = Cache::get('AIX_city_spell');
  286. $content = null;
  287. if (null === $content) {
  288. //获取所有city spell信息
  289. $spell_citys['QS_city_spell'] = $this->CategoryDistrictRepository->customDistrictCache();
  290. $content = '';
  291. foreach ($spell_citys as $key => $cate) {
  292. //$content .= "var ".$key."_parent=new Array({{$this->spellAssembly($cate[0])}});";
  293. $content .= "var ".$key."=new Array();";
  294. foreach ($cate[0] as $_key => $val) {
  295. $content .= $key."['".$val['spell']."']=".$this->spellAssembly($cate[$_key], '`', '').";";
  296. if (array_get($cate, $_key)) {
  297. foreach ($cate[$_key] as $skey => $sval) {
  298. if (array_get($cate, $skey)) {
  299. $content .= $key."['".$sval['spell']."']=".$this->spellAssembly($cate[$skey], '`', '').";";
  300. if (array_get($cate, $skey)) {
  301. foreach ($cate[$skey] as $skey4 => $sval4) {
  302. if (array_get($cate, $skey4)) {
  303. $content .= $key."['".$sval4['spell']."']=".$this->spellAssembly($cate[$skey4], '`', '').";";
  304. foreach ($cate[$skey4] as $skey5 => $sval5) {
  305. if (array_get($cate, $skey5)) {
  306. $content .= $key."['".$sval5['spell']."']=".$this->spellAssembly($cate[$skey5], '`', '').";";
  307. foreach ($cate[$skey5] as $skey6 => $sval6) {
  308. if (array_get($cate, $sval6)) {
  309. $content .= $key."['".$sval6['spell']."']=".$this->spellAssembly($cate[$skey6], '`', '').";";
  310. } else {
  311. $content .= $key."['".$sval6['spell']."']='';";
  312. }
  313. }
  314. } else {
  315. $content .= $key."['".$sval5['spell']."']='';";
  316. }
  317. }
  318. } else {
  319. $content .= $key."['".$sval4['spell']."']='';";
  320. }
  321. }
  322. }
  323. } else {
  324. $content .= $key."['".$sval['spell']."']= '';";
  325. }
  326. }
  327. }
  328. }
  329. }
  330. }
  331. return $content;
  332. }
  333. public function getDefaultDistrictInfo()
  334. {
  335. $default_district = config('aix.system.site_other.site_other.district');
  336. $subsites = Cache::get('subsites_list');
  337. if ($subsites) {
  338. if (get_subsite_id() > 0) {
  339. if ($subsites[get_subsite_id()]['district']) {
  340. $default_district = $subsites[get_subsite_id()]['district'];
  341. }
  342. }
  343. }
  344. $district_info = array('default_district'=>'','default_district_spell'=>'');
  345. if ($default_district) {
  346. $default_district_arr = explode('.', $default_district);
  347. $default_district_spell_arr = array();
  348. $city_cates = Cache::get('city_cate_list');
  349. if (null === $city_cates) {
  350. $city_cates = $this->CategoryDistrictRepository->cityCateCache();
  351. Cache::put('city_cate_list', $city_cates, '86400');
  352. }
  353. foreach ($default_district_arr as $k => $v) {
  354. $default_district_spell_arr[] = $city_cates['id'][$v]['spell'];
  355. }
  356. $default_district_spell = implode('.', $default_district_spell_arr);
  357. $district_info = array('default_district'=>$default_district,'default_district_spell'=>$default_district_spell);
  358. }
  359. return $district_info;
  360. }
  361. //获取职位分类信息
  362. public function getJobsCategories($where = array(), $limit = 0)
  363. {
  364. $result = Cache::get('jobs_custom_cate');
  365. if (null === $result) {
  366. $result = $this->CategoryJobsRepository->jobsCategoryCache();
  367. Cache::put('jobs_custom_cate', $result, '86400');
  368. }
  369. if ($where) {
  370. if (array_has($where, 'id') && (array_get($where, 'id') !='all')) {
  371. $result = $result[intval($where['id'])];
  372. }
  373. }
  374. if ($limit>0) {
  375. $result = array_slice($result, 0, $limit);
  376. }
  377. return $result;
  378. }
  379. // 获取职位分类信息内容
  380. public function getJobsCategoryInfo()
  381. {
  382. $result = Cache::get('jobs_cate_list');
  383. if (null === $result) {
  384. $result = $this->CategoryJobsRepository->jobsCateInfoCache();
  385. Cache::put('jobs_cate_list', $result, '86400');
  386. }
  387. return $result;
  388. }
  389. public function connectStatus($resume_uid, $resume_id)
  390. {
  391. $fill = false;
  392. $uid = 0;
  393. if (auth('web-member')->user()) {
  394. $uid = auth('web-member')->user()->id;
  395. $utype = auth('web-member')->user()->utype;
  396. }
  397. if (auth('web-company')->user()) {
  398. $uid = auth('web-company')->user()->id;
  399. $utype= auth('web-company')->user()->utype;
  400. }
  401. $rule = config('aix.companyset.comset.contact_set.showjobcontact');
  402. if ($rule==0) { // 游客。
  403. $fill = true;
  404. } elseif ($rule==1) { //登录
  405. if ($uid) {
  406. $fill = true;
  407. }
  408. } elseif ($rule==2) { //下载后可见。
  409. if ($uid) {
  410. if ($utype==2) { //个人
  411. if ($resume_uid==$uid) {
  412. $fill = true;
  413. }
  414. } elseif ($utype==1) {
  415. $down = DB::table('company_down_resumes')->where(['resume_id'=>$resume_id,'company_uid'=>$uid])->first();
  416. if ($down) {
  417. $fill = true;
  418. }
  419. $apply = DB::table('personal_jobs_apply')->where(['resume_id'=>$resume_id,'company_id'=>$uid])->first();
  420. if ($apply) {
  421. $fill = true;
  422. }
  423. }
  424. }
  425. }
  426. return $fill;
  427. }
  428. //获取专业分类
  429. public function getMajorCategory($pid = 'all')
  430. {
  431. $categories = $this->getCategory();
  432. $lists = array();
  433. if ($categories) {
  434. $major_category = array_get($categories, 'major');
  435. if ($major_category && array_get($major_category, 'first')) {
  436. $first = array_get($major_category, 'first');
  437. foreach ($first as $k => $v) {
  438. $cate = explode(',', $v);
  439. $lists[$cate[0]] = array('id'=>$cate[0],'categoryname'=>$cate[1]);
  440. }
  441. }
  442. if ($major_category && array_get($major_category, 'sec')) {
  443. $sec = array_get($major_category, 'sec');
  444. foreach ($sec as $k => $v) {
  445. $cates = explode('`', $v);
  446. foreach ($cates as $key => $val) {
  447. $cate = explode(',', $val);
  448. $lists[$cate[2]]['subs'][] = array('id'=>$cate[0],'categoryname'=>$cate[1],'parent_id'=>$cate[2]);
  449. }
  450. }
  451. }
  452. }
  453. if ($pid != 'all') {
  454. return array_get($lists, $pid);
  455. }
  456. return $lists;
  457. }
  458. //获取专业信息
  459. public function getMajorInfo($id = 'all')
  460. {
  461. $lists = Cache::get('major_data_list');
  462. if ($lists === null) {
  463. $res = $this->CategoryMajorRepository->getMajorList();
  464. foreach ($res as $k => $v) {
  465. $lists[$v['id']] = $v;
  466. }
  467. Cache::put('major_data_list', $lists, '86400');
  468. }
  469. if ($id) {
  470. return array_get($lists, $id);
  471. }
  472. return $lists;
  473. }
  474. /**
  475. * 获取默认地区信息.
  476. */
  477. public function getDefaultDistrict()
  478. {
  479. $defaultCity = self::DEFAULT_CITY;
  480. $disCity = self::DIS_CITY;
  481. $disHan = self::DIS_HAN;
  482. $default = config('aix.system.site_other.site_other.district');
  483. if ($default) {
  484. $defaultCity = $default;
  485. $parent_id = isset(explode('.', $default)[0]) ? explode('.', $default)[0] : '';
  486. if ($parent_id) {
  487. $distirctCity = $this->CategoryDistrictRepository->getCategoryByParent($parent_id);
  488. $disCity = $defaultCity.'.'.$distirctCity[0]->id;
  489. $disHan = $distirctCity[0]->name;
  490. }
  491. }
  492. return (object)['defaultCity'=>$defaultCity,'disCity'=>$disCity,'disHan'=>$disHan];
  493. }
  494. public function getAllJobsCategory()
  495. {
  496. //$result = Cache::get('all_jobs_cate');
  497. //if (null === $result) {
  498. $result = $this->CategoryJobsRepository->getAllJobsCategories(0);
  499. //}
  500. //Cache::put('all_jobs_cate', $result, '86400');
  501. return $result;
  502. }
  503. }