Base.php 12 KB

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