QuanzhidaController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 = [
  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_data['wap_title'] = '泉州职业大学';
  48. return view('mobile.app.active.quanzhida', $return_data);
  49. }
  50. /**
  51. * 搜索条件处理
  52. */
  53. private function _dealWhere(Request $request)
  54. {
  55. //搜索条件
  56. $where = [];
  57. $keyword = $request->input('keyword');
  58. if (!empty($keyword)) {
  59. $key_name = $request->input('key_name');
  60. $where[] = [$key_name, 'like', "%{$keyword}%"];
  61. }
  62. $education = $request->input('education');
  63. if (!empty($education)) {
  64. $where[] = ['education', '>=', $education];
  65. }
  66. $experience = $request->input('experience');
  67. if (!empty($experience)) {
  68. $where[] = ['experience', '=', $experience];
  69. }
  70. return $where;
  71. }
  72. }