JobsSearchRepository.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Date: 2018/11/19
  5. * Time: 15:30
  6. */
  7. namespace App\Repositories;
  8. use App\Models\JobsSearch;
  9. use App\Models\Jobs;
  10. use App\Models\JobsContact;
  11. use Prettus\Repository\Criteria\RequestCriteria;
  12. use Prettus\Repository\Eloquent\BaseRepository;
  13. class JobsSearchRepository extends BaseRepository
  14. {
  15. public function model()
  16. {
  17. return JobsSearch::class;
  18. }
  19. public function jobs()
  20. {
  21. return Jobs::class;
  22. }
  23. /**
  24. * Boot up the repository, pushing criteria
  25. */
  26. public function boot()
  27. {
  28. $this->pushCriteria(app(RequestCriteria::class));
  29. }
  30. /*
  31. 完善职位索引信息
  32. @ $jobs 职位信息
  33. @ $pid 职位id
  34. */
  35. public function checkJobs($jobs, $pid)
  36. {
  37. $pid=intval($pid);
  38. if ($pid && !$jobs) {
  39. $jobs=$this->getJobsOne(array('id'=>$pid));
  40. }
  41. if (!$jobs) {
  42. return false;
  43. }
  44. //省市,职位,标签
  45. $d = array();
  46. if ($jobs->district) {
  47. $a = array_filter(explode('.', $jobs->district));
  48. for ($i=count($a)-1; $i>=0; $i--) {
  49. $d[] = 'city'.implode('_', $a);
  50. $a[$i] = 0;
  51. }
  52. }
  53. if ($jobs->topclass) {
  54. $job = $jobs->topclass.'.'.$jobs->category.'.'.$jobs->subclass;
  55. $a = array_filter(explode('.', $job));
  56. for ($i=count($a)-1; $i>=0; $i--) {
  57. $d[] = 'jobs'.implode('_', $a);
  58. $a[$i] = 0;
  59. }
  60. }
  61. if (implode(',', $jobs->tag)) {
  62. foreach ($jobs->tag as $key => $val) {
  63. $d[] = 'tag'.$val;
  64. }
  65. }
  66. $foreach_arr = array(
  67. 'eme'=>'emergency',
  68. 'stick'=>'stick',
  69. 'nat'=>'nature',
  70. 'sex'=>'sex',
  71. 'trade'=>'trade',
  72. 'edu'=>'education',
  73. 'exp'=>'experience',
  74. 'neg'=>'negotiable',
  75. 'set'=>'setmeal_id',
  76. 'audit'=>'audit',
  77. 'dis'=>'display',
  78. 'use'=>'user_status',
  79. 'robot'=>'robot',
  80. 'scale'=>'scale',
  81. 'sub'=>'subsite_id',
  82. 'lic'=>'company_audit',
  83. 'ent'=>'is_entrust'
  84. );
  85. foreach ($foreach_arr as $key => $val) {
  86. if (isset($jobs->$val)) {
  87. $d[] = $key.$jobs->$val;
  88. }
  89. }
  90. if ($jobs->allowance_id) {
  91. $d[] = 'all1';
  92. }
  93. $setsqlarr['key_precise'] = implode(' ', $d);
  94. $jobs->key_precise = $setsqlarr['key_precise'];
  95. return $this->jobsIndex($jobs['id'], $jobs);
  96. }
  97. //更新职位索引表
  98. public function jobsIndex($id, $jobs)
  99. {
  100. $where = array('id'=>$id);
  101. if ($id && !$jobs) {
  102. $jobs = $this->getJobsOne($where);
  103. }
  104. if (!$jobs) {
  105. return false;
  106. }
  107. if ($jobs->valid != 1) {
  108. $this->model->where($where)->delete();
  109. } else {
  110. $data['id'] = $jobs->id;
  111. $data['company_id'] = $jobs->company_id;
  112. $data['wage'] = $jobs->wage;
  113. $data['stime'] = $jobs->stime;
  114. $data['map_x'] = $jobs->map_x;
  115. $data['map_y'] = $jobs->map_y;
  116. $data['click'] = $jobs->click?$jobs->click:0;
  117. $data['jobs_name'] = $jobs->jobs_name;
  118. $data['companyname'] = $jobs->company_name;
  119. $data['key'] = $jobs->key_precise;
  120. $data['created_at'] = $jobs->created_at;
  121. $data['updated_at'] = $jobs->refresh_time?$jobs->refresh_time:$jobs->created_at;
  122. if ($this->model->where($where)->first()) {
  123. $reg = $this->model->where($where)->update($data);
  124. } else {
  125. $reg = $this->model->insert($data);
  126. }
  127. return $reg;
  128. }
  129. return true;
  130. }
  131. //获取单条职位
  132. public function getJobsOne($where)
  133. {
  134. $val = Jobs::where($where)->first();
  135. if (!$val) {
  136. return false;
  137. }
  138. $val->contact= JobsContact::where(array('job_id'=>$val['id']))->first();
  139. $val->deadline_days=($val->deadline -time())>0?"距到期时间还有<strong style=\"color:#FF0000\">".sub_day($val->deadline,time())."</strong>":"<span style=\"color:#FF6600\">目前已过期</span>";
  140. return $val;
  141. }
  142. }