Base.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php
  2. namespace app\enterprise\controller;
  3. use app\enterprise\common\EnterpriseController;
  4. use app\enterprise\api\TalentApi;
  5. use app\enterprise\model\Talent as TalentModel;
  6. use think\facade\Db;
  7. use app\common\api\TalentLogApi;
  8. use app\common\api\TalentState;
  9. // 0正在填写 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  10. /**
  11. * Description of Base
  12. *
  13. * @author sgq
  14. */
  15. class Base extends EnterpriseController {
  16. public function index() {
  17. return view();
  18. }
  19. public function list() {
  20. $res = TalentApi::getList($this->request, [TalentState::FST_SAVE, TalentState::FST_SUBMIT]);
  21. return json($res);
  22. }
  23. public function add() {
  24. $request = $this->request;
  25. $param = $request->param();
  26. $id = isset($param["id"]) ? $param["id"] : 0;
  27. $info = self::chkIsOwner($id, $this->user["uid"]);
  28. if ($info) {
  29. $info["real_state"] = TalentLogApi::getLastLog($id, 1)["state"];
  30. }
  31. if ($info && in_array($info["checkState"], [TalentState::BASE_VERIFY_PASS, TalentState::SCND_SAVE])) {
  32. $res = ["msg" => "错误的访问方式"];
  33. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  34. exit;
  35. }
  36. if ($info && in_array($info["checkState"], [TalentState::FST_VERIFY_PASS, TalentState::DEPT_VERIFY_PASS, TalentState::REVERIFY_PASS, TalentState::REVERIFY_FAIL])) {
  37. return $this->view($request);
  38. exit();
  39. }
  40. if ($request->isPost()) {
  41. if ($id) {
  42. $data["id"] = $id;
  43. if (!$info) {
  44. $res = ["msg" => "没有对应的人才认定申报信息"];
  45. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  46. exit;
  47. }
  48. if ($info["checkState"] == TalentState::REVERIFY_FAIL) {
  49. $res = ["msg" => "审核失败,不能再修改"];
  50. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  51. exit;
  52. }
  53. if (!in_array($info["checkState"], [TalentState::FST_SAVE, TalentState::BASE_VERIFY_PASS, TalentState::SCND_SAVE])) {
  54. $res = ["msg" => "审核中,不能修改"];
  55. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  56. exit;
  57. }
  58. }
  59. $files = $param["uploadFiles"];
  60. $filed_dict = \app\common\api\DictApi::getTalentFields(1);
  61. $data["headimgurl"] = $info["headimgurl"];
  62. if ($request->file()) {
  63. $headimg = $request->file("photo");
  64. if ($info && $info["headimgurl"]) {
  65. $old_head_url = "storage/" . $info["headimgurl"];
  66. if (file_exists($old_head_url))
  67. unlink($old_head_url);
  68. }
  69. $upload = new \app\common\api\UploadApi();
  70. $result = $upload->uploadOne($headimg, "image", "talent/photo");
  71. $data["headimgurl"] = $result->filepath;
  72. }
  73. if (!$data["headimgurl"]) {
  74. $res = ["msg" => "请上传头像"];
  75. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  76. exit;
  77. }
  78. $no_empty = ["talent_type", "name", "card_type", "card_number", "sex", "birthday", "nationality", "province", "city", "nation", "politics"];
  79. if (in_array($param["talent_type"], [1, 2])) {
  80. list($date1, $date2) = explode(" - ", $param["tax_insurance_month"]);
  81. if (strtotime($date1) > strtotime($date2)) {
  82. $res = ["msg" => $filed_dict["tax_insurance_month"] . "起始时间不能大于结束时间"];
  83. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  84. exit;
  85. }
  86. /* $start = date_create($date1);
  87. $end = date_create($date2);
  88. $diff = date_diff($end, $start);
  89. $m = $diff->m ?: 0;
  90. $y = $diff->y ?: 0;
  91. $months = $y * 12 + $m;
  92. if ($months < 6) {
  93. $res = ["msg" => $filed_dict["tax_insurance_month"] . "应大于或等于6个月"];
  94. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  95. exit;
  96. } */
  97. $no_empty[] = "tax_insurance_month";
  98. $no_empty[] = "labor_contract_rangetime";
  99. }
  100. if ($param["talent_type"] == 3) {
  101. list($date1, $date2) = explode(" - ", $param["labor_contract_rangetime"]);
  102. if (strtotime($date1) > strtotime($date2)) {
  103. $res = ["msg" => $filed_dict["labor_contract_rangetime"] . "起始时间不能大于结束时间"];
  104. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  105. exit;
  106. }
  107. /* $start = date_create($date1);
  108. $end = date_create($date2);
  109. $diff = date_diff($end, $start);
  110. $m = $diff->m ?: 0;
  111. $y = $diff->y ?: 0;
  112. $months = $y * 12 + $m;
  113. if ($months < 6) {
  114. $res = ["msg" => $filed_dict["labor_contract_rangetime"] . "应大于或等于6个月"];
  115. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  116. exit;
  117. } */
  118. $no_empty[] = "pre_contract_rangetime";
  119. }
  120. $return = [];
  121. foreach ($no_empty as $key) {
  122. if (!$param[$key]) {
  123. $return[] = sprintf("请填写“%s”", $filed_dict[$key]);
  124. }
  125. }
  126. if (count($return) > 0) {
  127. $res = ["msg" => implode("<br>", $return)];
  128. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  129. exit;
  130. }
  131. $where = [];
  132. $where[] = ["step", "=", 1];
  133. $where[] = ["project", "=", 1];
  134. $where[] = ["type", "=", $this->user["type"]];
  135. $where[] = ["must", "=", 1];
  136. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  137. $ft_ids = array_column($filetypes, "id");
  138. $whr = [];
  139. $upload_type_counts = 0;
  140. if ($files) {
  141. $whr[] = ["typeId", "in", $ft_ids];
  142. $whr[] = ["id", "in", $files];
  143. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  144. $upload_type_counts = count($distinct_filetypes);
  145. }
  146. if ($upload_type_counts != count($ft_ids)) {
  147. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
  148. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  149. exit;
  150. }
  151. $data["enterprise_id"] = $this->user["uid"];
  152. $data["talent_type"] = $param["talent_type"];
  153. $data["tax_insurance_month"] = $param["tax_insurance_month"];
  154. $data["labor_contract_rangetime"] = $param["labor_contract_rangetime"];
  155. $data['pre_import_type'] = $param["pre_import_type"];
  156. $data["name"] = $param["name"];
  157. $data["card_type"] = $param["card_type"];
  158. $data["card_number"] = $param["card_number"];
  159. $data["sex"] = $param["sex"];
  160. $data["birthday"] = $param["birthday"];
  161. $data["nationality"] = $param["nationality"];
  162. $data["province"] = $param["province"];
  163. $data["city"] = $param["city"];
  164. $data["county"] = $param["county"];
  165. $data["nation"] = $param["nation"];
  166. $data["politics"] = $param["politics"];
  167. if ($info["real_state"] == 4) {
  168. //真实状态4是驳回,需要判断什么字段可以提交
  169. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  170. $tmp_data = $data;
  171. $data = [];
  172. if ($tmp_data["id"]) {
  173. $data["id"] = $tmp_data["id"];
  174. }
  175. foreach ($modify_fields as $field) {
  176. $data[$field] = $tmp_data[$field];
  177. }
  178. }
  179. if ($id > 0) {
  180. TalentModel::update($data);
  181. } else {
  182. $data["checkState"] = TalentState::FST_SAVE;
  183. $id = TalentModel::insertGetId($data);
  184. TalentLogApi::write(1, $id, TalentState::FST_SAVE, "添加人才认定申报", 1);
  185. }
  186. if ($id) {
  187. $whr = [];
  188. $whr[] = ["id", "in", $files];
  189. Db::table("new_talent_file")->where($whr)->save(["mainId" => $id]);
  190. $res = ["code" => 200, "msg" => "保存成功", "obj" => ["id" => $id, "checkState" => TalentState::FST_SAVE]];
  191. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  192. } else {
  193. $res = ["msg" => "保存失败"];
  194. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  195. }
  196. exit();
  197. }
  198. $checkState = $info["checkState"] ?: 0;
  199. $enterprise_info = \app\common\model\Enterprise::find($this->user["uid"]);
  200. $info["enterprise"] = $enterprise_info;
  201. $info["talent_type_list"] = \app\common\api\DictApi::findChildDictByCode("talent_type");
  202. return view("first", ["year" => date("Y"), "checkState" => $checkState, "row" => $info]);
  203. }
  204. public function view(\think\Request $request) {
  205. $id = $request->param("id");
  206. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  207. return view("view", ["row" => $info]);
  208. }
  209. // 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  210. public function submit() {
  211. $id = $this->request->param("id");
  212. if (!$info = self::chkIsOwner($id, $this->user["uid"]))
  213. return json(["msg" => "没有对应的人才认定申报信息"]);
  214. $checkState = $info["checkState"];
  215. if ($checkState == TalentState::BASE_VERIFY_PASS || $checkState == 0) {
  216. return json(["msg" => '请先保存资料并上传相应附件后再点击提交审核']);
  217. } else if ($checkState == TalentState::FST_SAVE) {
  218. //初次提交材料
  219. $where = [];
  220. $where[] = ["step", "=", 1];
  221. $where[] = ["project", "=", 1];
  222. $where[] = ["type", "=", $this->user["type"]];
  223. $where[] = ["must", "=", 1];
  224. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  225. $ft_ids = array_column($filetypes, "id");
  226. $whr = [];
  227. $upload_type_counts = 0;
  228. if ($ft_ids) {
  229. $whr[] = ["typeId", "in", $ft_ids];
  230. $whr[] = ["mainId", "=", $id];
  231. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  232. $upload_type_counts = count($distinct_filetypes);
  233. }
  234. if ($upload_type_counts != count($ft_ids)) {
  235. return json(["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"]);
  236. }
  237. $change_state = TalentState::FST_SUBMIT; //等待审核
  238. $data["id"] = $id;
  239. $data["checkState"] = $change_state;
  240. $data["first_submit_time"] = date("Y-m-d H:i:s");
  241. $data["active"] = 1;
  242. TalentModel::update($data);
  243. TalentLogApi::write(1, $id, $change_state, "提交基础判定材料待审核", 1);
  244. return json(["code" => 200, "msg" => "提交成功"]);
  245. } else if ($checkState == TalentState::REVERIFY_FAIL) {
  246. return ["msg" => "审核失败,不能再提交审核"];
  247. }
  248. return json(["msg" => "已提交审核,请耐心等待"]);
  249. }
  250. public function delete() {
  251. $id = $this->request->param("talentInfoId");
  252. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  253. if (!$info) {
  254. return json(["msg" => "操作失败"]);
  255. }
  256. $checkState = $info["checkState"];
  257. if (in_array($checkState, [0, 1])) {
  258. $log = TalentLogApi::getLastLog($id, 1);
  259. if ($log["state"] > 1) {
  260. //有提交审核记录
  261. return json(["msg" => "操作失败"]);
  262. }
  263. }
  264. $data["id"] = $id;
  265. $data["delete"] = 1;
  266. TalentModel::update($data);
  267. return json(["msg" => "删除成功"]);
  268. }
  269. static private function chkIsOwner($id, $uid) {
  270. $where[] = ["id", "=", $id];
  271. $where[] = ["enterprise_id", "=", $uid];
  272. $info = TalentModel::where($where)->findOrEmpty()->toArray();
  273. return $info;
  274. }
  275. }