JobController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Handlers\ImageHandler;
  4. use App\Http\Requests\CheckAddJonInfoRequest;
  5. use App\Models\JobList;
  6. use Carbon\Carbon;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\Auth;
  9. use Illuminate\Support\Facades\Log;
  10. use Illuminate\Support\Facades\Validator;
  11. class JobController extends Controller
  12. {
  13. /**首页分类列表**/
  14. public function HomeClassifyList(){
  15. return $this->success(JobList::GetTopJob());
  16. }
  17. /**列表**/
  18. public function JobList(Request $request){
  19. $page_index=$request->input('page_index');
  20. $page_size=$request->input('page_size');
  21. $status=true;
  22. if (!Auth::check()){
  23. $status=false;
  24. }
  25. $classify_pid=$request->input('classify_pid');
  26. $classify_id=$request->input('classify_id');
  27. $province=$request->input('province');
  28. $city=$request->input('city');
  29. return $this->successNewPaginate(JobList::GetJobList($page_index,$page_size,$status,$classify_pid,$classify_id,$province,$city));
  30. }
  31. public function GetUserJobList(Request $request){
  32. $user_id=Auth::user()->id;
  33. $page_index=$request->input('page_index');
  34. $page_size=$request->input('page_size');
  35. return $this->success(JobList::GetUserJobList($page_index,$page_size));
  36. }
  37. /**获取详情**/
  38. public function GetJobDetail(Request $request){
  39. $id=$request->input('id');
  40. $status=true;
  41. if (!Auth::check()){
  42. $status=false;
  43. }
  44. return $this->success(JobList::GetJobDetail($id,$status));
  45. }
  46. /*
  47. * 发布招工信息
  48. * ***/
  49. public function AddInfo(Request $request,JobList $jobList){
  50. $data=$request->all();
  51. $rules=[
  52. 'title' => 'required|max:50',//招工名称
  53. 'classify_id' => 'required',//所属分类
  54. 'mobile' => 'required',//联系电话
  55. 'province' => 'required',
  56. 'city' => 'required',
  57. 'area' => 'required',//招工地址
  58. 'address' => 'required',//招工地址
  59. 'username' => 'required|max:20',//联系人
  60. 'description' => 'required|max:50',//项目简介
  61. // 'longitude' => 'required',//纬度
  62. // 'latitude' => 'required',//经度
  63. ];
  64. $messages=[
  65. 'required'=>':attribute 是必填项!',
  66. 'max'=>':attribute 超过最大值'
  67. ];
  68. $validator = Validator::make($data, $rules, $messages);
  69. if($validator->fails()){
  70. return $this->fail(['400013',$validator->errors()->first()]);
  71. }
  72. $data['user_id']=Auth::user()->id;
  73. $data['created_at']=Carbon::now()->toDateTimeString();
  74. $data['updated_at']=Carbon::now()->toDateTimeString();
  75. JobList::add($data);
  76. return $this->success();
  77. }
  78. /**上传图片***/
  79. public function UploadImg(Request $request,ImageHandler $imageHandler){
  80. $file=$request->file('file');
  81. if (!$file){
  82. return $this->fail();
  83. }
  84. $path=$imageHandler->save($file,'job',random_int(11,99));
  85. return $this->success(['url'=>$path['path']]);
  86. }
  87. /**点击更新招满、进行时的装态**/
  88. public function UpdateStatus(Request $request){
  89. $id=$request->input('id');
  90. $status=$request->input('status');
  91. JobList::updateStatus($id,$status);
  92. return $this->success();
  93. }
  94. /**删除招工**/
  95. public function DelJobInfo(Request $request){
  96. $id=$request->input('id');
  97. JobList::DelJobInfo($id);
  98. return $this->success();
  99. }
  100. }