JobfairPutJobRepository.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wuzhenke
  5. * Date: 2019/1/25
  6. * Time: 14:19
  7. */
  8. namespace App\Repositories\Jobfair;
  9. use App\Models\Jobfair\JobfairPutJob;
  10. use function foo\func;
  11. use Illuminate\Support\Facades\DB;
  12. use Prettus\Repository\Eloquent\BaseRepository;
  13. class JobfairPutJobRepository extends BaseRepository
  14. {
  15. public function model()
  16. {
  17. return JobfairPutJob::class;
  18. }
  19. public function createData($data)
  20. {
  21. return $this->model->create($data);
  22. }
  23. public function findDone($where)
  24. {
  25. return $this->model->where($where)->first();
  26. }
  27. public function searchJob($jobfair_id, $keyword, $company_id, $id)
  28. {
  29. return $this->model->whereHas('jobs',function ($query) use ($company_id,$keyword){
  30. $query->where('audit',1)->where('company_id',$company_id)->where(function ($query) use ($keyword){
  31. $query->where('jobs_name', 'like', '%'.$keyword.'%')->orWhere('company_name', 'like', '%'.$keyword.'%');
  32. });
  33. })->where(['jobfair_id'=> $jobfair_id])->where('exid', $id)->get();
  34. }
  35. public function getOne($where)
  36. {
  37. return $this->model->with(['jobfairs','jobs'])->where($where)->first();
  38. }
  39. public function getJobsCount($jobfair_id)
  40. {
  41. return $this->model->whereHas('jobs',function ($query){
  42. $query->where('audit',1)->where('display',1);
  43. })->whereHas('jobfair_company',function($query){
  44. $query->where('audit',1);
  45. })->where(['jobfair_id'=>$jobfair_id])->count();
  46. }
  47. public function getNeedPerson($jobfair_id)
  48. {
  49. return $this->model->joinJobfairJob()
  50. ->where(['jobfair_jobs.audit'=>1,'jobfair_put_jobs.jobfair_id' => $jobfair_id])
  51. ->whereHas('jobfair_company',function($query){
  52. $query->where('audit',1);
  53. })
  54. ->selectRaw('sum(jobfair_jobs.amount) as sum')
  55. ->first();
  56. }
  57. public function getJobfairJob($exid)
  58. {
  59. return $this->model->with('jobs')->whereHas('jobs',function ($query){
  60. $query->where(['audit'=>1,'display'=>1]);
  61. })->where('exid', $exid)->get();
  62. }
  63. public function getExidJobfairJob($exid)
  64. {
  65. return $this->model->with('jobs')->whereHas('jobs',function ($query){
  66. $query->where(['audit'=>1]);
  67. })->where('exid', $exid)->get();
  68. }
  69. public function getJobfairCompanyJob($where1,$where,$limit = '')
  70. {
  71. if($limit){
  72. return $this->model->with(['jobfair_company','jobs'])->whereHas('jobs',function ($query) use ($where){
  73. $query->where($where);
  74. })->where($where1)->orderBy('updated_at','desc')->paginate($limit);
  75. }else{
  76. return $this->model->with(['jobfair_company','jobs'])->whereHas('jobs',function ($query) use ($where){
  77. $query->where($where);
  78. })->where($where1)->orderBy('updated_at','desc')->get();
  79. }
  80. }
  81. public function getJobfairCompanyJobPage($where,$where1,$page){
  82. return $this->model->with(['jobfair_company','jobs'])->has('jobfair_company')->whereHas('jobs',function ($query) use ($where1){
  83. $query->where($where1);
  84. })->where($where)->orderBy('position_id')->paginate($page);
  85. }
  86. public function aioJobfairJob($where, $orwhere, $limit)
  87. {
  88. return $this->model->whereHas('jobfairs', function ($query) {
  89. $query->where([
  90. ['holddate_start', '<', strtotime("+60 minute")],
  91. ['holddate_end', '>', time()],
  92. ['subsite_id',get_subsite_id()]
  93. ])
  94. ->where(function ($query){
  95. $query->where('showendtime', '>=', time())->orWhere('showendtime', 0);
  96. });
  97. })->whereHas('jobs',function ($query) use ($where,$orwhere) {
  98. $query->whereHas('company')->where($where);
  99. if ($orwhere) {
  100. $query->where($orwhere[0][0], $orwhere[0][1], $orwhere[0][2])->orWhere($orwhere[1][0], $orwhere[1][1], $orwhere[1][2]);
  101. }
  102. })->whereHas('jobfair_company',function ($query) {
  103. $query->where('audit',1);
  104. })->paginate($limit);
  105. }
  106. public function getAudit($id){
  107. return $this->model->with(['jobs'=>function($query){
  108. $query->select('id','audit');
  109. }])->find($id);
  110. }
  111. public function editJob($id)
  112. {
  113. return $this->model->with('jobs')->where('id', $id)->first();
  114. }
  115. /**
  116. * 获取单条职位(在招的)
  117. * @param $data 条件
  118. * @return bool返回值 如果有返回职位数组,否则返回 false
  119. */
  120. public function getAuditJobsOne($data)
  121. {
  122. $val = $this->model->where($data)->first();
  123. if (!$val) {
  124. return false;
  125. }
  126. // $val->contact= JobfairPutJobsContact::where('pid', $val->id)->first();
  127. $val->deadline_days=($val->deadline-time())>0?"距到期时间还有<strong style=\"color:#FF0000\">".sub_day($val->deadline, time())."</strong>":"<span style=\"color:#FF6600\">目前已过期</span>";
  128. return $val;
  129. }
  130. //招聘会参展职位
  131. public function jobfairCompanyJob($where,$map1, $limit)
  132. {
  133. return $this->model->with(['jobfair_company','jobfairs','jobs'])->whereHas('jobs',function ($query) use ($map1){
  134. $query->where($map1)->orderByRaw("Field(jobfair_jobs.audit,2,1,3)");
  135. })->where($where)->orderByDesc('created_at')->paginate($limit);
  136. }
  137. public function delJobs($id)
  138. {
  139. return $this->model->whereIn('id', $id)->delete();
  140. }
  141. public function delJobIds($id)
  142. {
  143. return $this->model->whereIn('job_id', $id)->delete();
  144. }
  145. public function delWhereJobs($jobs_id,$where)
  146. {
  147. return $this->model->whereIn('job_id', $jobs_id)->where($where)->delete();
  148. }
  149. public function jobedit($id)
  150. {
  151. return $this->model->where('id', $id)->first();
  152. }
  153. public function getStatisticsJobCount($where, $whereIn)
  154. {
  155. $res = $this->model->where($where);
  156. if ($whereIn) {
  157. foreach ($whereIn as $k => $v) {
  158. $res->whereIn($k, $v);
  159. }
  160. }
  161. return $res->count();
  162. }
  163. public function getStatisticsJobAmount($where, $whereIn)
  164. {
  165. $res = $this->model->where($where);
  166. if ($whereIn) {
  167. foreach ($whereIn as $k => $v) {
  168. $res->whereIn($k, $v);
  169. }
  170. }
  171. return $res->sum('amount');
  172. }
  173. public function getTopClassRand($where, $whereIn, $fields, $group_by, $order_by, $limit)
  174. {
  175. $res = $this->model->selectRaw($fields)->where($where);
  176. if ($whereIn) {
  177. foreach ($whereIn as $k => $v) {
  178. $res->whereIn($k, $v);
  179. }
  180. }
  181. if ($group_by) {
  182. foreach ($group_by as $k => $v) {
  183. $res->groupBy($v);
  184. }
  185. }
  186. if ($order_by) {
  187. $res->orderByRaw($order_by);
  188. }
  189. if ($limit) {
  190. $res->offset(0)->limit($limit);
  191. }
  192. return $res->get();
  193. }
  194. public function getOpenPutJobs($where){
  195. return $this->model->whereHas('jobfairs',function ($query){
  196. $query->where('holddate_end','>=',time());
  197. })->where($where)->get();
  198. }
  199. public function getFairJobIds($where)
  200. {
  201. return $this->model->where($where)->pluck('job_id')->toArray();
  202. }
  203. public function getFairJobInIds($ids)
  204. {
  205. return $this->model->whereIn('id',$ids)->pluck('job_id')->toArray();
  206. }
  207. public function getPluck($where,$column)
  208. {
  209. return $this->model->where($where)->pluck($column);
  210. }
  211. public function getWhere($jobs_where,$put_jobs_where)
  212. {
  213. return $this->model->whereHas('jobs',function ($query) use($jobs_where){
  214. $query->where($jobs_where);
  215. })->where($put_jobs_where)->groupBy('job_id')->get();
  216. }
  217. public function isSync($jobs_where,$put_jobs_where)
  218. {
  219. return $this->model->whereHas('jobs',function ($query) use($jobs_where){
  220. $query->where($jobs_where);
  221. })->where($put_jobs_where)->groupBy('job_id')->first();
  222. }
  223. public function getJobIds($where)
  224. {
  225. return $this->model->whereHas('jobs',function ($query){
  226. $query->where('audit',1);
  227. })->where($where)->pluck('job_id')->toArray();
  228. }
  229. public function destroyArr($del_array)
  230. {
  231. return $this->model->destroy($del_array);
  232. }
  233. public function delList($where,$ids)
  234. {
  235. return $this->model->where($where)->whereIn('job_id',$ids)->delete();
  236. }
  237. }