BuyhouseController.php 13 KB

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