House.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <?php
  2. namespace app\enterprise\controller;
  3. use app\enterprise\common\EnterpriseController;
  4. use think\facade\Db;
  5. use think\facade\Log;
  6. use app\common\api\EnterpriseApi;
  7. use app\common\api\TalentLogApi;
  8. use think\exception\ValidateException;
  9. use app\common\state\ProjectState;
  10. use app\common\api\BatchApi;
  11. use app\common\api\HouseApi;
  12. use app\common\model\TalentLog;
  13. use app\common\api\DictApi;
  14. /**
  15. * Description of House
  16. * 购房补贴
  17. * @author sgq
  18. */
  19. class House extends EnterpriseController {
  20. public function index() {
  21. return view("", ['type' => session("user")['type']]);
  22. }
  23. public function list() {
  24. $params = $this->request;
  25. $order = trim($params["order"]) ?: "desc";
  26. $offset = trim($params["offset"]) ?: 0;
  27. $limit = trim($params["limit"]) ?: 10;
  28. $where = [];
  29. $where[] = ["type", "=", $this->user["type"]];
  30. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  31. if ($params["year"]) {
  32. $where[] = ["year", "=", $params["year"]];
  33. }
  34. if (\StrUtil::isNotEmpAndNull($params["name"])) {
  35. $where[] = ["name", "like", "%" . $params["name"] . "%"];
  36. }
  37. if (\StrUtil::isNotEmpAndNull($params["idCard"])) {
  38. $where[] = ["idCard", "like", "%" . $params["idCard"] . "%"];
  39. }
  40. if ($params["talentArrange"]) {
  41. $where[] = ["talentArrange", "=", $params["talentArrange"]];
  42. }
  43. if (\StrUtil::isNotEmpAndNull($params["spouseName"])) {
  44. $where[] = ["spouseName", "like", "%" . $params["spouseName"] . "%"];
  45. }
  46. if (\StrUtil::isNotEmpAndNull($params["spouseIdcard"])) {
  47. $where[] = ["spouseIdcard", "like", "%" . $params["spouseIdcard"] . "%"];
  48. }
  49. if (\StrUtil::isNotEmpAndNull($params["childName"])) {
  50. $where[] = ["childName", "like", "%" . $params["childName"] . "%"];
  51. }
  52. if (\StrUtil::isNotEmpAndNull($params["childIdCard"])) {
  53. $where[] = ["childIdCard", "like", "%" . $params["childIdCard"] . "%"];
  54. }
  55. if ($params["marryStatus"]) {
  56. $where[] = ["marryStatus", "=", $params["marryStatus"]];
  57. }
  58. $count = Db::table("un_housepurchase")->where($where)->count();
  59. $list = Db::table("un_housepurchase")->where($where)->limit($offset, $limit)->order("createTime $order")->select()->toArray();
  60. //获取字典表婚姻状态
  61. $marryMap = DictApi::selectByParentCode("marry_status");
  62. $cardTypeMap = DictApi::selectByParentCode("card_type");
  63. $streetMap = DictApi::selectByParentCode("street");
  64. $levelMap = DictApi::selectByParentCode("talent_arrange");
  65. $whrCondition = [];
  66. $whrCondition[] = ["type", "=", $this->user["type"]];
  67. $conditionMap = \app\common\model\TalentCondition::where($whrCondition)->column("name", "id");
  68. foreach ($list as &$item) {
  69. $item["marryStatusName"] = $marryMap[$item["marryStatus"]];
  70. $item["cardTypeName"] = $cardTypeMap[$item["cardType"]];
  71. $item["spouseCardTypeName"] = $cardTypeMap[$item["spouseCardType"]];
  72. $item["childCardTypeName"] = $cardTypeMap[$item["childCardType"]];
  73. $item["streetName"] = $streetMap[$item["street"]];
  74. $item["talentArrangeName"] = $levelMap[$item["talentArrange"]];
  75. $item["identifyConditionCH"] = $conditionMap[$item["identifyCondition"]];
  76. }unset($item);
  77. return json(["rows" => $list, "total" => $count]);
  78. }
  79. /**
  80. * 申请
  81. */
  82. public function apply(\think\Request $request) {
  83. $param = $request->param();
  84. $id = isset($param["id"]) ? $param["id"] : 0;
  85. $vars = [];
  86. if ($id) {
  87. $info = HouseApi::getInfoById($id);
  88. $childrenList = HouseApi::getChildren($id);
  89. $houseInfo = HouseApi::getHouseInfo($info["idCard"]);
  90. $dicts = DictApi::selectByParentCode("card_type");
  91. $vars["dicts"] = $dicts;
  92. $vars["row"] = $info;
  93. $vars["hand"] = $houseInfo ? 2 : 1;
  94. $vars["childrenList"] = $childrenList;
  95. }
  96. if ($request->isPost()) {
  97. return $this->save($info, $request);
  98. }
  99. $batch = $info["year"] ?: BatchApi::getValidBatch(ProjectState::HOUSE, $this->user["type"])["batch"];
  100. $vars["year"] = $batch;
  101. $vars["type"] = $this->user["type"];
  102. return view("", $vars);
  103. }
  104. public function detail(\think\Request $request) {
  105. $info = HouseApi::getInfoById($id);
  106. $childrenList = HouseApi::getChildren($id);
  107. $dicts = DictApi::selectByParentCode("card_type");
  108. $vars["dicts"] = $dicts;
  109. $vars["row"] = $info;
  110. $vars["childrenList"] = $childrenList;
  111. $vars["type"] = $this->user["type"];
  112. return view("", $vars);
  113. }
  114. private function other_validate($info) {
  115. $responseObj = new \stdClass();
  116. /* 校验姓名是否与人才库一致 */
  117. $where = [];
  118. $where[] = ["checkState", ">=", \app\common\api\TalentState::REVERIFY_PASS];
  119. $where[] = ["checkState", "not in", [\app\common\api\TalentState::REVERIFY_REJECT, \app\common\api\TalentState::REVERIFY_FAIL]];
  120. $where[] = ["card_number", "=", $info["idCard"]];
  121. $talentInfo = Db::table("new_talent_info")->where($where)->order("createTime desc")->find();
  122. if ($talentInfo && $talentInfo["name"] != $info["name"]) {
  123. $responseObj->msg = "该证件号码的姓名与人才库姓名不匹配!";
  124. return $responseObj;
  125. }
  126. $year = substr($info["year"], 0, 4);
  127. /* 查询当前批次审核通过的数量以及当前批次未审核完成的数量 */
  128. $where = [];
  129. $where[] = ["year", "like", "{$year}%"];
  130. $where[] = ["idCard", "=", $info["idCard"]];
  131. $where[] = ["checkState", "<>", LaState::LA_NOTPASS];
  132. if ($info["id"]) {
  133. $where[] = ["id", "<>", $info["id"]];
  134. }
  135. $nowYearApplyCount = LaModel::where($where)->count();
  136. if ($nowYearApplyCount > 0) {
  137. $responseObj->msg = "不能重复申报";
  138. return $responseObj;
  139. }
  140. if (!$info["id"]) {
  141. $passYears = CommonLaApi::getPassYearsByIdCard($info["idCard"]);
  142. if (in_array($year, $passYears)) {
  143. return $responseObj->msg = "您今年度已经申报过了,每年度仅能享受一次生活补贴!";
  144. }
  145. if (count($passYears) >= 3) {
  146. return $responseObj->msg = "一个人最多享受三次!";
  147. }
  148. }
  149. $responseObj->code = 200;
  150. return $responseObj;
  151. }
  152. private function validateIsEdit($checkState) {
  153. $responseObj = new \stdClass();
  154. if ($checkState != LaState::LA_SAVE && $checkState != LaState::LA_BEFORE_REJECT && $checkState != LaState::LA_FIRST_REJECT) {
  155. if ($checkState == LaState::LA_NOTPASS) {
  156. $responseObj->msg = "您的申报审核不通过,无法操作";
  157. } else if ($checkState >= LaState::LA_PASS) {
  158. $responseObj->msg = "您的申报已审核通过,无法操作";
  159. } else {
  160. $responseObj->msg = "您的申报正在审核中,请耐心等待";
  161. }
  162. $responseObj->code = 500;
  163. return $responseObj;
  164. }
  165. $responseObj->code = 200;
  166. return $responseObj;
  167. }
  168. /**
  169. * 提交表单
  170. */
  171. public function submitToCheck() {
  172. try {
  173. $id = $this->request["id"];
  174. $info = CommonLaApi::getInfoById($id);
  175. if (!$info) {
  176. throw new ValidateException("提交审核失败,请先填写基础信息");
  177. }
  178. if ($info["enterpriseId"] != $this->user["uid"]) {
  179. throw new ValidateException("没有对应的人才认定申报信息");
  180. }
  181. $batch = BatchApi::checkBatchValid(["type" => ProjectState::LIVINGALLOWANCE, "year" => $info["year"], "first_submit_time" => $info["firstSubmitTime"]], $this->user["type"]);
  182. if ($batch["code"] != 200) {
  183. throw new ValidateException($batch["msg"]);
  184. }
  185. $response = $this->validateIsEdit($info["checkState"]);
  186. if ($response->code != 200) {
  187. throw new ValidateException($response->msg);
  188. }
  189. validate(LivingAllowanceValidator::class)->check($info);
  190. $response = $this->other_validate($info);
  191. if ($response->code != 200) {
  192. throw new ValidateException($response->msg);
  193. }
  194. $where = [];
  195. $where[] = ["mainId", "=", $id];
  196. $where[] = ["type", "=", ProjectState::LIVINGALLOWANCE];
  197. $uploadedFileTypes = Db::table("new_talent_file")->where($where)->column("distinct typeId");
  198. $where = [];
  199. $where[] = ["project", "=", ProjectState::LIVINGALLOWANCE];
  200. $where[] = ["type", "=", $this->user["type"]];
  201. $where[] = ["must", "=", 1];
  202. $where[] = ["active", "=", 1];
  203. $where[] = ["delete", "=", 0];
  204. $where[] = ["id", "not in", $uploadedFileTypes];
  205. $unUploadfiletypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  206. if ($unUploadfiletypes) {
  207. $msg = "以下附件为必传:<br>";
  208. foreach ($unUploadfiletypes as $ft) {
  209. $msg .= "<span style='color:red;'>*</span>" . $ft["name"] . "<br>";
  210. }
  211. throw new ValidateException($msg);
  212. }
  213. $data["id"] = $id;
  214. $data["checkState"] = LaState::LA_NEED_FIRST_CHECK;
  215. if (!$info["firstSubmitTime"]) {
  216. $data["firstSubmitTime"] = date("Y-m-d H:i:s");
  217. }
  218. $data["newSubmitTime"] = date("Y-m-d H:i:s");
  219. $data["checkMsg"] = "";
  220. $data["files"] = "";
  221. $data["fields"] = "";
  222. $res = LaModel::update($data);
  223. if ($res) {
  224. $user = session("user");
  225. $log["id"] = getStringId();
  226. $log["active"] = 1;
  227. $log["state"] = 1;
  228. $log["step"] = 0;
  229. $log["stateChange"] = LaState::getStateDesc($info["checkState"]) . "->" . LaState::getStateDesc($data["checkState"]);
  230. $log["type"] = ProjectState::LIVINGALLOWANCE;
  231. $log["mainId"] = $id;
  232. $log["description"] = "确认提交审核";
  233. $log["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  234. $log["createTime"] = date("Y-m-d H:i:s");
  235. TalentLog::create($log);
  236. return json(["code" => 200, "msg" => "提交审核成功"]);
  237. }
  238. throw new ValidateException("提交审核失败");
  239. } catch (ValidateException $e) {
  240. $responseObj = new \stdClass();
  241. $responseObj->code = 500;
  242. $responseObj->msg = $e->getMessage();
  243. return json($responseObj);
  244. } catch (\think\Exception $e) {
  245. $res = ["code" => 500, "msg" => "发生预料外错误,请联系管理员处理,错误代码:" . $e->getCode()];
  246. $logInfo = [
  247. "enterprise_id" => $this->user["uid"],
  248. "data" => $data,
  249. "controller" => $this->request->controller(),
  250. "action" => $this->request->action(),
  251. "errCode" => $e->getCode(),
  252. "errMsg" => $e->getMessage()
  253. ];
  254. Log::write($logInfo, "error");
  255. return json($res);
  256. }
  257. }
  258. public function save($info, \think\Request $request) {
  259. try {
  260. $batch = BatchApi::checkBatchValid(["type" => ProjectState::LIVINGALLOWANCE, "year" => $info["year"], "first_submit_time" => $info["firstSubmitTime"]], $this->user["type"]);
  261. if ($batch["code"] != 200) {
  262. throw new ValidateException($batch["msg"]);
  263. }
  264. if ($info) {
  265. $response = $this->validateIsEdit($info["checkState"]);
  266. if ($response->code != 200) {
  267. throw new ValidateException($response->msg);
  268. }
  269. }
  270. $data = $request->param();
  271. $data["year"] = $batch["batch"];
  272. validate(LivingAllowanceValidator::class)->check($data);
  273. $response = $this->other_validate($data);
  274. if ($response->code != 200) {
  275. throw new ValidateException($response->msg);
  276. }
  277. $id = $data["id"];
  278. if ($id) {
  279. if (!$info || $info["id"] != $id || $info["enterpriseId"] != $this->user["uid"]) {
  280. throw new ValidateException("没有对应的人才认定申报信息");
  281. }
  282. $data["checkState"] = $info["checkState"];
  283. } else {
  284. $data["id"] = getStringId();
  285. $data["active"] = 1;
  286. $data["checkState"] = LaState::LA_SAVE;
  287. $data["isPublic"] = 1;
  288. $data["recommendIsPay"] = 0;
  289. $data["isPay"] = 0;
  290. $data["createTime"] = date("Y-m-d H:i:s");
  291. $data["createUser"] = $this->user["uid"];
  292. $data["creditStatus"] = 1;
  293. $count = count(CommonLaApi::getPassYearsByIdCard($data["idCard"]));
  294. $data["applyCount"] = $count + 1;
  295. if ($data["applyCount"] > 1 && !$data["personalTax"]) {
  296. throw new ValidateException("非首年申报必须填写个税缴交情况!");
  297. }
  298. }
  299. $checkState = $data["checkState"];
  300. $data["photo"] = $info["photo"];
  301. if ($request->file()) {
  302. $headimg = $request->file("file");
  303. $upload = new \app\common\api\UploadApi();
  304. $result = $upload->uploadOne($headimg, "image", "talent/photo");
  305. if ($result->code != 200) {
  306. throw new ValidateException($result->msg);
  307. }
  308. $file = imagecreatefromstring(file_get_contents("storage/" . $result->filepath));
  309. $width = imagesx($file);
  310. $height = imagesy($file);
  311. //免冠二寸照长宽413:579
  312. if ($width * 579 != $height * 413) {
  313. @unlink("storage/" . $result->filepath); //像素不符合,删除上传文件
  314. throw new ValidateException("近期免冠半身彩照(二寸)不符合二寸像素标准。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
  315. }
  316. if ($info && $info["photo"]) {
  317. //如果新照片符合像素要求,则删除旧照片
  318. $old_head_url = "storage/" . $info["photo"];
  319. if (file_exists($old_head_url))
  320. @unlink($old_head_url);
  321. }
  322. $data["photo"] = $result->filepath;
  323. }
  324. if (!$data["photo"])
  325. throw new ValidateException("请上传头像。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
  326. if ($info["checkState"] == LaState::LA_FIRST_REJECT) {
  327. //驳回,需要判断什么字段可以提交
  328. $modify_fields = array_filter(explode(",", $info["fields"]));
  329. $tmp_data = $data;
  330. $data = [];
  331. foreach ($modify_fields as $field) {
  332. $data[$field] = $tmp_data[$field];
  333. }
  334. $data["id"] = $id;
  335. }
  336. if ($id) {
  337. $res = LaModel::update($data);
  338. } else {
  339. $res = LaModel::insertGetId($data);
  340. }
  341. if ($res) {
  342. return json(["code" => 200, "msg" => "保存成功", "obj" => ["id" => $data["id"], "checkState" => $checkState]]);
  343. }
  344. throw new ValidateException("保存失败");
  345. } catch (ValidateException $e) {
  346. $responseObj = new \stdClass();
  347. $responseObj->code = 500;
  348. $responseObj->msg = $e->getMessage();
  349. return json($responseObj);
  350. } catch (\think\Exception $e) {
  351. $res = ["code" => 500, "msg" => "发生预料外错误,请联系管理员处理,错误代码:" . $e->getCode()];
  352. $logInfo = [
  353. "enterprise_id" => $this->user["uid"],
  354. "data" => $data,
  355. "controller" => $this->request->controller(),
  356. "action" => $this->request->action(),
  357. "errCode" => $e->getCode(),
  358. "errMsg" => $e->getMessage()
  359. ];
  360. Log::write($logInfo, "error");
  361. return json($res);
  362. }
  363. }
  364. public function delete() {
  365. $id = $this->request->param("id");
  366. $info = CommonLaApi::getInfoById($id);
  367. if (!$info || $info["enterpriseId"] != $this->user["uid"]) {
  368. return json(["msg" => "操作失败"]);
  369. }
  370. $checkState = $info["checkState"];
  371. if ($checkState != LaState::LA_SAVE) {
  372. return json(["msg" => "该申报已提交审核,无法删除"]);
  373. }
  374. TalentModel::delete($id);
  375. $where = [["mainId", "=", $id], ["type", "=", ProjectState::LIVINGALLOWANCE]];
  376. $list = Db::table("new_talent_file")->where($where)->select()->toArray();
  377. foreach ($list as $key => $file) {
  378. if (!empty($file["url"])) {
  379. $filepath = "storage/" . $file["url"];
  380. if (file_exists($filepath)) {
  381. @unlink($filepath);
  382. }
  383. }
  384. Db::table("new_talent_file")->delete($file["id"]);
  385. }
  386. return json(["msg" => "删除成功"]);
  387. }
  388. public function getTalentInfo($id) {
  389. }
  390. }