Base.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <?php
  2. namespace app\enterprise\controller;
  3. use app\common\api\DictApi;
  4. use app\common\api\EnterpriseApi;
  5. use app\enterprise\common\EnterpriseController;
  6. use app\enterprise\api\TalentApi;
  7. use app\enterprise\model\Talent as TalentModel;
  8. use think\facade\Db;
  9. use app\common\api\TalentLogApi;
  10. use app\common\api\TalentState;
  11. use think\exception\ValidateException;
  12. use app\enterprise\validate\TalentInfo;
  13. // 0正在填写 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  14. /**
  15. * Description of Base
  16. *
  17. * @author sgq
  18. */
  19. class Base extends EnterpriseController {
  20. public function index() {
  21. return view();
  22. }
  23. public function list() {
  24. $step = 1;
  25. $res = TalentApi::getList($this->request, $step);
  26. return json($res);
  27. }
  28. public function add() {
  29. $request = $this->request;
  30. $param = $request->param();
  31. $id = isset($param["id"]) ? $param["id"] : 0;
  32. $info = TalentApi::chkIsOwner($id, $this->user["uid"]);
  33. $ep = EnterpriseApi::getOne($this->user["uid"]);
  34. if (!chkEnterpriseFull($ep))
  35. return;
  36. $tagList = DictApi::selectByParentCode('enterprise_tag');
  37. $streetList = DictApi::selectByParentCode('street');
  38. $industryFieldNew = DictApi::selectByParentCode('industry_field');
  39. $ep->enterpristTagName = $tagList[$ep->enterpriseTag];
  40. $ep->streetName = $streetList[$ep->street];
  41. $ep->industryFieldNewName = $industryFieldNew[$ep->industryFieldNew];
  42. if ($info) {
  43. $info["real_state"] = TalentLogApi::getLastLog($id, 1)["state"];
  44. }
  45. if ($info && in_array($info["checkState"], [TalentState::BASE_VERIFY_PASS, TalentState::SCND_SAVE])) {
  46. $res = ["msg" => "错误的访问方式"];
  47. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  48. exit;
  49. }
  50. if ($info && in_array($info["checkState"], [TalentState::FST_VERIFY_PASS, TalentState::DEPT_VERIFY_PASS, TalentState::REVERIFY_PASS, TalentState::REVERIFY_FAIL])) {
  51. return $this->view($request);
  52. exit();
  53. }
  54. if ($request->isPost()) {
  55. $this->save($info, $request, TalentState::FST_SAVE);
  56. exit();
  57. }
  58. $checkState = $info["checkState"] ?: 0;
  59. $info["enterprise"] = $ep;
  60. $info["talent_type_list"] = \app\common\api\DictApi::findChildDictByCode("talent_type");
  61. return view("first", ["year" => date("Y"), "checkState" => $checkState, "row" => $info]);
  62. }
  63. public function view(\think\Request $request) {
  64. $id = $request->param("id");
  65. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  66. return view("view", ["row" => $info]);
  67. }
  68. // 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  69. public function submit() {
  70. $param = $this->request->param();
  71. $id = $param["id"];
  72. $info = self::chkIsOwner($id, $this->user["uid"]);
  73. $checkState = $info["checkState"] ?: 0;
  74. if ($checkState == TalentState::FST_SAVE || $checkState == 0) {
  75. $filed_dict = \app\common\api\DictApi::getTalentFields(1);
  76. $no_empty = ["talent_type", "name", "card_type", "card_number", "sex", "birthday", "nationality", "province", "city", "county", "nation", "politics", "experience", "education"];
  77. $birthday = $param["birthday"];
  78. $birthdayYear = substr($birthday, 0, 4);
  79. $currentYear = date("Y");
  80. $age = $currentYear - $birthdayYear;
  81. if (in_array($param["talent_type"], [1, 2])) {
  82. $no_empty[] = "tax_insurance_month";
  83. $no_empty[] = "labor_contract_rangetime";
  84. }
  85. if ($param["talent_type"] == 3) {
  86. $no_empty[] = "pre_import_type";
  87. }
  88. $return = [];
  89. foreach ($no_empty as $key) {
  90. if (!$param[$key]) {
  91. $return[] = sprintf("请填写“%s”", $filed_dict[$key]);
  92. }
  93. }
  94. if (count($return) > 0) {
  95. $res = ["msg" => implode("<br>", $return)];
  96. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  97. exit;
  98. }
  99. $where = [];
  100. $where[] = ["step", "=", 1];
  101. $where[] = ["project", "=", 1];
  102. $where[] = ["type", "=", $this->user["type"]];
  103. $where[] = ["must", "=", 1];
  104. $where[] = ["active", "=", 1];
  105. $where[] = ["delete", "=", 0];
  106. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  107. $ft_ids = [];
  108. foreach ($filetypes as $ft) {
  109. if ($ft["option"]) {
  110. if ($ft["rel"] == "birthday") {
  111. if ($age < $ft["option"]) {
  112. $deletes[] = $ft["id"];
  113. continue;
  114. }
  115. } else {
  116. $selectVal = $param[$ft["rel"]];
  117. $conditions = array_filter(explode(",", $ft["option"]));
  118. if (!in_array($selectVal, $conditions)) {
  119. $deletes[] = $ft["id"];
  120. continue;
  121. }
  122. }
  123. }
  124. $ft_ids[] = $ft["id"];
  125. }
  126. //$ft_ids = array_column($filetypes, "id");
  127. $whr = [];
  128. $upload_type_counts = 0;
  129. if ($ft_ids) {
  130. $whr[] = ["typeId", "in", $ft_ids];
  131. $whr[] = ["mainId", "=", $id];
  132. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  133. $upload_type_counts = count($distinct_filetypes);
  134. }
  135. if ($upload_type_counts != count($ft_ids)) {
  136. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核" . count($ft_ids)];
  137. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  138. exit;
  139. }
  140. $this->save($info, $this->request, TalentState::FST_SUBMIT);
  141. //初次提交材料
  142. } else if ($checkState == TalentState::REVERIFY_FAIL) {
  143. $res = ["msg" => "审核失败,不能再提交审核"];
  144. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  145. exit;
  146. }
  147. $res = ["msg" => "已提交审核,请耐心等待"];
  148. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  149. exit;
  150. }
  151. /**
  152. * 保存表单
  153. * @param type $info talent_info
  154. * @param type $param request->param();
  155. */
  156. private function save($info, \think\Request $request, $checkState) {
  157. try {
  158. $param = $request->param();
  159. validate(TalentInfo::class)->check($param);
  160. $id = $param["id"];
  161. if ($id) {
  162. $data["id"] = $id;
  163. if (!$info) {
  164. throw new ValidateException("没有对应的人才认定申报信息");
  165. }
  166. if ($info["checkState"] == TalentState::REVERIFY_FAIL) {
  167. throw new ValidateException("审核失败,不能再修改");
  168. }
  169. if (!in_array($info["checkState"], [TalentState::FST_SAVE, 0])) {
  170. throw new ValidateException("审核中,不能修改");
  171. }
  172. }
  173. $files = $param["uploadFiles"];
  174. $data["headimgurl"] = $info["headimgurl"];
  175. if ($request->file()) {
  176. $headimg = $request->file("photo");
  177. $upload = new \app\common\api\UploadApi();
  178. $result = $upload->uploadOne($headimg, "image", "talent/photo");
  179. $file = imagecreatefromstring(file_get_contents("storage/" . $result->filepath));
  180. $width = imagesx($file);
  181. $height = imagesy($file);
  182. //免冠二寸照长宽413:579
  183. if ($width * 579 != $height * 413) {
  184. @unlink("storage/" . $result->filepath); //像素不符合,删除上传文件
  185. throw new ValidateException("近期免冠半身彩照(二寸)不符合二寸像素标准。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
  186. }
  187. if ($info && $info["headimgurl"]) {
  188. //如果新照片符合像素要求,则删除旧照片
  189. $old_head_url = "storage/" . $info["headimgurl"];
  190. if (file_exists($old_head_url))
  191. @unlink($old_head_url);
  192. }
  193. $data["headimgurl"] = $result->filepath;
  194. }
  195. if (!$data["headimgurl"] && $checkState == TalentState::FST_SUBMIT)
  196. throw new ValidateException("请上传头像。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
  197. $where = [];
  198. $where[] = ["step", "=", 1];
  199. $where[] = ["project", "=", 1];
  200. $where[] = ["type", "=", $this->user["type"]];
  201. $where[] = ["must", "=", 1];
  202. $where[] = ["active", "=", 1];
  203. $where[] = ["delete", "=", 0];
  204. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  205. $age = 0;
  206. if ($param["birthday"]) {
  207. $birthday = $param["birthday"];
  208. $birthdayYear = substr($birthday, 0, 4);
  209. $currentYear = date("Y");
  210. $age = $currentYear - $birthdayYear;
  211. }
  212. $ft_ids = [];
  213. $deletes = [];
  214. foreach ($filetypes as $ft) {
  215. if ($ft["option"]) {
  216. if ($ft["rel"] == "birthday") {
  217. if ($age < $ft["option"]) {
  218. $deletes[] = $ft["id"];
  219. continue;
  220. }
  221. } else {
  222. $selectVal = $param[$ft["rel"]];
  223. $conditions = array_filter(explode(",", $ft["option"]));
  224. if (!in_array($selectVal, $conditions)) {
  225. $deletes[] = $ft["id"];
  226. continue;
  227. }
  228. }
  229. }
  230. $ft_ids[] = $ft["id"];
  231. }
  232. $data["name"] = $param["name"];
  233. $data["enterprise_id"] = $this->user["uid"];
  234. $data["nation"] = $param["nation"];
  235. $data["card_type"] = $param["card_type"];
  236. $data["card_number"] = $param["card_number"];
  237. $data["sex"] = $param["sex"];
  238. $data["birthday"] = $param["birthday"];
  239. $data["politics"] = $param["politics"];
  240. $data["nationality"] = $param["nationality"];
  241. $data["province"] = $param["province"];
  242. $data["city"] = $param["city"];
  243. $data["county"] = $param["county"];
  244. $data["talent_type"] = $param["talent_type"];
  245. if (in_array($data["talent_type"], [1, 2])) {
  246. $data["tax_insurance_month"] = $param["tax_insurance_month"];
  247. $data["labor_contract_rangetime"] = $param["labor_contract_rangetime"];
  248. $data["fst_work_time"] = $param["fst_work_time"];
  249. $data['pre_import_type'] = null;
  250. } else {
  251. $data["tax_insurance_month"] = null;
  252. $data["labor_contract_rangetime"] = null;
  253. $data["fst_work_time"] = null;
  254. $data['pre_import_type'] = $param["pre_import_type"];
  255. }
  256. $data["experience"] = $param["experience"];
  257. $data["education"] = $param["education"];
  258. if ($info["real_state"] == 4) {
  259. //真实状态4是驳回,需要判断什么字段可以提交
  260. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  261. $tmp_data = $data;
  262. $data = [];
  263. if ($tmp_data["id"]) {
  264. $data["id"] = $tmp_data["id"];
  265. }
  266. foreach ($modify_fields as $field) {
  267. $data[$field] = $tmp_data[$field];
  268. }
  269. }
  270. $success_msg = "保存成功";
  271. $error_msg = "保存失败";
  272. if ($checkState == TalentState::FST_SAVE) {
  273. if ($data["id"] > 0) {
  274. TalentModel::update($data);
  275. } else {
  276. $data["checkState"] = $checkState;
  277. $id = TalentModel::insertGetId($data);
  278. TalentLogApi::write(1, $id, $checkState, "添加人才认定申报", 1);
  279. $whr = [];
  280. $whr[] = ["fileId", "in", $files];
  281. $upd_checklog["mainId"] = $id;
  282. Db::table("new_talent_checklog")->where($whr)->save($upd_checklog);
  283. }
  284. } else if ($checkState == TalentState::FST_SUBMIT) {
  285. $success_msg = "提交成功";
  286. $error_msg = "提交失败";
  287. $data["checkState"] = $checkState;
  288. $data["first_submit_time"] = date("Y-m-d H:i:s");
  289. if ($data["id"] > 0) {
  290. TalentModel::update($data);
  291. } else {
  292. $id = TalentModel::insertGetId($data);
  293. $whr = [];
  294. $whr[] = ["fileId", "in", $files];
  295. $upd_checklog["mainId"] = $id;
  296. Db::table("new_talent_checklog")->where($whr)->save($upd_checklog);
  297. }
  298. TalentLogApi::write(1, $id, $checkState, "提交基础判定材料待审核", 1);
  299. } else {
  300. throw new ValidateException("错误的审核状态");
  301. }
  302. if ($id) {
  303. if ($deletes) {
  304. //删除多余的附件,一般是选择人才类型留下来的
  305. $whr = [];
  306. $whr[] = ["typeId", "in", $deletes];
  307. $whr[] = ["id", "in", $files];
  308. $_wait_del_files = Db::table("new_talent_file")->where($whr)->select()->toArray();
  309. $_logfileIds[] = [];
  310. foreach ($_wait_del_files as $_del_file) {
  311. $_logfileIds[] = $_del_file["id"];
  312. @unlink("storage/" . $_del_file["url"]);
  313. }
  314. Db::table("new_talent_file")->where($whr)->delete();
  315. if ($_logfileIds) {
  316. $whr = [];
  317. $whr[] = ["fileId", "in", $_logfileIds];
  318. $_upd_checklog["description"] = "人才申报过程1中取消且已经彻底删除的附件";
  319. $_upd_checklog["updateUser"] = sprintf("%s(%s)", $this->user["account"], $this->user["companyName"] ?: $this->user["rolename"]);
  320. $_upd_checklog["updateTime"] = date("Y-m-d H:i:s");
  321. Db::table("new_talent_checklog")->where($whr)->save($_upd_checklog);
  322. }
  323. }
  324. $whr = [];
  325. $whr[] = ["id", "in", $files];
  326. Db::table("new_talent_file")->where($whr)->save(["mainId" => $id]);
  327. $res = ["code" => 200, "msg" => $success_msg, "obj" => ["id" => $id, "checkState" => $checkState]];
  328. $callback = $checkState == TalentState::FST_SAVE ? "infoCallback" : "submitCallback";
  329. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  330. exit();
  331. } else {
  332. throw new ValidateException($error_msg);
  333. }
  334. } catch (ValidateException $e) {
  335. $res = ["msg" => $e->getMessage()];
  336. $callback = $checkState == TalentState::FST_SAVE ? "infoCallback" : "submitCallback";
  337. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  338. exit();
  339. }
  340. }
  341. public function delete() {
  342. $id = $this->request->param("talentInfoId");
  343. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  344. if (!$info) {
  345. return json(["msg" => "操作失败"]);
  346. }
  347. $checkState = $info["checkState"];
  348. if (in_array($checkState, [0, 1])) {
  349. $log = TalentLogApi::getLastLog($id, 1);
  350. if ($log["state"] > 1) {
  351. //有提交审核记录
  352. return json(["msg" => "操作失败"]);
  353. }
  354. }
  355. $data["id"] = $id;
  356. $data["delete"] = 1;
  357. TalentModel::update($data);
  358. return json(["msg" => "删除成功"]);
  359. }
  360. }