BuyhouseController.php 16 KB

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