BuyhouseController.php 14 KB

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