TeachController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace App\Http\Controllers\Mobile\Health;
  3. use App\Http\Controllers\Mobile\MobileBaseController;
  4. use App\Models\Presentation;
  5. use App\Models\PresentationAppoint;
  6. use App\Repositories\CategoryMajorRepository;
  7. use App\Repositories\CategoryRepository;
  8. use App\Services\Common\CategoryService;
  9. use App\Validators\PresentationAppointValidatorRequest;
  10. use Illuminate\Support\Facades\Storage;
  11. use App\Repositories\CategoryDistrictRepository;
  12. class TeachController extends MobileBaseController
  13. {
  14. protected $categoryService;
  15. protected $CategoryDistrictRepository;
  16. protected $CategoryMajorRepository;
  17. protected $CategoryRepository;
  18. public function __construct(CategoryService $categoryService, CategoryDistrictRepository $categoryDistrictRepository, CategoryMajorRepository $CategoryMajorRepository, CategoryRepository $CategoryRepository)
  19. {
  20. $this->categoryService = $categoryService;
  21. $this->CategoryDistrictRepository = $categoryDistrictRepository;
  22. $this->CategoryMajorRepository = $CategoryMajorRepository;
  23. $this->CategoryRepository = $CategoryRepository;
  24. }
  25. public function uploadHead()
  26. {
  27. $image_data = request()->pic1;
  28. $saveName = 'person/images/' . uniqid() . '.jpg';
  29. $data = base64_decode($image_data);
  30. if (!empty($data)) {
  31. $res = Storage::disk('public')->put($saveName, $data);
  32. return response()->json(['status' => 1, 'info' => 'success', 'data' => $saveName]);
  33. } else {
  34. return response()->json(['status' => 0, 'info' => '请上传图片']);
  35. }
  36. }
  37. public function index()
  38. {
  39. $district = $this->categoryService->getDefaultDistrict();
  40. $presentation_list = Presentation::where('status', 1)->get();
  41. return view('mobile.app.health.teach.index', [
  42. 'presentation_list' => $presentation_list,
  43. 'defaultCity' => $district->defaultCity,
  44. ]);
  45. }
  46. public function save(PresentationAppointValidatorRequest $request)
  47. {
  48. $field = [
  49. 'pid'=>'招聘会场次',
  50. 'realname'=>'姓名',
  51. 'sex'=> '性别',
  52. 'mobile'=>'手机号',
  53. 'birthday'=>'出生年月',
  54. 'native_place'=>'籍贯',
  55. 'fresh'=>'是否应届',
  56. 'education'=>'学历',
  57. 'school'=>'学校',
  58. 'dep'=>'院系',
  59. 'pro_type'=>'专业',
  60. 'pro_text'=>'具体专业'
  61. ];
  62. $data = $request->post();
  63. foreach ($field as $k => $v) {
  64. if (empty($data[$k])) {
  65. return response()->json(['status' => 0, 'msg' => $v . '不能为空']);
  66. }
  67. }
  68. $check = PresentationAppoint::where('pid', $data['pid'])->where('mobile', $data['mobile'])->first();
  69. if (!empty($check)) {
  70. return response()->json(['status' => 0, 'msg' => '您已提交过,请勿重复提交']);
  71. }
  72. //籍贯
  73. $native_place_arr = explode('.', $data['native_place']);
  74. $houseRes = $this->CategoryDistrictRepository->getManydistrict($native_place_arr);
  75. $native_place_cn = '';
  76. foreach ($houseRes as $k => $v) {
  77. $native_place_cn .= $v['name'];
  78. }
  79. $data['native_place'] = $native_place_cn;
  80. //专业类别
  81. $majorArr = $this->CategoryMajorRepository->getCategoryMajor($data['pro_type']);
  82. $data['pro_type'] = $majorArr['name'];
  83. //学历
  84. $educationArr = $this->CategoryRepository->getCategory($data['education']);
  85. $data['education'] = $educationArr['demand'];
  86. //其他处理
  87. $data['avatar'] = $data['avatar'] ?? '';
  88. $data['attachment'] = $data['attachment'] ?? '';
  89. PresentationAppoint::create($data);
  90. return response()->json(['status' => 1]);
  91. }
  92. }