LivingAllowance.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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\DictApi;
  8. use app\common\api\TalentLogApi;
  9. use think\exception\ValidateException;
  10. use app\enterprise\validate\LivingAllowance as LivingAllowanceValidator;
  11. use app\common\state\ProjectState;
  12. use app\common\api\BatchApi;
  13. use app\enterprise\api\LivingAllowanceApi as EnterpriseLaApi;
  14. use app\common\api\LivingAllowanceApi;
  15. /**
  16. * Description of LivingAllowance
  17. * 硕博人才生活补贴申请
  18. * @author sgq
  19. */
  20. class LivingAllowance extends EnterpriseController {
  21. public function index() {
  22. return view("", ['type' => session("user")['type']]);
  23. }
  24. public function list() {
  25. $res = EnterpriseLaApi::getList($this->request);
  26. return json($res);
  27. }
  28. /**
  29. * 新人才申报企业端统一申报入口,混合基础信息及人才信息
  30. */
  31. public function apply(\think\Request $request) {
  32. $type = $this->user["type"];
  33. $param = $request->param();
  34. $id = isset($param["id"]) ? $param["id"] : 0;
  35. $info = LivingAllowanceApi::getInfoById($id);
  36. $ep = EnterpriseApi::getOne($this->user["uid"]);
  37. if (!chkEnterpriseFull($ep))
  38. return;
  39. if ($info && in_array($info["checkState"], [TalentState::FST_VERIFY_PASS, TalentState::DEPT_VERIFY_PASS, TalentState::REVERIFY_PASS, TalentState::REVERIFY_FAIL])) {
  40. return $this->view($request);
  41. exit();
  42. }
  43. if ($request->isPost()) {
  44. $checkState = $info["checkState"] ?: 0;
  45. if ($checkState == TalentState::SCND_SAVE || $checkState == 0) {
  46. $this->save($info, $request, TalentState::SCND_SAVE);
  47. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL])) {
  48. $res = ["msg" => "审核不通过,不能再保存"];
  49. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  50. exit;
  51. }
  52. $res = ["msg" => "已提交审核,请耐心等待"];
  53. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  54. exit;
  55. }
  56. $hand = $info ? "update" : "add";
  57. $batch = $info["year"] ?: BatchApi::getValidBatch(ProjectState::LIVINGALLOWANCE, $this->user["type"])["batch"];
  58. return view("", ["year" => $batch, "row" => $info, "enterprise" => $ep, "hand" => $hand]);
  59. }
  60. public function view(\think\Request $request) {
  61. switch ($this->user["type"]) {
  62. case 1:
  63. $tpl = "view"; //晋江人才
  64. break;
  65. case 2:
  66. $tpl = "ic_view"; //集成电路
  67. break;
  68. }
  69. $id = $request->param("id");
  70. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  71. if ($info["isImport"]) {
  72. //$tpl = "no_file_view";
  73. }
  74. return view($tpl, ["row" => $info]);
  75. }
  76. /**
  77. * 提交表单
  78. */
  79. public function submitToCheck() {
  80. $params = $this->request->param();
  81. $id = $params["id"];
  82. if (!$info = TalentApi::chkIsOwner($id, $this->user["uid"])) {
  83. return json(["msg" => "没有对应的人才认定申报信息"]);
  84. }
  85. if ($info) {
  86. $info["real_state"] = TalentLogApi::getLastLog($id, 1)["state"];
  87. }
  88. $checkState = $info["checkState"];
  89. if ($checkState == TalentState::SCND_SAVE) {
  90. $field_dict = \app\common\api\DictApi::getTalentFields_IC();
  91. $no_empty = ["name", "card_type", "card_number", "sex", "birthday", "nationality", "province", "city", "nation", "politics", "break_faith",
  92. "phone", "email", "highest_degree", "graduate_school", "major", "study_abroad", "position", "cur_entry_time", "labor_contract_rangetime",
  93. "talent_arrange", "talent_condition", "identifyConditionName", "identifyGetTime",
  94. "bank", "bank_branch_name", "bank_account", "experience", "education"];
  95. $no_empty = array_filter($no_empty);
  96. $return = [];
  97. foreach ($no_empty as $key) {
  98. if (!$info[$key]) {
  99. $return[] = sprintf("请填写“%s”", $field_dict[$key]);
  100. }
  101. }
  102. if (count($return) > 0) {
  103. return json(["msg" => implode("<br>", $return)]);
  104. }
  105. $where = [];
  106. $where[] = ["project", "=", 1];
  107. $where[] = ["type", "=", $this->user["type"]];
  108. $where[] = ["must", "=", 1];
  109. $where[] = ["active", "=", 1];
  110. $where[] = ["delete", "=", 0];
  111. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  112. $ft_ids = array_column($filetypes, "id");
  113. $whr = [];
  114. $whr[] = ["typeId", "in", $ft_ids];
  115. $whr[] = ["mainId", "=", $id];
  116. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  117. $upload_type_counts = count($distinct_filetypes);
  118. if ($upload_type_counts != count($ft_ids)) {
  119. return json(["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"]);
  120. }
  121. return $this->icSave($info, $this->request, TalentState::SCND_SUBMIT);
  122. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL, TalentState::ZX_FAIL, TalentState::ANNOUNCED_REVERIFY_FAIL, TalentState::PUBLISH_FAIL])) {
  123. return json(["msg" => "审核不通过,不能再提交审核", "code" => 500]);
  124. }
  125. return json(["msg" => "已提交审核,请耐心等待", "code" => 500]);
  126. }
  127. public function save($info, \think\Request $request, $checkState) {
  128. try {
  129. $batch = BatchApi::checkBatchValid(["type" => ProjectState::TALENT, "year" => $info["apply_year"], "first_submit_time" => $info["first_submit_time"]], $this->user["type"]);
  130. if ($batch["code"] != 200) {
  131. throw new ValidateException($batch["msg"]);
  132. }
  133. $param = $request->param();
  134. validate(TalentInfo::class)->check($param);
  135. $id = $param["id"];
  136. if ($id) {
  137. if (!$info || $info["id"] != $id || $info["enterprise_id"] != $this->user["uid"]) {
  138. throw new ValidateException("没有对应的人才认定申报信息");
  139. }
  140. }
  141. $files = $param["uploadFiles"];
  142. $data["headimgurl"] = $info["headimgurl"];
  143. if ($request->file()) {
  144. $headimg = $request->file("photo");
  145. $upload = new \app\common\api\UploadApi();
  146. $result = $upload->uploadOne($headimg, "image", "talent/photo");
  147. $file = imagecreatefromstring(file_get_contents("storage/" . $result->filepath));
  148. $width = imagesx($file);
  149. $height = imagesy($file);
  150. //免冠二寸照长宽413:579
  151. if ($width * 579 != $height * 413) {
  152. @unlink("storage/" . $result->filepath); //像素不符合,删除上传文件
  153. throw new ValidateException("近期免冠半身彩照(二寸)不符合二寸像素标准。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
  154. }
  155. if ($info && $info["headimgurl"]) {
  156. //如果新照片符合像素要求,则删除旧照片
  157. $old_head_url = "storage/" . $info["headimgurl"];
  158. if (file_exists($old_head_url))
  159. @unlink($old_head_url);
  160. }
  161. $data["headimgurl"] = $result->filepath;
  162. }
  163. if (!$data["headimgurl"] && $checkState == TalentState::SCND_SUBMIT)
  164. throw new ValidateException("请上传头像。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
  165. $data["apply_year"] = $batch["batch"];
  166. $all_valid_keys = ["name", "card_type", "card_number", "sex", "birthday", "nationality", "province", "city", "county", "nation", "politics", "experience", "education", "break_faith",
  167. "phone", "email", "highest_degree", "graduate_school", "major", "study_abroad",
  168. "position", "cur_entry_time", "labor_contract_rangetime",
  169. "talent_arrange", "talent_condition", "identifyConditionName", "identifyGetTime", "title", "pro_qua",
  170. "bank", "bank_branch_name", "bank_account", "description"];
  171. foreach ($all_valid_keys as $key) {
  172. $value = trim($param[$key]);
  173. if ($value) {
  174. $data[$key] = $value;
  175. }
  176. }
  177. if ($info["real_state"] == TalentState::FST_VERIFY_REJECT) {
  178. //真实状态11是驳回,需要判断什么字段可以提交
  179. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  180. $tmp_data = $data;
  181. $data = [];
  182. foreach ($modify_fields as $field) {
  183. $data[$field] = $tmp_data[$field];
  184. }
  185. }
  186. $data["checkState"] = $checkState;
  187. $data["id"] = $id;
  188. $success_msg = "提交成功";
  189. $error_msg = "提交失败";
  190. if ($checkState == TalentState::SCND_SAVE) {
  191. $success_msg = "保存成功";
  192. if ($data["id"]) {
  193. //编辑
  194. TalentModel::update($data);
  195. $last_log = TalentLogApi::getLastLog($data["id"], 1);
  196. if ($last_log["new_state"] != TalentState::SCND_SAVE) {
  197. TalentLogApi::write(1, $data["id"], $checkState, "保存未提交", 1);
  198. } else {
  199. if (!$last_log["companyId"]) {
  200. TalentLogApi::setActive($last_log["id"], 1); //更新修改时间
  201. }
  202. }
  203. } else {
  204. //新增
  205. $data["enterprise_id"] = $this->user["uid"];
  206. $id = TalentModel::insertGetId($data);
  207. TalentLogApi::write(1, $id, $checkState, "保存未提交", 1);
  208. $whr = [];
  209. $whr[] = ["fileId", "in", $files];
  210. $upd_checklog["mainId"] = $id;
  211. Db::table("new_talent_checklog")->where($whr)->save($upd_checklog);
  212. }
  213. $res = ["code" => 200, "msg" => $success_msg, "obj" => ["id" => $id, "checkState" => $checkState]];
  214. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  215. exit();
  216. } else if ($checkState == TalentState::SCND_SUBMIT) {
  217. $data["new_submit_time"] = date("Y-m-d H:i:s");
  218. TalentModel::update($data);
  219. TalentLogApi::write(1, $data["id"], $checkState, "确认提交审核", 1);
  220. return json(["msg" => $success_msg, "code" => 200]);
  221. } else {
  222. throw new ValidateException($error_msg);
  223. }
  224. } catch (ValidateException $e) {
  225. if ($checkState == TalentState::SCND_SAVE) {
  226. $res = ["msg" => $e->getMessage()];
  227. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  228. exit();
  229. } else {
  230. return json(["msg" => $e->getMessage()]);
  231. }
  232. } catch (\think\Exception $e) {
  233. $res = ["msg" => "发生预料外错误,请联系管理员处理,错误代码:" . $e->getCode()];
  234. $logInfo = [
  235. "enterprise_id" => $this->user["uid"],
  236. "data" => $data,
  237. "controller" => $this->request->controller(),
  238. "action" => $this->request->action(),
  239. "errCode" => $e->getCode(),
  240. "errMsg" => $e->getMessage()
  241. ];
  242. Log::write($logInfo, "error");
  243. if ($checkState == TalentState::SCND_SAVE) {
  244. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  245. exit();
  246. } else {
  247. return json($res);
  248. }
  249. }
  250. }
  251. public function delete() {
  252. $id = $this->request->param("talentInfoId");
  253. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  254. if (!$info) {
  255. return json(["msg" => "操作失败"]);
  256. }
  257. $checkState = $info["checkState"];
  258. if (in_array($checkState, [0, 1])) {
  259. $log = TalentLogApi::getLastLog($id, 1);
  260. if ($log["state"] > 1) {
  261. //有提交审核记录
  262. return json(["msg" => "该申报已提交审核,无法删除"]);
  263. }
  264. }
  265. $data["id"] = $id;
  266. $data["delete"] = 1;
  267. TalentModel::update($data);
  268. return json(["msg" => "删除成功"]);
  269. }
  270. // public function mixDelete() {
  271. // $id = $this->request->param("talentInfoId");
  272. // $info = TalentApi::chkIsOwner($id, $this->user["uid"]);
  273. // if (!$info) {
  274. // return json(["msg" => "操作失败"]);
  275. // }
  276. // $checkState = $info["checkState"];
  277. // if (in_array($checkState, [0, TalentState::SCND_SAVE])) {
  278. // $data["id"] = $id;
  279. // $data["delete"] = 1;
  280. // TalentModel::update($data);
  281. // return json(["msg" => "删除成功"]);
  282. // }
  283. // return json(["msg" => "该申报已提交审核,无法删除"]);
  284. // }
  285. }