123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace App\Repositories;
- use App\Models\CategoryJobs;
- use Prettus\Repository\Eloquent\BaseRepository;
- use Prettus\Repository\Criteria\RequestCriteria;
- use Illuminate\Support\Facades\Cache;
- /**
- * Class MemberRepositoryEloquent.
- *
- * @package namespace App\Repositories;
- */
- class CategoryJobsRepository extends BaseRepository
- {
- /**
- * Specify Model class name
- *
- * @return string
- */
- public function model()
- {
- return CategoryJobs::class;
- }
- /**
- * Boot up the repository, pushing criteria
- */
- public function boot()
- {
- $this->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;
- }
- }
- }
|