BuyhouseController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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\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['declare_time_text'] = date('Y-m-d', strtotime($v['declare_time']));
  45. $v['status_text'] = $this->house_status[$v['status']];
  46. $v['status_tag'] = $this->tag_status[$v['status']];
  47. $v['url'] = route('buyhouse.list', ['id' => $v['id']]);
  48. }
  49. $return_data['house'] = $house;
  50. //新闻
  51. $news = Article::where('type_id', 56)->where('is_display', 1)->select(['id', 'title', 'updated_at'])->orderBy('list_order', 'desc')->limit(10)->get();
  52. foreach ($news as $v) {
  53. $v['updated_at_text'] = date('Y-m-d', strtotime($v['updated_at']));
  54. $v['url'] = route('news.show', ['id' => $v['id']]);
  55. }
  56. $return_data['news'] = $news;
  57. //我的申报
  58. if ($user_id > 0) {
  59. $apply = TalentHouseApply::with('house')
  60. ->select(['id', 'house_id', 'status'])
  61. ->where('is_draft', 2)
  62. ->where('user_id', $user_id)
  63. ->get();
  64. foreach ($apply as $v) {
  65. $v['status_text'] = $this->apply_status[$v['status']];
  66. $v['status_tag'] = $this->tag_status[$v['status']];
  67. $v['url'] = route('buyhouse.list', ['id' => $v['house_id']]);
  68. }
  69. $return_data['apply'] = $apply;
  70. }
  71. return view('app.content.buyhouse.login', $return_data);
  72. }
  73. /**
  74. * 房源信息
  75. */
  76. public function house(Request $request)
  77. {
  78. $lists = TalentHouse::orderByRaw(DB::raw("FIELD(status,2,1,3)"))->paginate(10);
  79. foreach ($lists as $v) {
  80. $v['status_text'] = $this->house_status[$v['status']];
  81. $v['status_tag'] = $this->tag_status[$v['status']];
  82. }
  83. $return_data = [
  84. 'articles' => $lists,
  85. 'now_cate' => '房源信息',
  86. ];
  87. return view('app.content.buyhouse.house', $return_data);
  88. }
  89. /**
  90. * 公告
  91. */
  92. public function news()
  93. {
  94. $lists = $this->articleService->list('', 56, '10');
  95. $return_data = [
  96. 'articles' => $lists,
  97. 'now_cate' => '公告',
  98. ];
  99. return view('app.content.buyhouse.news', $return_data);
  100. }
  101. /**
  102. * 报名列表
  103. */
  104. public function list(Request $request)
  105. {
  106. $login = $this->checkLogin();
  107. if ($login) {
  108. return $login;
  109. }
  110. $user_id = auth('web-member')->id();
  111. $id = $request->get('id');
  112. if (empty($id)) {
  113. $back_url = \Illuminate\Support\Facades\URL::previous();
  114. return $this->showMessage('该房源不存在或已删除', $back_url, true, '上一页', '3');
  115. }
  116. //房源信息
  117. $house = TalentHouse::where('id', $id)->first();
  118. if (empty($house)) {
  119. $back_url = \Illuminate\Support\Facades\URL::previous();
  120. return $this->showMessage('该房源不存在或已删除', $back_url, true, '上一页', '3');
  121. }
  122. $house['declare_time_text'] = date('Y-m-d', strtotime($house['declare_time']));
  123. $house['status_text'] = $this->house_status[$house['status']];
  124. $house['status_tag'] = $this->tag_status[$house['status']];
  125. $house['apply_time'] = date('Y-m-d', strtotime($house['apply_time_start'])) . ' - ' . date('Y-m-d', strtotime($house['apply_time_end']));
  126. //报名信息
  127. $apply = TalentHouseApply::where('house_id', $id)->where('user_id', $user_id)->first();
  128. $check = [];
  129. if ($apply) {
  130. if ($house['status'] != 2 && $apply['is_draft'] == 1) {
  131. $back_url = \Illuminate\Support\Facades\URL::previous();
  132. return $this->showMessage('该房源未在申报时间', $back_url, true, '上一页', '3');
  133. }
  134. //审核状态
  135. if ($apply['is_draft'] == 2) {
  136. if ($apply['rs_check_status'] != 2) {
  137. $check['status_text'] = '人社局' . $this->apply_status[$apply['rs_check_status']];
  138. $check['comment'] = $apply['rs_check_status'] == 1 ? '' : $apply['rs_check_comment'];
  139. $check['type'] = $this->check_type[$apply['rs_check_status']];
  140. } elseif ($apply['zj_check_status'] != 2) {
  141. $check['status_text'] = '住建局' . $this->apply_status[$apply['zj_check_status']];
  142. $check['comment'] = $apply['zj_check_status'] == 1 ? '' : $apply['zj_check_comment'];
  143. $check['type'] = $this->check_type[$apply['zj_check_status']];
  144. } else {
  145. $check['title'] = '';
  146. $check['status_text'] = $this->apply_status[$apply['zj_check_status']];
  147. $check['comment'] = '';
  148. $check['type'] = 'success';
  149. }
  150. }
  151. } else {
  152. if ($house['status'] != 2) {
  153. $back_url = \Illuminate\Support\Facades\URL::previous();
  154. return $this->showMessage('该房源未在申报时间', $back_url, true, '上一页', '3');
  155. }
  156. $time = time();
  157. $resume = Resume::where('uid', $user_id)->where('def', 1)->first();
  158. if (empty($resume)) {
  159. $back_url = route('person.resume');
  160. return $this->showMessage('请先填写一份简历', $back_url, true, '上一页', '3');
  161. }
  162. $infos = MemberInfo::where('uid', $user_id)->first();
  163. if (empty($infos['id_card'])) {
  164. $back_url = route('person.resume');
  165. return $this->showMessage('请先填写身份证号', $back_url, true, '上一页', '3');
  166. }
  167. $request_post = [
  168. 'idCards' => [$infos['id_card']],
  169. 'sign' => mb_strtoupper(md5("timestr={$time}&key=rsKVyec52fqEKpk4RRD2TU8fKvPxt6ombKg0qSq1velPQtBHVi")),
  170. 'timeStr' => (string)$time,
  171. ];
  172. $res = https_request('https://rc.jucai.gov.cn/api/dataInterface/findTalentInfoByIdCards', json_encode($request_post), ['Content-Type:application/json']);
  173. $talent = json_decode($res, true);
  174. if (empty($talent['obj'])) {
  175. $back_url = \Illuminate\Support\Facades\URL::previous();
  176. return $this->showMessage('您还未认定人才,暂无申报资格', $back_url, true, '上一页', '3');
  177. }
  178. $talent = $talent['obj'][0];
  179. if ($talent['type'] != 1) {
  180. $back_url = \Illuminate\Support\Facades\URL::previous();
  181. return $this->showMessage('目前仅支持晋江高层次人才申报', $back_url, true, '上一页', '3');
  182. }
  183. $add = [
  184. 'user_id' => $user_id,
  185. 'house_id' => $id,
  186. 'name' => $talent['name'],
  187. 'mobile' => $talent['phone'],
  188. 'native' => $talent['nativePlace'],
  189. 'email' => $talent['email'],
  190. 'talent_level' => $this->talent_level[$talent['talentArrange']],
  191. 'talent_card_validity' => $talent['activeDate'],
  192. 'talent_tags' => $talent['talentType'],
  193. 'talent_condition' => $talent['identifyCondition'],
  194. 'family' => json_encode([['relation' => '', 'realname' => '', 'idcard' => '']]),
  195. 'certificates' => '[]',
  196. 'marry_prove' => '[]',
  197. 'household_register' => '[]',
  198. 'work_prove' => '[]',
  199. 'created_at' => date('Y-m-d H:i:s'),
  200. 'updated_at' => date('Y-m-d H:i:s'),
  201. ];
  202. $id = TalentHouseApply::insertGetId($add);
  203. $apply = TalentHouseApply::find($id);
  204. }
  205. $apply['family'] = json_decode($apply['family'], true);
  206. $apply['certificates'] = json_decode($apply['certificates'], true);
  207. $apply['marry_prove'] = json_decode($apply['marry_prove'], true);
  208. $apply['household_register'] = json_decode($apply['household_register'], true);
  209. $apply['work_prove'] = json_decode($apply['work_prove'], true);
  210. $apply['checked'] = true;
  211. //是否可填表格
  212. $formDisable = 'true';
  213. if ($house['status'] == 2) {
  214. if ($apply['is_draft'] == 1) {
  215. $formDisable = 'false';
  216. }
  217. }
  218. if ($apply['rs_check_status'] == 3 || $apply['zj_check_status'] == 3) {
  219. $formDisable = 'false';
  220. }
  221. $return_data = [
  222. 'formDisable' => $formDisable,
  223. 'check' => $check,
  224. 'apply' => json_encode($apply),
  225. 'house' => json_encode($house),
  226. 'module' => ['identification'],
  227. ];
  228. return view('app.content.buyhouse.list', $return_data);
  229. }
  230. public function listPost(Request $request)
  231. {
  232. //数据校验
  233. $data = $request->only(['id', 'certificates', 'marry', 'marry_prove', 'household_register', 'family', 'work_prove', 'street', 'house_condition', 'house_policy']);
  234. $rules = [
  235. 'certificates' => 'required',
  236. 'marry' => 'required',
  237. 'household_register' => 'required',
  238. 'work_prove' => 'required',
  239. 'street' => 'required',
  240. 'house_condition' => 'required',
  241. 'house_policy' => 'required',
  242. ];
  243. $messages = [
  244. 'certificates.required' => '请上传证件信息',
  245. 'marry.required' => '请选择婚姻状况',
  246. 'household_register.required' => '请上传户口本',
  247. 'work_prove.required' => '请上传人才工作单位',
  248. 'street.required' => '请填写所属街道',
  249. 'house_condition.required' => '请填写家庭成员在晋江市行政区域内住房情况',
  250. 'house_policy.required' => '请填写在晋享受政策性住房或相关优惠情况',
  251. ];
  252. $validator = Validator::make($data, $rules, $messages);
  253. if ($validator->fails()) {
  254. $msg = $validator->errors()->all();
  255. return response()->json(['status' => 0, 'msg' => $msg[0]]);
  256. }
  257. if ($data['marry'] > 1 && empty($data['marry_prove'])) {
  258. return response()->json(['status' => 0, 'msg' => '请上传婚姻证明']);
  259. }
  260. //报名信息
  261. $info = TalentHouseApply::find($data['id']);
  262. if (empty($info)) {
  263. return response()->json(['status' => 0, 'msg' => '提交格式有误']);
  264. }
  265. //图片
  266. $images = ['certificates', 'household_register', 'marry_prove', 'work_prove'];
  267. foreach ($images as $image) {
  268. if (is_array($data[$image])) {
  269. //删除掉没有成功返回路径的图片
  270. foreach ($data[$image] as $k => $v) {
  271. if (!array_key_exists('response', $v)) {
  272. unset($data[$image][$k]);
  273. }
  274. }
  275. $data[$image] = array_values($data[$image]);
  276. }
  277. }
  278. //更新数据
  279. $info->certificates = json_encode($data['certificates']);
  280. $info->marry = $data['marry'];
  281. if ($data['marry'] > 1) {
  282. $info->marry_prove = json_encode($data['marry_prove']);
  283. }
  284. $info->household_register = json_encode($data['household_register']);
  285. $info->family = json_encode($data['family']);
  286. $info->work_prove = json_encode($data['work_prove']);
  287. $info->street = $data['street'];
  288. $info->house_condition = $data['house_condition'];
  289. $info->house_policy = $data['house_policy'];
  290. $info->status = 1;
  291. //审核状态
  292. if ($info->rs_check_status == 3) {
  293. $info->rs_check_status = 1;
  294. }
  295. if ($info->zj_check_status == 3) {
  296. $info->zj_check_status = 1;
  297. }
  298. if ($info->is_draft == 1) {
  299. $info->is_draft = 2;
  300. }
  301. $info->save();
  302. return response()->json(['status' => 1]);
  303. }
  304. public function upload(Request $request)
  305. {
  306. header('Access-Control-Allow-Origin:*');
  307. header('Access-Control-Allow-Methods:GET,POST,PUT,DELETE');
  308. header('Access-Control-Allow-Headers:Origin, Content-Type, Cookie, Accept, X-CSRF-TOKEN');
  309. header('Access-Control-Allow-Credentials:true');
  310. $file = $request->file('file');
  311. if ($file->isValid()) { //判断文件是否存在
  312. //获取文件的扩展名
  313. $ext = $file->getClientOriginalExtension();
  314. if (!in_array(strtolower($ext), ['jpg', 'jpeg', 'png', 'doc', 'docx', 'pdf'])) {
  315. $res['status'] = 0;
  316. $res['msg'] = '文件格式不正确';
  317. } else {
  318. //获取文件的绝对路径
  319. $path = $file->getRealPath();
  320. $oldname = $file->getClientOriginalName();
  321. //定义文件名
  322. $filename = 'storage/buyhouse/' . uniqid() . mt_rand(10000, 99999) . '.' . $ext;
  323. //存储文件。disk里面的public。总的来说,就是调用disk模块里的public配置
  324. Storage::disk('public')->put($filename, file_get_contents($path));
  325. $res['status'] = 1;
  326. $res['filename'] = $oldname;
  327. $res['path'] = "/storage/" . $filename;
  328. $res['msg'] = '上传成功';
  329. }
  330. } else {
  331. $res['status'] = 0;
  332. $res['msg'] = '上传失败';
  333. }
  334. return response()->json($res);
  335. }
  336. /**
  337. * 登录状态
  338. */
  339. private function checkLogin()
  340. {
  341. $user_id = auth('web-member')->id();
  342. if (empty($user_id)) {
  343. return redirect(route('buyhouse.login'));
  344. }
  345. return false;
  346. }
  347. }