123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530 |
- <?php
- namespace App\Services\Common;
- use App\Models\CategoryJobs;
- use App\Repositories\CategoryDistrictRepository;
- use App\Repositories\CategoryGroupRepository;
- use App\Repositories\CategoryJobsRepository;
- use App\Repositories\CategoryMajorRepository;
- use App\Repositories\CategoryRepository;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\DB;
- class CategoryService
- {
- /**
- * @var CategoryMajorRepository
- */
- protected $CategoryMajorRepository;
- protected $CategoryJobsRepository;
- protected $CategoryDistrictRepository;
- protected $CategoryGroupRepository;
- protected $CategoryRepository;
- const DEFAULT_CITY = '9.107';
- const DIS_CITY = '9.107.1119';
- const DIS_HAN = '黄浦区';
- /**
- * CategoryService constructor.
- * @param CategoryMajorRepository $CategoryMajorRepository
- * @param CategoryJobsRepository $CategoryJobsRepository
- * @param CategoryDistrictRepository $CategoryDistrictRepository
- * @param CategoryGroupRepository $CategoryGroupRepository
- * @param CategoryRepository $CategoryRepository
- */
- public function __construct(CategoryMajorRepository $CategoryMajorRepository, CategoryJobsRepository $CategoryJobsRepository, CategoryDistrictRepository $CategoryDistrictRepository, CategoryGroupRepository $CategoryGroupRepository, CategoryRepository $CategoryRepository)
- {
- $this->CategoryMajorRepository = $CategoryMajorRepository;
- $this->CategoryJobsRepository = $CategoryJobsRepository;
- $this->CategoryDistrictRepository = $CategoryDistrictRepository;
- $this->CategoryGroupRepository = $CategoryGroupRepository;
- $this->CategoryRepository = $CategoryRepository;
- }
- /**
- * 获取专业--职位--地区--其他信息。
- */
- public function getCategory()
- {
- if (Cache::has('aix_category')) {
- return Cache::get('aix_category');
- } else {
- /**
- * 专业
- */
- $major = $this->CategoryMajorRepository->getCategoryById();
- $major_V = [];
- foreach ($major as $k => $v) {
- $major_V[] = $v['id'].','.$v['name'];
- }
- $major_par = [];
- foreach ($major as $key => $val) {
- $major_list = $this->CategoryMajorRepository->getCategoryById($val['id']);
- $imp = [];
- foreach ($major_list as $key1 => $val1) {
- $imp[] = implode(',', $val1);
- }
- $major_par[$val['id']] = implode('`', $imp);
- }
- /**
- * 职位信息
- */
- $jobs = $this->CategoryJobsRepository->getCategoryById();
- $jobs_V = [];
- foreach ($jobs as $k => $v) {
- $jobs_V[] = $v['id'].','.$v['name'];
- }
- $jobs_par = [];
- foreach ($jobs as $key => $val) {
- $jobs_list = $this->CategoryJobsRepository->getCategoryById($val['id']);
- $kl = [];
- foreach ($jobs_list as $key1 => $val1) {
- $arr = explode(',', implode(',', $val1));
- $kl[] = $arr[0].','.$arr[1];
- $jobs_k = $this->CategoryJobsRepository->getCategoryById($val1['id']);
- $kmd = [];
- foreach ($jobs_k as $key2 => $val2) {
- $kmd[] = implode(',', $val2);
- }
- $jobs_par[$val1['id']] = implode('`', $kmd);
- }
- $jobs_par[$val['id']] = implode('`', $kl);
- }
- /**
- * 地区信息。
- */
- $district = $this->CategoryDistrictRepository->getCategoryById();
- $district_V = [];
- $district_s = [];
- foreach ($district as $k => $v) {
- $district_V[] = $v['id'].','.$v['name'];
- $district_s[] = $v['spell'].','.$v['name'];
- }
- $district_par = [];
- $district_par_person = [];
- foreach ($district as $key => $val) {
- $district_list = $this->CategoryDistrictRepository->getCategoryById($val['id']);
- $kl = [];
- foreach ($district_list as $key1 => $val1) {
- $arr = explode(',', implode(',', $val1));
- $kl[] = $arr[0].','.$arr[1];
- $district_k = $this->CategoryDistrictRepository->getCategoryById($val1['id']);
- $kmd = [];
- $kmd_person = [];
- foreach ($district_k as $key2 => $val2) {
- $kmd[] = implode(',', $val2);
- $kmd_person[] = implode(',', $val2);
- }
- array_unshift($kmd, '0,不限,'.$val1['id'].',buxian');
- $district_par[$val1['id']] = implode('`', $kmd);
- $district_par_person[$val1['id']] = implode('`', $kmd_person);
- }
- $district_par[$val['id']] = implode('`', $kl);
- $district_par_person[$val['id']] = implode('`', $kl);
- }
- /**
- * 其他信息。
- */
- $Groups = $this->CategoryGroupRepository->getCategoryGroup();
- $Groups_arr = array_column($Groups, 'alias');
- $category = $this->CategoryRepository->getCategoryInfo($Groups_arr);
- $category_V = [];
- foreach ($Groups_arr as $k => $v) {
- foreach ($category as $k1 => $v1) {
- if ($v==$v1['alias']) {
- $category_V[$v][] = $v1['id'].','.$v1['demand'];
- }
- }
- }
- 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);
- 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];
- }
- }
- /**
- * 根据行业获取分类。
- */
- public function getCategoryByTrade($trade_arr)
- {
- $where = '';
- if (!empty($trade_arr)) {
- foreach ($trade_arr as $key => $val) {
- $where .= "name LIKE '%" . $val . "%' OR ";
- }
- }
- if ($where != '') {
- $where = substr($where, 0, strlen($where) - 3);
- }
- return CategoryJobs::whereRaw($where)->pluck('name')->toArray();
- }
- /**
- * [spell_assembly 数组转字符串]
- * @param [array] $data [被转换的数组]
- * @param string $p [间隔字符]
- * @return [string] [处理结果]
- */
- public function spellAssembly($data, $p = ',', $s = '"')
- {
- foreach ($data as $key => $val) {
- $arr[] = $s.$val['spell'].','.$val['name'].$s;
- }
- $arr = implode($p, $arr);
- if (!$s) {
- return '"'.$arr.'"';
- }
- return $arr;
- }
- public function getCategoryJobs($id)
- {
- return $this->CategoryJobsRepository->find($id);
- }
- //获取地标地段(找工作)
- public function getCitys($default_distinct = null)
- {
- if (!$default_distinct) {
- $default_distinct = config('aix.system.site_other.site_other.district');
- $subsites = Cache::get('subsites_list');
- if ($subsites) {
- if (get_subsite_id() > 0) {
- if ($subsites[get_subsite_id()]['district']) {
- $default_distinct = $subsites[get_subsite_id()]['district'];
- }
- }
- }
- }
- if ($default_distinct) { //后台设置默认地区
- //获取所有地区信息
- $city_cates = Cache::get('city_cate_list_'.get_subsite_id());
- if (null === $city_cates) {
- $city_cates = $this->CategoryDistrictRepository->cityCateCache();
- Cache::put('city_cate_list_'.get_subsite_id(), $city_cates, '86400');
- }
- //获取所有地区搜索缓存
- $city_searchs = Cache::get('city_search_list_'.get_subsite_id());
- if ($city_searchs === null) {
- $city_searchs = $this->CategoryDistrictRepository->citySearchCache();
- Cache::put('city_search_list_'.get_subsite_id(), $city_searchs, '86400');
- }
- if (!strpos($default_distinct, ".")) {
- //$result['select'] = $city_cates['id'][$default_distinct];
- if (preg_match('/^(\d{1,10},)*(\d{1,10})$/', $default_distinct)) {
- $result['select'] = $city_cates['id'][$default_distinct];
- } else {
- $result['select'] = $city_cates['spell'][$default_distinct];
- }
- $citycategory = $city_searchs[$result['select']['id']];
- $temp = $result['select']['id'];
- $city = explode('_', $citycategory);
- } else {
- $citycategory = $default_distinct;
- $city = explode('.', $default_distinct);
- if (array_has($city, 2) && array_get($city, 2)) {
- $result['select'] = $city_cates['id'][$city[2]];
- $temp = $city[2];
- } elseif (array_has($city, 1) && array_get($city, 1)) {
- $result['select'] = $city_cates['id'][$city[1]];
- $temp = $city[1];
- } else {
- $result['select'] = $city_cates['id'][$city[0]];
- $temp = $city[0];
- }
- }
- $result['select']['citycategory'] = $city_cates['id'][$result['select']['id']]['spell'];
- if (/*!Cache::get('subsite_id') && */$city[1]) {
- $result['list'] = $this->CategoryDistrictRepository->getDistrictCache($city[1]);
- if (!$result['list']) {
- $result['list'] = $this->CategoryDistrictRepository->getDistrictCache($city[0]);
- }
- foreach ($result['list'] as $key => $val) {
- $result['list'][$key] = array('id'=>$key,'name'=>$val,'citycategory'=>$city_cates['id'][$key]['spell']);
- }
- $result['parent'] = $city_cates['id'][$city[1]];
- $result['parent']['citycategory'] = $city_cates['id'][$result['parent']['id']]['spell'];
- } else if (/*!Cache::get('subsite_id') &&*/ $city[1]=='0') {
- $result['list'] = $this->CategoryDistrictRepository->getDistrictCache($city[0]);
- foreach ($result['list'] as $key => $val) {
- $result['list'][$key] = array('id'=>$key,'name'=>$val,'citycategory'=>$city_cates['id'][$key]['spell']);
- }
- $result['parent'] = $city_cates['id'][$city[0]];
- $result['parent']['citycategory'] = $city_cates['id'][$result['parent']['id']]['spell'];
- }
- return $result;
- }
- return false;
- }
- public function getCategories($filter_data = array())
- {
- $list = array();
- if ($filter_data) {
- $cates = $this->CategoryRepository->getCategories();
- if ($cates) {
- foreach ($cates as $key => $val) {
- if ($key == 'AIX_wage') {
- foreach ($val as $k => $v) {
- if (config('aix.system.site_other.site_other.site_salary') == 1) {
- $cates[$key][$k]['demand'] = $v['demand'];
- } else {
- $cates[$key][$k]['demand'] = $v['demand'];
- }
- }
- }
- }
- }
- foreach ($filter_data as $k => $v) {
- if (array_key_exists($k, $cates)) {
- $list[$k] = array_slice($cates[$k], 0, 3);
- if ($v) {
- $list[$k] = array_slice($cates[$k], 0, $v, true);
- } else {
- $list[$k] = $cates[$k];
- }
- } else {
- $list[$k] = array();
- }
- }
- }
- return $list;
- }
- public function getCitySpell()
- {
- $content = Cache::get('AIX_city_spell');
- $content = null;
- if (null === $content) {
- //获取所有city spell信息
- $spell_citys['QS_city_spell'] = $this->CategoryDistrictRepository->customDistrictCache();
- $content = '';
- foreach ($spell_citys as $key => $cate) {
- //$content .= "var ".$key."_parent=new Array({{$this->spellAssembly($cate[0])}});";
- $content .= "var ".$key."=new Array();";
- foreach ($cate[0] as $_key => $val) {
- $content .= $key."['".$val['spell']."']=".$this->spellAssembly($cate[$_key], '`', '').";";
- if (array_get($cate, $_key)) {
- foreach ($cate[$_key] as $skey => $sval) {
- if (array_get($cate, $skey)) {
- $content .= $key."['".$sval['spell']."']=".$this->spellAssembly($cate[$skey], '`', '').";";
- if (array_get($cate, $skey)) {
- foreach ($cate[$skey] as $skey4 => $sval4) {
- if (array_get($cate, $skey4)) {
- $content .= $key."['".$sval4['spell']."']=".$this->spellAssembly($cate[$skey4], '`', '').";";
- foreach ($cate[$skey4] as $skey5 => $sval5) {
- if (array_get($cate, $skey5)) {
- $content .= $key."['".$sval5['spell']."']=".$this->spellAssembly($cate[$skey5], '`', '').";";
- foreach ($cate[$skey5] as $skey6 => $sval6) {
- if (array_get($cate, $sval6)) {
- $content .= $key."['".$sval6['spell']."']=".$this->spellAssembly($cate[$skey6], '`', '').";";
- } else {
- $content .= $key."['".$sval6['spell']."']='';";
- }
- }
- } else {
- $content .= $key."['".$sval5['spell']."']='';";
- }
- }
- } else {
- $content .= $key."['".$sval4['spell']."']='';";
- }
- }
- }
- } else {
- $content .= $key."['".$sval['spell']."']= '';";
- }
- }
- }
- }
- }
- }
- return $content;
- }
- public function getDefaultDistrictInfo()
- {
- $default_district = config('aix.system.site_other.site_other.district');
- $subsites = Cache::get('subsites_list');
- if ($subsites) {
- if (get_subsite_id() > 0) {
- if ($subsites[get_subsite_id()]['district']) {
- $default_district = $subsites[get_subsite_id()]['district'];
- }
- }
- }
- $district_info = array('default_district'=>'','default_district_spell'=>'');
- if ($default_district) {
- $default_district_arr = explode('.', $default_district);
- $default_district_spell_arr = array();
- $city_cates = Cache::get('city_cate_list');
- if (null === $city_cates) {
- $city_cates = $this->CategoryDistrictRepository->cityCateCache();
- Cache::put('city_cate_list', $city_cates, '86400');
- }
- foreach ($default_district_arr as $k => $v) {
- $default_district_spell_arr[] = $city_cates['id'][$v]['spell'];
- }
- $default_district_spell = implode('.', $default_district_spell_arr);
- $district_info = array('default_district'=>$default_district,'default_district_spell'=>$default_district_spell);
- }
- return $district_info;
- }
- //获取职位分类信息
- public function getJobsCategories($where = array(), $limit = 0)
- {
- $result = Cache::get('jobs_custom_cate');
- if (null === $result) {
- $result = $this->CategoryJobsRepository->jobsCategoryCache();
- Cache::put('jobs_custom_cate', $result, '86400');
- }
- if ($where) {
- if (array_has($where, 'id') && (array_get($where, 'id') !='all')) {
- $result = $result[intval($where['id'])];
- }
- }
- if ($limit>0) {
- $result = array_slice($result, 0, $limit);
- }
- return $result;
- }
- // 获取职位分类信息内容
- public function getJobsCategoryInfo()
- {
- $result = Cache::get('jobs_cate_list');
- if (null === $result) {
- $result = $this->CategoryJobsRepository->jobsCateInfoCache();
- Cache::put('jobs_cate_list', $result, '86400');
- }
- return $result;
- }
- public function connectStatus($resume_uid, $resume_id)
- {
- $fill = false;
- $uid = 0;
- if (auth('web-member')->user()) {
- $uid = auth('web-member')->user()->id;
- $utype = auth('web-member')->user()->utype;
- }
- if (auth('web-company')->user()) {
- $uid = auth('web-company')->user()->id;
- $utype= auth('web-company')->user()->utype;
- }
- $rule = config('aix.companyset.comset.contact_set.showjobcontact');
- if ($rule==0) { // 游客。
- $fill = true;
- } elseif ($rule==1) { //登录
- if ($uid) {
- $fill = true;
- }
- } elseif ($rule==2) { //下载后可见。
- if ($uid) {
- if ($utype==2) { //个人
- if ($resume_uid==$uid) {
- $fill = true;
- }
- } elseif ($utype==1) {
- $down = DB::table('company_down_resumes')->where(['resume_id'=>$resume_id,'company_uid'=>$uid])->first();
- if ($down) {
- $fill = true;
- }
- $apply = DB::table('personal_jobs_apply')->where(['resume_id'=>$resume_id,'company_id'=>$uid])->first();
- if ($apply) {
- $fill = true;
- }
- }
- }
- }
- return $fill;
- }
- //获取专业分类
- public function getMajorCategory($pid = 'all')
- {
- $categories = $this->getCategory();
- $lists = array();
- if ($categories) {
- $major_category = array_get($categories, 'major');
- if ($major_category && array_get($major_category, 'first')) {
- $first = array_get($major_category, 'first');
- foreach ($first as $k => $v) {
- $cate = explode(',', $v);
- $lists[$cate[0]] = array('id'=>$cate[0],'categoryname'=>$cate[1]);
- }
- }
- if ($major_category && array_get($major_category, 'sec')) {
- $sec = array_get($major_category, 'sec');
- foreach ($sec as $k => $v) {
- $cates = explode('`', $v);
- foreach ($cates as $key => $val) {
- $cate = explode(',', $val);
- $lists[$cate[2]]['subs'][] = array('id'=>$cate[0],'categoryname'=>$cate[1],'parent_id'=>$cate[2]);
- }
- }
- }
- }
- if ($pid != 'all') {
- return array_get($lists, $pid);
- }
- return $lists;
- }
- //获取专业信息
- public function getMajorInfo($id = 'all')
- {
- $lists = Cache::get('major_data_list');
- if ($lists === null) {
- $res = $this->CategoryMajorRepository->getMajorList();
- foreach ($res as $k => $v) {
- $lists[$v['id']] = $v;
- }
- Cache::put('major_data_list', $lists, '86400');
- }
- if ($id) {
- return array_get($lists, $id);
- }
- return $lists;
- }
- /**
- * 获取默认地区信息.
- */
- public function getDefaultDistrict()
- {
- $defaultCity = self::DEFAULT_CITY;
- $disCity = self::DIS_CITY;
- $disHan = self::DIS_HAN;
- $default = config('aix.system.site_other.site_other.district');
- if ($default) {
- $defaultCity = $default;
- $parent_id = isset(explode('.', $default)[0]) ? explode('.', $default)[0] : '';
- if ($parent_id) {
- $distirctCity = $this->CategoryDistrictRepository->getCategoryByParent($parent_id);
- $disCity = $defaultCity.'.'.$distirctCity[0]->id;
- $disHan = $distirctCity[0]->name;
- }
- }
- return (object)['defaultCity'=>$defaultCity,'disCity'=>$disCity,'disHan'=>$disHan];
- }
- public function getAllJobsCategory()
- {
- //$result = Cache::get('all_jobs_cate');
- //if (null === $result) {
- $result = $this->CategoryJobsRepository->getAllJobsCategories(0);
- //}
- //Cache::put('all_jobs_cate', $result, '86400');
- return $result;
- }
- }
|