BuyhouseController.php 22 KB

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