BuyhouseController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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['is_draft'] == 2) {
  127. if ($apply['rs_check_status'] != 2) {
  128. $check['status_text'] = '人社局' . $this->apply_status[$apply['rs_check_status']];
  129. $check['comment'] = $apply['rs_check_status'] == 1 ? '' : $apply['rs_check_comment'];
  130. $check['type'] = $this->check_type[$apply['rs_check_status']];
  131. } elseif ($apply['zj_check_status'] != 2) {
  132. $check['status_text'] = '住建局' . $this->apply_status[$apply['zj_check_status']];
  133. $check['comment'] = $apply['zj_check_status'] == 1 ? '' : $apply['zj_check_comment'];
  134. $check['type'] = $this->check_type[$apply['zj_check_status']];
  135. } else {
  136. $check['title'] = '';
  137. $check['status_text'] = $this->apply_status[$apply['zj_check_status']];
  138. $check['comment'] = '';
  139. $check['type'] = 'success';
  140. }
  141. }
  142. } else {
  143. $time = time();
  144. $resume = Resume::where('uid', $user_id)->where('def', 1)->first();
  145. if (empty($resume) || empty($resume['idcard'])) {
  146. $back_url = route('person.resume');
  147. return $this->showMessage('请先填写一份简历', $back_url, true, '上一页', '3');
  148. }
  149. $request_post = [
  150. 'idCards' => [$resume['idcard']],
  151. 'sign' => mb_strtoupper(md5("timestr={$time}&key=rsKVyec52fqEKpk4RRD2TU8fKvPxt6ombKg0qSq1velPQtBHVi")),
  152. 'timeStr' => (string)$time,
  153. ];
  154. $res = https_request('https://rc.jucai.gov.cn/api/dataInterface/findTalentInfoByIdCards', json_encode($request_post), ['Content-Type:application/json']);
  155. $talent = json_decode($res, true);
  156. if (empty($talent['obj'])) {
  157. $back_url = \Illuminate\Support\Facades\URL::previous();
  158. return $this->showMessage('您还未认定人才,暂无申报资格', $back_url, true, '上一页', '3');
  159. }
  160. $talent = $talent['obj'][0];
  161. $add = [
  162. 'user_id' => $user_id,
  163. 'house_id' => $id,
  164. 'name' => $talent['name'],
  165. 'mobile' => $talent['phone'],
  166. 'native' => $talent['nativePlace'],
  167. 'email' => $talent['email'],
  168. 'talent_level' => $this->talent_level[$talent['talentArrange']],
  169. 'talent_card_validity' => $talent['activeDate'],
  170. 'talent_tags' => '',
  171. 'talent_condition' => $talent['identifyCondition'],
  172. 'family' => json_encode([['relation' => '', 'realname' => '', 'idcard' => '']]),
  173. 'certificates' => '[]',
  174. 'marry_prove' => '[]',
  175. 'household_register' => '[]',
  176. 'work_prove' => '[]',
  177. 'created_at' => date('Y-m-d H:i:s'),
  178. 'updated_at' => date('Y-m-d H:i:s'),
  179. ];
  180. $id = TalentHouseApply::insertGetId($add);
  181. $apply = TalentHouseApply::find($id);
  182. }
  183. $apply['family'] = json_decode($apply['family'], true);
  184. $apply['certificates'] = json_decode($apply['certificates'], true);
  185. $apply['marry_prove'] = json_decode($apply['marry_prove'], true);
  186. $apply['household_register'] = json_decode($apply['household_register'], true);
  187. $apply['work_prove'] = json_decode($apply['work_prove'], true);
  188. $apply['checked'] = true;
  189. $return_data = [
  190. 'check' => $check,
  191. 'apply' => json_encode($apply),
  192. 'house' => json_encode($house),
  193. 'module' => ['identification'],
  194. ];
  195. return view('app.content.buyhouse.list', $return_data);
  196. }
  197. public function listPost(Request $request)
  198. {
  199. //数据校验
  200. $data = $request->only(['id', 'certificates', 'marry', 'marry_prove', 'household_register', 'family', 'work_prove', 'street', 'house_condition', 'house_policy']);
  201. $rules = [
  202. 'certificates' => 'required',
  203. 'marry' => 'required',
  204. 'household_register' => 'required',
  205. 'work_prove' => 'required',
  206. 'street' => 'required',
  207. 'house_condition' => 'required',
  208. 'house_policy' => 'required',
  209. ];
  210. $messages = [
  211. 'certificates.required' => '请上传证件信息',
  212. 'marry.required' => '请选择婚姻状况',
  213. 'household_register.required' => '请上传户口本',
  214. 'work_prove.required' => '请上传人才工作单位',
  215. 'street.required' => '请填写所属街道',
  216. 'house_condition.required' => '请填写家庭成员在晋江市行政区域内住房情况',
  217. 'house_policy.required' => '请填写在晋享受政策性住房或相关优惠情况',
  218. ];
  219. $validator = Validator::make($data, $rules, $messages);
  220. if ($validator->fails()) {
  221. $msg = $validator->errors()->all();
  222. return response()->json(['status' => 0, 'msg' => $msg[0]]);
  223. }
  224. if ($data['marry'] > 1 && empty($data['marry_prove'])) {
  225. return response()->json(['status' => 0, 'msg' => '请上传婚姻证明']);
  226. }
  227. //报名信息
  228. $info = TalentHouseApply::find($data['id']);
  229. if (empty($info)) {
  230. return response()->json(['status' => 0, 'msg' => '提交格式有误']);
  231. }
  232. //图片
  233. $images = ['certificates', 'household_register', 'marry_prove', 'work_prove'];
  234. foreach ($images as $image) {
  235. if (is_array($data[$image])) {
  236. //删除掉没有成功返回路径的图片
  237. foreach ($data[$image] as $k => $v) {
  238. if (!array_key_exists('response', $v)) {
  239. unset($data[$image][$k]);
  240. }
  241. }
  242. $data[$image] = array_values($data[$image]);
  243. }
  244. }
  245. //更新数据
  246. $info->certificates = json_encode($data['certificates']);
  247. $info->marry = $data['marry'];
  248. if ($data['marry'] > 1) {
  249. $info->marry_prove = json_encode($data['marry_prove']);
  250. }
  251. $info->household_register = json_encode($data['household_register']);
  252. $info->family = json_encode($data['family']);
  253. $info->work_prove = json_encode($data['work_prove']);
  254. $info->street = $data['street'];
  255. $info->house_condition = $data['house_condition'];
  256. $info->house_policy = $data['house_policy'];
  257. //审核状态
  258. if ($info->rs_check_status == 3) {
  259. $info->rs_check_status = 1;
  260. }
  261. if ($info->zj_check_status == 3) {
  262. $info->zj_check_status = 1;
  263. }
  264. if ($info->is_draft == 1) {
  265. $info->is_draft = 2;
  266. }
  267. $info->save();
  268. return response()->json(['status' => 1]);
  269. }
  270. public function upload(Request $request)
  271. {
  272. header('Access-Control-Allow-Origin:*');
  273. header('Access-Control-Allow-Methods:GET,POST,PUT,DELETE');
  274. header('Access-Control-Allow-Headers:Origin, Content-Type, Cookie, Accept, X-CSRF-TOKEN');
  275. header('Access-Control-Allow-Credentials:true');
  276. $file = $request->file('file');
  277. if ($file->isValid()) { //判断文件是否存在
  278. //获取文件的扩展名
  279. $ext = $file->getClientOriginalExtension();
  280. if (!in_array(strtolower($ext), ['jpg', 'jpeg', 'png', 'doc', 'docx', 'pdf'])) {
  281. $res['status'] = 0;
  282. $res['msg'] = '文件格式不正确';
  283. } else {
  284. //获取文件的绝对路径
  285. $path = $file->getRealPath();
  286. $oldname = $file->getClientOriginalName();
  287. //定义文件名
  288. $filename = 'storage/buyhouse/' . uniqid() . mt_rand(10000, 99999) . '.' . $ext;
  289. //存储文件。disk里面的public。总的来说,就是调用disk模块里的public配置
  290. Storage::disk('public')->put($filename, file_get_contents($path));
  291. $res['status'] = 1;
  292. $res['filename'] = $oldname;
  293. $res['path'] = "/storage/" . $filename;
  294. $res['msg'] = '上传成功';
  295. }
  296. } else {
  297. $res['status'] = 0;
  298. $res['msg'] = '上传失败';
  299. }
  300. return response()->json($res);
  301. }
  302. /**
  303. * 登录状态
  304. */
  305. private function checkLogin()
  306. {
  307. $user_id = auth('web-member')->id();
  308. if (empty($user_id)) {
  309. return redirect(route('buyhouse.login'));
  310. }
  311. return false;
  312. }
  313. }