Base.php 14 KB

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