Base.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. $no_empty[] = "tax_insurance_month";
  77. if ($param["talent_type"] == 3)
  78. $no_empty[] = "labor_contract_rangetime";
  79. $return = [];
  80. foreach ($no_empty as $key) {
  81. if (!$param[$key]) {
  82. $return[] = sprintf("请填写“%s”", $filed_dict[$key]);
  83. }
  84. }
  85. if (count($return) > 0) {
  86. $res = ["msg" => implode("<br>", $return)];
  87. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  88. exit;
  89. }
  90. $where = [];
  91. $where[] = ["step", "=", 1];
  92. $where[] = ["project", "=", 1];
  93. $where[] = ["type", "=", $this->user["type"]];
  94. $where[] = ["must", "=", 1];
  95. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  96. $ft_ids = array_column($filetypes, "id");
  97. $whr = [];
  98. $upload_type_counts = 0;
  99. if ($files) {
  100. $whr[] = ["typeId", "in", $ft_ids];
  101. $whr[] = ["id", "in", $files];
  102. $upload_type_counts = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->count();
  103. }
  104. if ($upload_type_counts != count($ft_ids)) {
  105. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
  106. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  107. exit;
  108. }
  109. $data["enterprise_id"] = $this->user["uid"];
  110. $data["talent_type"] = $param["talent_type"];
  111. $data["tax_insurance_month"] = $param["tax_insurance_month"];
  112. $data["labor_contract_rangetime"] = $param["labor_contract_rangetime"];
  113. $data["name"] = $param["name"];
  114. $data["card_type"] = $param["card_type"];
  115. $data["card_number"] = $param["card_number"];
  116. $data["sex"] = $param["sex"];
  117. $data["birthday"] = $param["birthday"];
  118. $data["nationality"] = $param["nationality"];
  119. $data["province"] = $param["province"];
  120. $data["city"] = $param["city"];
  121. $data["county"] = $param["county"];
  122. $data["nation"] = $param["nation"];
  123. $data["politics"] = $param["politics"];
  124. if ($id > 0) {
  125. TalentModel::update($data);
  126. } else {
  127. $data["checkState"] = TalentState::FST_SAVE;
  128. $id = TalentModel::insertGetId($data);
  129. TalentLogApi::write(1, $id, TalentState::FST_SAVE, "添加人才认定申报", 1);
  130. }
  131. if ($id) {
  132. $whr = [];
  133. $whr[] = ["id", "in", $files];
  134. Db::table("new_talent_file")->where($whr)->save(["mainId" => $id]);
  135. $res = ["code" => 200, "msg" => "保存成功", "obj" => ["id" => $id, "checkState" => TalentState::FST_SAVE]];
  136. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  137. } else {
  138. $res = ["msg" => "保存失败"];
  139. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  140. }
  141. exit();
  142. }
  143. $checkState = $info["checkState"] ?: 0;
  144. $enterprise_info = \app\common\model\Enterprise::find($this->user["uid"]);
  145. $info["enterprise"] = $enterprise_info;
  146. $info["talent_type_list"] = \app\common\api\DictApi::findChildDictByCode("talent_type");
  147. return view("first", ["year" => date("Y"), "checkState" => $checkState, "row" => $info]);
  148. }
  149. public function view(\think\Request $request) {
  150. $id = $request->param("id");
  151. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  152. return view("view", ["row" => $info]);
  153. }
  154. // 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  155. public function submit() {
  156. $id = $this->request->param("id");
  157. if (!$info = self::chkIsOwner($id, $this->user["uid"]))
  158. return json(["msg" => "没有对应的人才认定申报信息"]);
  159. $checkState = $info["checkState"];
  160. if ($checkState == TalentState::BASE_VERIFY_PASS || $checkState == 0) {
  161. return json(["msg" => '请先保存资料并上传相应附件后再点击提交审核']);
  162. } else if ($checkState == TalentState::FST_SAVE) {
  163. //初次提交材料
  164. $where = [];
  165. $where[] = ["step", "=", 1];
  166. $where[] = ["project", "=", 1];
  167. $where[] = ["type", "=", $this->user["type"]];
  168. $where[] = ["must", "=", 1];
  169. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  170. $ft_ids = array_column($filetypes, "id");
  171. $whr = [];
  172. $upload_type_counts = 0;
  173. if ($ft_ids) {
  174. $whr[] = ["typeId", "in", $ft_ids];
  175. $whr[] = ["mainId", "=", $id];
  176. $upload_type_counts = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->count();
  177. }
  178. if ($upload_type_counts != count($ft_ids)) {
  179. return json(["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"]);
  180. }
  181. $change_state = TalentState::FST_SUBMIT; //等待审核
  182. $data["id"] = $id;
  183. $data["checkState"] = $change_state;
  184. $data["first_submit_time"] = date("Y-m-d H:i:s");
  185. $data["active"] = 1;
  186. TalentModel::update($data);
  187. TalentLogApi::write(1, $id, $change_state, "提交基础判定材料待审核", 1);
  188. return json(["code" => 200, "msg" => "提交成功"]);
  189. } else if ($checkState == TalentState::REVERIFY_FAIL) {
  190. return ["msg" => "审核失败,不能再提交审核"];
  191. }
  192. return json(["msg" => "已提交审核,请耐心等待"]);
  193. }
  194. public function delete() {
  195. $id = $this->request->param("talentInfoId");
  196. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  197. if (!$info) {
  198. return json(["msg" => "操作失败"]);
  199. }
  200. $checkState = $info["checkState"];
  201. if (in_array($checkState, [0, 1])) {
  202. $log = TalentLogApi::getLastLog($id, 1);
  203. if ($log["state"] > 1) {
  204. //有提交审核记录
  205. return json(["msg" => "操作失败"]);
  206. }
  207. }
  208. $data["id"] = $id;
  209. $data["delete"] = 1;
  210. TalentModel::update($data);
  211. return json(["msg" => "删除成功"]);
  212. }
  213. static private function chkIsOwner($id, $uid) {
  214. $where[] = ["id", "=", $id];
  215. $where[] = ["enterprise_id", "=", $uid];
  216. $info = TalentModel::where($where)->findOrEmpty()->toArray();
  217. return $info;
  218. }
  219. }