BuyhouseController.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. <?php
  2. namespace App\Http\Controllers\Web\Content;
  3. use App\Http\Controllers\Web\WebBaseController;
  4. use App\Models\Article;
  5. use App\Models\MemberInfo;
  6. use App\Models\Resume;
  7. use App\Models\TalentHouse;
  8. use App\Models\TalentHouseApply;
  9. use App\Models\TalentHousePeople;
  10. use App\Services\Content\ArticleService;
  11. use Illuminate\Http\Request;
  12. use Illuminate\Support\Facades\DB;
  13. use Illuminate\Support\Facades\Storage;
  14. use Illuminate\Support\Facades\Validator;
  15. class BuyhouseController extends WebBaseController
  16. {
  17. private $street = [
  18. '青阳街道', '梅岭街道', '西园街道', '罗山街道', '灵源街道', '新塘街道', '陈埭镇', '池店镇', '安海镇', '磁灶镇', '内坑镇', '紫帽镇', '东石镇', '永和镇', '英林镇', '金井镇', '龙湖镇', '深沪镇', '西滨镇',
  19. ];
  20. private $house_status = ['未知', '未开始', '申报中', '已结束'];
  21. private $tag_status = ['', 'info', 'success', 'danger'];
  22. private $apply_status = ['未知', '审核中', '已通过', '已拒绝'];
  23. private $check_type = ['', 'warning', 'success', 'error'];
  24. private $talent_level = ['不是人才', '第一层次', '第二层次', '第三层次', '第四层次', '第五层次', '第六层次', '第七层次'];
  25. protected $articleService;
  26. /**
  27. * ArticleController constructor.
  28. * @param $articleService
  29. * @param $articleCategoryService
  30. */
  31. public function __construct(ArticleService $articleService)
  32. {
  33. $this->articleService = $articleService;
  34. }
  35. /**
  36. * 登录
  37. */
  38. public function login()
  39. {
  40. $user_id = auth('web-member')->id();
  41. $return_data = ['user_id' => $user_id ?: 0, 'apply' => '[]'];
  42. //房源
  43. $house = TalentHouse::orderBy('updated_at', 'desc')->orderByRaw(DB::raw("FIELD(status,2,1,3)"))->limit(8)->get();
  44. foreach ($house as $v) {
  45. $v['apply_time_start'] = date('Y-m-d', strtotime($v['apply_time_start']));
  46. $v['apply_time_end'] = date('Y-m-d', strtotime($v['apply_time_end']));
  47. $v['status_text'] = $this->house_status[$v['status']];
  48. $v['status_tag'] = $this->tag_status[$v['status']];
  49. $v['url'] = route('buyhouse.detail', ['id' => $v['id']]);
  50. }
  51. $return_data['house'] = $house;
  52. //新闻
  53. $news = Article::where('type_id', 56)->where('is_display', 1)->select(['id', 'title', 'updated_at'])->orderBy('list_order', 'desc')->limit(10)->get();
  54. foreach ($news as $v) {
  55. $v['updated_at_text'] = date('Y-m-d', strtotime($v['updated_at']));
  56. $v['url'] = route('news.show', ['id' => $v['id']]);
  57. }
  58. $return_data['news'] = $news;
  59. //我的申报
  60. if ($user_id > 0) {
  61. $apply = TalentHouseApply::with('house')
  62. ->select(['id', 'house_id', 'status'])
  63. ->where('is_draft', 2)
  64. ->where('is_back', 2)
  65. ->where('user_id', $user_id)
  66. ->get();
  67. foreach ($apply as $v) {
  68. $v['status_text'] = $this->apply_status[$v['status']];
  69. $v['status_tag'] = $this->tag_status[$v['status']];
  70. $v['url'] = route('buyhouse.list', ['id' => $v['house_id']]);
  71. }
  72. $return_data['apply'] = $apply;
  73. //用户信息
  74. $memberInfo = MemberInfo::where('uid', $user_id)->first();
  75. $return_data['member_info'] = $memberInfo;
  76. }
  77. return view('app.content.buyhouse.login', $return_data);
  78. }
  79. /**
  80. * 完善信息
  81. */
  82. public function perfect(Request $request)
  83. {
  84. $user_id = auth('web-member')->id();
  85. if (empty($user_id)) {
  86. return response()->json(['status' => 0, 'msg' => '请先登录']);
  87. }
  88. $data = $request->only(['realname', 'card_t_cn', 'id_card']);
  89. MemberInfo::where('uid',$user_id)->update($data);
  90. return response()->json(['status' => 1, 'msg' => '修改成功']);
  91. }
  92. /**
  93. * 房源信息
  94. */
  95. public function house()
  96. {
  97. $lists = TalentHouse::orderByRaw(DB::raw("FIELD(status,2,1,3)"))->paginate(10);
  98. foreach ($lists as $v) {
  99. $v['apply_time_start'] = date('Y-m-d', strtotime($v['apply_time_start']));
  100. $v['apply_time_end'] = date('Y-m-d', strtotime($v['apply_time_end']));
  101. $v['status_text'] = $this->house_status[$v['status']];
  102. $v['status_tag'] = $this->tag_status[$v['status']];
  103. }
  104. $return_data = [
  105. 'articles' => $lists,
  106. 'now_cate' => '房源信息',
  107. ];
  108. return view('app.content.buyhouse.house', $return_data);
  109. }
  110. /**
  111. * 公告
  112. */
  113. public function news()
  114. {
  115. $lists = $this->articleService->list('', 56, '10');
  116. $return_data = [
  117. 'articles' => $lists,
  118. 'now_cate' => '公告',
  119. ];
  120. return view('app.content.buyhouse.news', $return_data);
  121. }
  122. public function detail(Request $request)
  123. {
  124. $id = $request->get('id');
  125. if (empty($id)) {
  126. $back_url = \Illuminate\Support\Facades\URL::previous();
  127. return $this->showMessage('该房源不存在或已删除', $back_url, true, '上一页', '3');
  128. }
  129. //房源信息
  130. $house = TalentHouse::where('id', $id)->first();
  131. if (empty($house)) {
  132. $back_url = \Illuminate\Support\Facades\URL::previous();
  133. return $this->showMessage('该房源不存在或已删除', $back_url, true, '上一页', '3');
  134. }
  135. $house['status_text'] = $this->house_status[$house['status']];
  136. $house['status_tag'] = $this->tag_status[$house['status']];
  137. $house['url'] = route('buyhouse.list', ['id' => $house['id']]);
  138. $house['apply_time'] = date('Y-m-d', strtotime($house['apply_time_start'])) . ' - ' . date('Y-m-d', strtotime($house['apply_time_end']));
  139. $return_data = [
  140. 'info' => $house,
  141. ];
  142. return view('app.content.buyhouse.detail', $return_data);
  143. }
  144. /**
  145. * 报名列表
  146. */
  147. public function list(Request $request)
  148. {
  149. $login = $this->checkLogin();
  150. if ($login) {
  151. return $login;
  152. }
  153. $user_id = auth('web-member')->id();
  154. if (empty($user_id)) {
  155. $back_url = route('buyhouse.login');
  156. return $this->showMessage('登录过期,请先登录', $back_url, true, '上一页', '3');
  157. }
  158. //拉黑
  159. $people = TalentHousePeople::where('user_id', $user_id)->first();
  160. if (!empty($people) && $people['status'] == 2) {
  161. $back_url = \Illuminate\Support\Facades\URL::previous();
  162. return $this->showMessage('由于您不遵守规则,已被拉黑,具体情况请联系有关部门', $back_url, true, '上一页', '3');
  163. }
  164. $id = $request->get('id');
  165. if (empty($id)) {
  166. $back_url = \Illuminate\Support\Facades\URL::previous();
  167. return $this->showMessage('该房源不存在或已删除', $back_url, true, '上一页', '3');
  168. }
  169. //是否报名其他
  170. $sock = TalentHouseApply::where('user_id', $user_id)->where('house_id', '<>', $id)->where('is_sock', 1)->where('is_draft', 2)->first();
  171. if (!empty($sock)) {
  172. $back_url = \Illuminate\Support\Facades\URL::previous();
  173. return $this->showMessage('不可以同时申报多个房源', $back_url, true, '上一页', '3');
  174. }
  175. //房源信息
  176. $house = TalentHouse::where('id', $id)->first();
  177. if (empty($house)) {
  178. $back_url = \Illuminate\Support\Facades\URL::previous();
  179. return $this->showMessage('该房源不存在或已删除', $back_url, true, '上一页', '3');
  180. }
  181. $house['declare_time_text'] = date('Y-m-d', strtotime($house['declare_time']));
  182. $house['status_text'] = $this->house_status[$house['status']];
  183. $house['status_tag'] = $this->tag_status[$house['status']];
  184. $house['apply_time'] = date('Y-m-d', strtotime($house['apply_time_start'])) . ' - ' . date('Y-m-d', strtotime($house['apply_time_end']));
  185. //报名信息
  186. $apply = TalentHouseApply::where('house_id', $id)->where('is_back', 2)->where('user_id', $user_id)->first();
  187. $check = [];
  188. $time = time();
  189. if ($apply) {
  190. if ($house['status'] != 2 && $apply['is_draft'] == 1) {
  191. $back_url = \Illuminate\Support\Facades\URL::previous();
  192. return $this->showMessage('该房源未在申报时间', $back_url, true, '上一页', '3');
  193. }
  194. //审核状态
  195. if ($apply['is_draft'] == 2) {
  196. if ($apply['rs_check_status'] != 2) {
  197. $check['status_text'] = '人社局' . $this->apply_status[$apply['rs_check_status']];
  198. $check['comment'] = $apply['rs_check_status'] == 1 ? '' : $apply['rs_check_comment'];
  199. $check['type'] = $this->check_type[$apply['rs_check_status']];
  200. } elseif ($apply['zj_check_status'] != 2) {
  201. $check['status_text'] = '住建局' . $this->apply_status[$apply['zj_check_status']];
  202. $check['comment'] = $apply['zj_check_status'] == 1 ? '' : $apply['zj_check_comment'];
  203. $check['type'] = $this->check_type[$apply['zj_check_status']];
  204. } else {
  205. $check['title'] = '';
  206. $check['status_text'] = $this->apply_status[$apply['zj_check_status']];
  207. $check['comment'] = '';
  208. $check['type'] = 'success';
  209. }
  210. }
  211. } else {
  212. if ($house['status'] != 2) {
  213. $back_url = \Illuminate\Support\Facades\URL::previous();
  214. return $this->showMessage('该房源未在申报时间', $back_url, true, '上一页', '3');
  215. }
  216. $infos = MemberInfo::where('uid', $user_id)->first();
  217. if (empty($infos['id_card'])) {
  218. $back_url = route('person.resume');
  219. return $this->showMessage('请先填写身份证号', $back_url, true, '上一页', '3');
  220. }
  221. $request_post = [
  222. 'idCards' => [$infos['id_card']],
  223. 'sign' => mb_strtoupper(md5("timestr={$time}&key=rsKVyec52fqEKpk4RRD2TU8fKvPxt6ombKg0qSq1velPQtBHVi")),
  224. 'timeStr' => (string)$time,
  225. ];
  226. $res = https_request('https://rc.jucai.gov.cn/api/dataInterface/findTalentInfoByIdCards', json_encode($request_post), ['Content-Type:application/json']);
  227. $talent = json_decode($res, true);
  228. if (empty($talent['obj'])) {
  229. $back_url = \Illuminate\Support\Facades\URL::previous();
  230. return $this->showMessage('您还未认定人才,暂无申报资格', $back_url, true, '上一页', '3');
  231. }
  232. $talent = $talent['obj'][0];
  233. if ($talent['talentArrange'] > 5) {
  234. $back_url = \Illuminate\Support\Facades\URL::previous();
  235. return $this->showMessage('目前仅支持一到五层次人才申报', $back_url, true, '上一页', '3');
  236. }
  237. if ($talent['type'] > 2) {
  238. $back_url = \Illuminate\Support\Facades\URL::previous();
  239. return $this->showMessage('其他人才暂不支持', $back_url, true, '上一页', '3');
  240. }
  241. $add = [
  242. 'user_id' => $user_id,
  243. 'house_id' => $id,
  244. 'type' => $talent['type'],
  245. 'name' => $talent['name'],
  246. 'mobile' => $talent['phone'],
  247. 'native' => $talent['nativePlace'],
  248. 'email' => $talent['email'],
  249. 'talent_level' => $this->talent_level[$talent['talentArrange']],
  250. 'talent_card_validity' => $talent['activeDate'],
  251. 'talent_tags' => $talent['talentType'],
  252. 'talent_condition' => $talent['identifyCondition'],
  253. 'family' => json_encode([['relation' => '', 'realname' => '', 'idcard' => '']]),
  254. 'certificates' => '[]',
  255. 'marry_prove' => '[]',
  256. 'household_register' => '[]',
  257. 'work_prove' => '[]',
  258. 'created_at' => date('Y-m-d H:i:s'),
  259. 'updated_at' => date('Y-m-d H:i:s'),
  260. ];
  261. $id = TalentHouseApply::insertGetId($add);
  262. $apply = TalentHouseApply::find($id);
  263. //报名人员列表
  264. $memberInfo = MemberInfo::where('uid', $user_id)->first();
  265. if (empty($people)) {
  266. $a = TalentHousePeople::insert([
  267. 'user_id' => $user_id,
  268. 'realname' => $memberInfo['realname'] ?: '',
  269. 'mobile' => $memberInfo['phone'] ?: '',
  270. 'email' => $memberInfo['email'] ?: '',
  271. 'card_t_cn' => $memberInfo['card_t_cn'] ?: 306,
  272. 'id_card' => $memberInfo['id_card'] ?: '',
  273. 'created_at' => date('Y-m-d H:i:s'),
  274. 'updated_at' => date('Y-m-d H:i:s'),
  275. ]);
  276. } else {
  277. TalentHousePeople::where('user_id', $user_id)->update([
  278. 'realname' => $memberInfo['realname'] ?: '',
  279. 'mobile' => $memberInfo['mobile'] ?: '',
  280. 'email' => $memberInfo['email'] ?: '',
  281. 'card_t_cn' => $memberInfo['card_t_cn'] ?: 306,
  282. 'id_card' => $memberInfo['id_card'] ?: '',
  283. 'updated_at' => date('Y-m-d H:i:s'),
  284. ]);
  285. }
  286. }
  287. $apply['family'] = json_decode($apply['family'], true);
  288. $apply['certificates'] = json_decode($apply['certificates'], true);
  289. $apply['marry_prove'] = json_decode($apply['marry_prove'], true);
  290. $apply['household_register'] = json_decode($apply['household_register'], true);
  291. $apply['work_prove'] = json_decode($apply['work_prove'], true);
  292. $apply['checked'] = true;
  293. //是否可填表格
  294. $formDisable = 'true';
  295. if ($apply['is_draft'] == 1) {
  296. //草稿
  297. $formDisable = 'false';
  298. } else {
  299. if ($time < $house['apply_time_end'] && $apply['status'] != 2) {
  300. $formDisable = 'false';
  301. } else {
  302. if ($time < $house['supply_time'] && ($apply['rs_check_status'] == 3 || $apply['zj_check_status'] == 3)) {
  303. $formDisable = 'false';
  304. }
  305. }
  306. }
  307. $return_data = [
  308. 'formDisable' => $formDisable,
  309. 'check' => $check,
  310. 'apply' => json_encode($apply),
  311. 'house' => json_encode($house),
  312. 'module' => ['identification'],
  313. ];
  314. return view('app.content.buyhouse.list', $return_data);
  315. }
  316. /**
  317. * 申报提交
  318. */
  319. public function listPost(Request $request)
  320. {
  321. //数据校验
  322. $data = $request->only(['id', 'certificates', 'marry', 'marry_prove', 'household_register', 'family', 'work_prove', 'street', 'house_condition', 'house_policy']);
  323. $rules = [
  324. 'certificates' => 'required',
  325. 'marry' => 'required',
  326. 'household_register' => 'required',
  327. 'work_prove' => 'required',
  328. 'street' => 'required',
  329. 'house_condition' => 'required',
  330. 'house_policy' => 'required',
  331. ];
  332. $messages = [
  333. 'certificates.required' => '请上传证件信息',
  334. 'marry.required' => '请选择婚姻状况',
  335. 'household_register.required' => '请上传户口本',
  336. 'work_prove.required' => '请上传人才工作单位',
  337. 'street.required' => '请填写所属街道',
  338. 'house_condition.required' => '请填写家庭成员在晋江市行政区域内住房情况',
  339. 'house_policy.required' => '请填写在晋享受政策性住房或相关优惠情况',
  340. ];
  341. $validator = Validator::make($data, $rules, $messages);
  342. if ($validator->fails()) {
  343. $msg = $validator->errors()->all();
  344. return response()->json(['status' => 0, 'msg' => $msg[0]]);
  345. }
  346. if ($data['marry'] > 1 && empty($data['marry_prove'])) {
  347. return response()->json(['status' => 0, 'msg' => '请上传婚姻证明']);
  348. }
  349. //报名信息
  350. $info = TalentHouseApply::find($data['id']);
  351. if (empty($info)) {
  352. return response()->json(['status' => 0, 'msg' => '提交格式有误']);
  353. }
  354. //图片
  355. $images = ['certificates', 'household_register', 'marry_prove', 'work_prove'];
  356. foreach ($images as $image) {
  357. if (!empty($data[$image]) && is_array($data[$image])) {
  358. //删除掉没有成功返回路径的图片
  359. foreach ($data[$image] as $k => $v) {
  360. if (!array_key_exists('response', $v)) {
  361. unset($data[$image][$k]);
  362. }
  363. }
  364. $data[$image] = array_values($data[$image]);
  365. }
  366. }
  367. //更新数据
  368. $info->certificates = json_encode($data['certificates']);
  369. $info->marry = $data['marry'];
  370. if ($data['marry'] > 1) {
  371. $info->marry_prove = json_encode($data['marry_prove']);
  372. }
  373. $info->household_register = json_encode($data['household_register']);
  374. $info->family = json_encode($data['family']);
  375. $info->work_prove = json_encode($data['work_prove']);
  376. $info->street = $data['street'];
  377. $info->house_condition = $data['house_condition'];
  378. $info->house_policy = $data['house_policy'];
  379. $info->status = 1;
  380. //审核状态
  381. if ($info->rs_check_status == 3) {
  382. $info->rs_check_status = 1;
  383. }
  384. if ($info->zj_check_status == 3) {
  385. $info->zj_check_status = 1;
  386. }
  387. if ($info->is_draft == 1) {
  388. $info->is_draft = 2;
  389. }
  390. if ($info->is_sock == 2) {
  391. $info->is_sock = 1;
  392. }
  393. $info->save();
  394. return response()->json(['status' => 1]);
  395. }
  396. /**
  397. * 撤消
  398. */
  399. public function back(Request $request)
  400. {
  401. $id = $request->get('id');
  402. if (empty($id)) {
  403. return response()->json(['status' => 1]);
  404. }
  405. $apply = TalentHouseApply::find($id);
  406. if (empty($apply) || $apply['user_id'] != auth('web-member')->id() || $apply['is_back'] == 1) {
  407. return response()->json(['status' => 1]);
  408. }
  409. if ($apply['status'] == 2) {
  410. return response()->json(['status' => 0, 'msg' => '已通过审核的申报无法撤消']);
  411. }
  412. $house = TalentHouse::find($apply['house_id']);
  413. if (strtotime($house['apply_time_end']) > time()) {
  414. return response()->json(['status' => 0, 'msg' => '报名结束的申报无法撤消']);
  415. }
  416. $apply->is_back = 1;
  417. $apply->is_sock = 2;
  418. $apply->save();
  419. return response()->json(['status' => 1]);
  420. }
  421. /**
  422. * 图片上传
  423. */
  424. public function upload(Request $request)
  425. {
  426. header('Access-Control-Allow-Origin:*');
  427. header('Access-Control-Allow-Methods:GET,POST,PUT,DELETE');
  428. header('Access-Control-Allow-Headers:Origin, Content-Type, Cookie, Accept, X-CSRF-TOKEN');
  429. header('Access-Control-Allow-Credentials:true');
  430. $file = $request->file('file');
  431. if ($file->isValid()) { //判断文件是否存在
  432. //获取文件的扩展名
  433. $ext = $file->getClientOriginalExtension();
  434. if (!in_array(strtolower($ext), ['jpg', 'jpeg', 'png', 'doc', 'docx', 'pdf'])) {
  435. $res['status'] = 0;
  436. $res['msg'] = '文件格式不正确';
  437. } else {
  438. //获取文件的绝对路径
  439. $path = $file->getRealPath();
  440. $oldname = $file->getClientOriginalName();
  441. //定义文件名
  442. $filename = 'storage/buyhouse/' . uniqid() . mt_rand(10000, 99999) . '.' . $ext;
  443. //存储文件。disk里面的public。总的来说,就是调用disk模块里的public配置
  444. Storage::disk('public')->put($filename, file_get_contents($path));
  445. $res['status'] = 1;
  446. $res['filename'] = $oldname;
  447. $res['path'] = "/storage/" . $filename;
  448. $res['msg'] = '上传成功';
  449. }
  450. } else {
  451. $res['status'] = 0;
  452. $res['msg'] = '上传失败';
  453. }
  454. return response()->json($res);
  455. }
  456. /**
  457. * 登录状态
  458. */
  459. private function checkLogin()
  460. {
  461. $user_id = auth('web-member')->id();
  462. if (empty($user_id)) {
  463. return redirect(route('buyhouse.login'));
  464. }
  465. return false;
  466. }
  467. }