QuanzhidaController.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wuzhenke
  5. * Date: 2019/1/17
  6. * Time: 16:19
  7. */
  8. namespace App\Http\Controllers\Mobile\Active;
  9. use App\Http\Controllers\Mobile\MobileBaseController;
  10. use App\Services\Common\CategoryService;
  11. use Illuminate\Http\Request;
  12. use Illuminate\Support\Facades\DB;
  13. class QuanzhidaController extends MobileBaseController
  14. {
  15. protected $categoryService;
  16. public function __construct(CategoryService $categoryService)
  17. {
  18. $this->categoryService = $categoryService;
  19. }
  20. public function index(Request $request)
  21. {
  22. //获取分类
  23. $filter_where = array(
  24. 'AIX_education' => 100,
  25. 'AIX_experience' => 100
  26. );
  27. $categories = $this->categoryService->getCategories($filter_where); //过滤条件信息
  28. //获取数据
  29. $where = $this->_dealWhere($request);
  30. $list = DB::table('quanzhida')->where($where)->paginate(10);
  31. //数据处理
  32. foreach ($list as $val) {
  33. $val->wage_cn = $val->wage_min .'-'.$val->wage_max.'/月';
  34. $val->education_cn = $val->education ? get_category($val->education) : '不限';
  35. $val->experience_cn = $val->experience ? get_category($val->experience) : '不限';
  36. }
  37. //ajax返回
  38. if ($request->ajax()) {
  39. if ($list->lastPage() < $list->currentPage()) {
  40. return response()->json(['status'=>0]);
  41. }
  42. return response()->json(['status'=>1,'data'=>view('mobile.app.active.ajax.quanzhida_list', ['list'=> $list->items()])->render()]);
  43. }
  44. $return_data['categories'] = $categories;
  45. $return_data['params'] = $request->input();
  46. $return_data['list'] = $list->items();
  47. return view('mobile.app.active.quanzhida', $return_data);
  48. }
  49. /**
  50. * 搜索条件处理
  51. */
  52. private function _dealWhere(Request $request)
  53. {
  54. //搜索条件
  55. $where = [];
  56. $keyword = $request->input('keyword');
  57. if (!empty($keyword)) {
  58. $key_name = $request->input('key_name');
  59. $where[] = [$key_name, 'like', "%{$keyword}%"];
  60. }
  61. $education = $request->input('education');
  62. if (!empty($education)) {
  63. $where[] = ['education', '>=', $education];
  64. }
  65. $experience = $request->input('experience');
  66. if (!empty($experience)) {
  67. $where[] = ['experience', '=', $experience];
  68. }
  69. return $where;
  70. }
  71. }