Base.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. if ($diff->m < 6) {
  90. $res = ["msg" => $filed_dict["tax_insurance_month"] . "应大于或等于6个月"];
  91. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  92. exit;
  93. }
  94. $no_empty[] = "tax_insurance_month";
  95. }
  96. if ($param["talent_type"] == 3) {
  97. list($date1, $date2) = explode(" - ", $param["labor_contract_rangetime"]);
  98. if (strtotime($date1) > strtotime($date2)) {
  99. $res = ["msg" => $filed_dict["labor_contract_rangetime"] . "起始时间不能大于结束时间"];
  100. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  101. exit;
  102. }
  103. $start = date_create($date1);
  104. $end = date_create($date2);
  105. $diff = date_diff($end, $start);
  106. if ($diff->m < 6) {
  107. $res = ["msg" => $filed_dict["labor_contract_rangetime"] . "应大于或等于6个月"];
  108. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  109. exit;
  110. }
  111. $no_empty[] = "labor_contract_rangetime";
  112. }
  113. $return = [];
  114. foreach ($no_empty as $key) {
  115. if (!$param[$key]) {
  116. $return[] = sprintf("请填写“%s”", $filed_dict[$key]);
  117. }
  118. }
  119. if (count($return) > 0) {
  120. $res = ["msg" => implode("<br>", $return)];
  121. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  122. exit;
  123. }
  124. $where = [];
  125. $where[] = ["step", "=", 1];
  126. $where[] = ["project", "=", 1];
  127. $where[] = ["type", "=", $this->user["type"]];
  128. $where[] = ["must", "=", 1];
  129. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  130. $ft_ids = array_column($filetypes, "id");
  131. $whr = [];
  132. $upload_type_counts = 0;
  133. if ($files) {
  134. $whr[] = ["typeId", "in", $ft_ids];
  135. $whr[] = ["id", "in", $files];
  136. $upload_type_counts = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->count();
  137. }
  138. if ($upload_type_counts != count($ft_ids)) {
  139. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
  140. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  141. exit;
  142. }
  143. $data["enterprise_id"] = $this->user["uid"];
  144. $data["talent_type"] = $param["talent_type"];
  145. $data["tax_insurance_month"] = $param["tax_insurance_month"];
  146. $data["labor_contract_rangetime"] = $param["labor_contract_rangetime"];
  147. $data["name"] = $param["name"];
  148. $data["card_type"] = $param["card_type"];
  149. $data["card_number"] = $param["card_number"];
  150. $data["sex"] = $param["sex"];
  151. $data["birthday"] = $param["birthday"];
  152. $data["nationality"] = $param["nationality"];
  153. $data["province"] = $param["province"];
  154. $data["city"] = $param["city"];
  155. $data["county"] = $param["county"];
  156. $data["nation"] = $param["nation"];
  157. $data["politics"] = $param["politics"];
  158. if ($info["real_state"] == 4) {
  159. //真实状态4是驳回,需要判断什么字段可以提交
  160. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  161. $tmp_data = $data;
  162. $data = [];
  163. if ($tmp_data["id"]) {
  164. $data["id"] = $tmp_data["id"];
  165. }
  166. foreach ($modify_fields as $field) {
  167. $data[$field] = $tmp_data[$field];
  168. }
  169. }
  170. if ($id > 0) {
  171. TalentModel::update($data);
  172. } else {
  173. $data["checkState"] = TalentState::FST_SAVE;
  174. $id = TalentModel::insertGetId($data);
  175. TalentLogApi::write(1, $id, TalentState::FST_SAVE, "添加人才认定申报", 1);
  176. }
  177. if ($id) {
  178. $whr = [];
  179. $whr[] = ["id", "in", $files];
  180. Db::table("new_talent_file")->where($whr)->save(["mainId" => $id]);
  181. $res = ["code" => 200, "msg" => "保存成功", "obj" => ["id" => $id, "checkState" => TalentState::FST_SAVE]];
  182. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  183. } else {
  184. $res = ["msg" => "保存失败"];
  185. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  186. }
  187. exit();
  188. }
  189. $checkState = $info["checkState"] ?: 0;
  190. $enterprise_info = \app\common\model\Enterprise::find($this->user["uid"]);
  191. $info["enterprise"] = $enterprise_info;
  192. $info["talent_type_list"] = \app\common\api\DictApi::findChildDictByCode("talent_type");
  193. return view("first", ["year" => date("Y"), "checkState" => $checkState, "row" => $info]);
  194. }
  195. public function view(\think\Request $request) {
  196. $id = $request->param("id");
  197. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  198. return view("view", ["row" => $info]);
  199. }
  200. // 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  201. public function submit() {
  202. $id = $this->request->param("id");
  203. if (!$info = self::chkIsOwner($id, $this->user["uid"]))
  204. return json(["msg" => "没有对应的人才认定申报信息"]);
  205. $checkState = $info["checkState"];
  206. if ($checkState == TalentState::BASE_VERIFY_PASS || $checkState == 0) {
  207. return json(["msg" => '请先保存资料并上传相应附件后再点击提交审核']);
  208. } else if ($checkState == TalentState::FST_SAVE) {
  209. //初次提交材料
  210. $where = [];
  211. $where[] = ["step", "=", 1];
  212. $where[] = ["project", "=", 1];
  213. $where[] = ["type", "=", $this->user["type"]];
  214. $where[] = ["must", "=", 1];
  215. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  216. $ft_ids = array_column($filetypes, "id");
  217. $whr = [];
  218. $upload_type_counts = 0;
  219. if ($ft_ids) {
  220. $whr[] = ["typeId", "in", $ft_ids];
  221. $whr[] = ["mainId", "=", $id];
  222. $upload_type_counts = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->count();
  223. }
  224. if ($upload_type_counts != count($ft_ids)) {
  225. return json(["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"]);
  226. }
  227. $change_state = TalentState::FST_SUBMIT; //等待审核
  228. $data["id"] = $id;
  229. $data["checkState"] = $change_state;
  230. $data["first_submit_time"] = date("Y-m-d H:i:s");
  231. $data["active"] = 1;
  232. TalentModel::update($data);
  233. TalentLogApi::write(1, $id, $change_state, "提交基础判定材料待审核", 1);
  234. return json(["code" => 200, "msg" => "提交成功"]);
  235. } else if ($checkState == TalentState::REVERIFY_FAIL) {
  236. return ["msg" => "审核失败,不能再提交审核"];
  237. }
  238. return json(["msg" => "已提交审核,请耐心等待"]);
  239. }
  240. public function delete() {
  241. $id = $this->request->param("talentInfoId");
  242. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  243. if (!$info) {
  244. return json(["msg" => "操作失败"]);
  245. }
  246. $checkState = $info["checkState"];
  247. if (in_array($checkState, [0, 1])) {
  248. $log = TalentLogApi::getLastLog($id, 1);
  249. if ($log["state"] > 1) {
  250. //有提交审核记录
  251. return json(["msg" => "操作失败"]);
  252. }
  253. }
  254. $data["id"] = $id;
  255. $data["delete"] = 1;
  256. TalentModel::update($data);
  257. return json(["msg" => "删除成功"]);
  258. }
  259. static private function chkIsOwner($id, $uid) {
  260. $where[] = ["id", "=", $id];
  261. $where[] = ["enterprise_id", "=", $uid];
  262. $info = TalentModel::where($where)->findOrEmpty()->toArray();
  263. return $info;
  264. }
  265. }