pushCriteria(app(RequestCriteria::class)); } /** * @param $id * @return mixed */ public function getCategoryJobs($id) { return $this->model->find($id); } public function getCategoryById($parent = 0) { return $this->model->where(['parent_id'=>$parent])->select(['id','name','parent_id'])->get()->toArray(); } public function getManyJobs($id) { return $this->model->whereIn('id', $id)->get(); } public function jobsCategoryCache() { $lists = array(); $jobsData = $this->model->select(array('id','parent_id','name','spell'))->orderBy('order', 'desc')->get()->toArray(); foreach ($jobsData as $key => $val) { $lists[$val['parent_id']][$val['id']] = $val; } return $lists; } public function jobsCateInfoCache() { $res = $this->model ->select(array('spell','id','parent_id','name')) ->orderBy('parent_id', 'desc') ->get() ->toArray(); $cateSpell = array(); $cateId =array(); foreach ($res as $key => $val) { $cateId[$val['id']] = $val; $cateSpell[$val['spell']] = $val; } $lists = array('spell'=>$cateSpell,'id'=>$cateId); return $lists; } public function getJobCategories() { $job_cates = Cache::get('jobs_custom_cate'); if (null === $job_cates) { $job_cates = $this->jobsCategoryCache(); Cache::put('jobs_custom_cate', $job_cates, '86400'); } return $job_cates; } public function getAllJobsCategories($parent_id = 0){ $result = []; $result = $this->model->where(['parent_id'=>$parent_id])->select(['id','name','parent_id'])->get()->toArray(); if($result){ foreach ($result as $k => $v){ $child = $this->getAllJobsCategories($v['id']); if($child && is_array($child) && count($child) > 0){ $result[$k]['child'] = $child; } } return $result; } } }