Education.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <?php
  2. namespace app\person\controller;
  3. use app\person\common\PersonController;
  4. use app\common\state\ProjectState;
  5. use app\common\state\MainState;
  6. use app\common\api\EducationApi;
  7. use app\common\api\BatchApi;
  8. use app\common\model\EducationSchool as EduModel;
  9. use think\facade\Db;
  10. use app\person\validate\EducationSchoolValidator;
  11. use app\common\model\TalentLog;
  12. use think\facade\Log;
  13. use think\exception\ValidateException;
  14. /**
  15. * Description of Education
  16. *
  17. * @author sgq
  18. */
  19. class Education extends PersonController {
  20. public function index() {
  21. return view("", ['type' => session("user")['type']]);
  22. }
  23. public function list() {
  24. $res = EducationApi::getList($this->request);
  25. return json($res);
  26. }
  27. /**
  28. * 申请
  29. */
  30. public function apply(\think\Request $request) {
  31. $type = $this->user["type"];
  32. $param = $request->param();
  33. $id = isset($param["id"]) ? $param["id"] : 0;
  34. $info = EducationApi::getInfoById($id);
  35. if (!$info) {
  36. $where = [];
  37. $where[] = ["checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  38. $where[] = ["card_number", "=", $this->user["idCard"]];
  39. $where[] = ["isEffect", "=", 1];
  40. $talentInfo = \app\enterprise\model\Talent::where($where)->find();
  41. $talentCondition = \app\common\api\TalentConditionApi::getOne($talentInfo["talent_condition"]);
  42. $info["personId"] = $this->user["uid"];
  43. $info["type"] = $this->user["type"];
  44. $info["talentId"] = $talentInfo["id"];
  45. $info["pName"] = $talentInfo["name"];
  46. $info["pSex"] = $talentInfo["sex"];
  47. $info["pIdcard"] = $talentInfo["card_number"];
  48. $info["talentArrange"] = $talentInfo["talent_arrange"];
  49. $info["identifyCondition"] = $talentCondition["name"];
  50. $info["certificateStartTime"] = $talentInfo["certificateGetTime"];
  51. $info["qzgccrcActiveTime"] = $talentInfo["certificateExpireTime"];
  52. $info["certificateNo"] = $talentInfo["certificateNo"];
  53. $area = [];
  54. if ($talentInfo["province"]) {
  55. $area[] = Db::table("un_common_location")->where("code", "=", $talentInfo["province"])->findOrEmpty()["name"];
  56. }
  57. if ($talentInfo["city"]) {
  58. $area[] = Db::table("un_common_location")->where("code", "=", $talentInfo["city"])->findOrEmpty()["name"];
  59. }
  60. if ($talentInfo["county"]) {
  61. $area[] = Db::table("un_common_location")->where("code", "=", $talentInfo["county"])->findOrEmpty()["name"];
  62. }
  63. $info["nativePlace"] = implode("", $area);
  64. $info["certificateNo"] = $talentInfo["certificateNo"];
  65. $info["phone"] = $talentInfo["phone"];
  66. }
  67. if ($request->isPost()) {
  68. return $this->save($info, $request);
  69. }
  70. $batch = $info["year"] ?: BatchApi::getValidBatch(ProjectState::EDUCATION, $type)["batch"];
  71. return view("", ["year" => $batch, "row" => $info]);
  72. }
  73. public function detail(\think\Request $request) {
  74. $param = $request->param();
  75. $id = $param["id"];
  76. $info = EducationApi::getInfoById($id);
  77. return view("apply", ["row" => $info]);
  78. }
  79. public function save($info, \think\Request $request) {
  80. $response = new \stdClass();
  81. $response->code = 500;
  82. try {
  83. $batch = BatchApi::checkBatchValid(["type" => ProjectState::EDUCATION, "year" => $info["year"], "first_submit_time" => $info["firstSubmitTime"]], $this->user["type"]);
  84. if ($batch["code"] != 200) {
  85. throw new ValidateException($batch["msg"]);
  86. }
  87. $data = $request->param();
  88. unset($data["jstime"]); //不知道为啥把get的数据也获取了,先这样处理
  89. $data["year"] = $batch["batch"];
  90. validate(EducationSchoolValidator::class)->check($data);
  91. $id = $data["id"];
  92. if ($id) {
  93. if (!$info || $info["id"] != $id || $info["personId"] != $this->user["uid"]) {
  94. throw new ValidateException("没有对应的子女择校申报信息");
  95. }
  96. $data["updateTime"] = date("Y-m-d H:i:s");
  97. $data["updateUser"] = $this->user["uid"];
  98. EduModel::update($data);
  99. $log["stateChange"] = "修改子女就学申报";
  100. $response->msg = "修改成功";
  101. } else {
  102. $talentInfo = \app\enterprise\api\TalentApi::getOne($info["talentId"]);
  103. if (!$talentInfo || $talentInfo["checkState"] != \app\common\api\TalentState::CERTIFICATED) {
  104. throw new ValidateException("未查询到有效的人才数据(根据证件号码匹配),无法申报");
  105. }
  106. if (!strtotime($talentInfo["certificateExpireTime"]) || strtotime($talentInfo["certificateExpireTime"]) < time()) {
  107. throw new ValidateException("您的人才证书已过期,请进行人才层次变更后再申报");
  108. }
  109. if ($this->user["type"] == 1 && $talentInfo["talent_arrange"] > 5) {
  110. throw new ValidateException("子女择校政策只针对第一至五层次人才!");
  111. }
  112. $area = [];
  113. if ($talentInfo["province"]) {
  114. $area[] = Db::table("un_common_location")->where("code", "=", $talentInfo["province"])->findOrEmpty()["name"];
  115. }
  116. if ($talentInfo["city"]) {
  117. $area[] = Db::table("un_common_location")->where("code", "=", $talentInfo["city"])->findOrEmpty()["name"];
  118. }
  119. if ($talentInfo["county"]) {
  120. $area[] = Db::table("un_common_location")->where("code", "=", $talentInfo["county"])->findOrEmpty()["name"];
  121. }
  122. $data["id"] = getStringId();
  123. $data["personId"] = $this->user["uid"];
  124. $data["pName"] = $talentInfo["name"];
  125. $data["pSex"] = $talentInfo["sex"];
  126. $data["pIdcard"] = $talentInfo["card_number"];
  127. $data["talentArrange"] = $talentInfo["talent_arrange"];
  128. $talentCondition = \app\common\api\TalentConditionApi::getOne($talentInfo["talent_condition"]);
  129. $data["identifyCondition"] = $talentCondition["name"];
  130. $data["certificateNo"] = $talentInfo["certificateNo"];
  131. $data["certificateStartTime"] = $talentInfo["certificateGetTime"];
  132. $data["qzgccrcActiveTime"] = $talentInfo["certificateExpireTime"];
  133. $data["nativePlace"] = implode("", $area);
  134. $data["checkState"] = -2;
  135. $data["createTime"] = date("Y-m-d H:i:s");
  136. $data["createUser"] = $this->user["uid"];
  137. EduModel::insert($data);
  138. $log["stateChange"] = "添加子女就学申报";
  139. $response->msg = "添加成功";
  140. }
  141. $log["id"] = getStringId();
  142. $log["active"] = 1;
  143. $log["state"] = -2;
  144. $log["step"] = 0;
  145. $log["type"] = ProjectState::EDUCATION;
  146. $log["mainId"] = $data["id"];
  147. $log["createUser"] = "申报用户";
  148. $log["createTime"] = date("Y-m-d H:i:s");
  149. TalentLog::create($log);
  150. $response->code = 200;
  151. $response->obj = $data;
  152. return json($response);
  153. } catch (ValidateException $e) {
  154. $response->msg = $e->getMessage();
  155. return json($response);
  156. } catch (\think\Exception $e) {
  157. $response->msg = "发生预料外错误,请联系管理员处理,错误代码:" . $e->getCode();
  158. $logInfo = [
  159. "personId" => $this->user["uid"],
  160. "data" => $data,
  161. "controller" => $this->request->controller(),
  162. "action" => $this->request->action(),
  163. "errCode" => $e->getCode(),
  164. "errMsg" => $e->getMessage()
  165. ];
  166. Log::write($logInfo, "error");
  167. return json($response);
  168. }
  169. }
  170. /**
  171. * 提交表单
  172. */
  173. public function submitToCheck() {
  174. $response = new \stdClass();
  175. $response->code = 500;
  176. try {
  177. $id = $this->request["id"];
  178. $info = EducationApi::getInfoById($id);
  179. if (!$info) {
  180. throw new ValidateException("提交审核失败,请先填写基础信息");
  181. }
  182. if ($info["personId"] != $this->user["uid"]) {
  183. throw new ValidateException("没有对应的子女择校申报信息");
  184. }
  185. $batch = BatchApi::checkBatchValid(["type" => ProjectState::EDUCATION, "year" => $info["year"], "first_submit_time" => $info["firstSubmitTime"]], $this->user["type"]);
  186. if ($batch["code"] != 200) {
  187. throw new ValidateException($batch["msg"]);
  188. }
  189. validate(EducationSchoolValidator::class)->check($info);
  190. $where = [];
  191. $where[] = ["mainId", "=", $id];
  192. $where[] = ["type", "=", ProjectState::EDUCATION];
  193. $uploadedFileTypes = Db::table("new_talent_file")->where($where)->column("distinct typeId");
  194. $where = [];
  195. $where[] = ["project", "=", ProjectState::EDUCATION];
  196. $where[] = ["type", "=", $this->user["type"]];
  197. $where[] = ["must", "=", 1];
  198. $where[] = ["active", "=", 1];
  199. $where[] = ["delete", "=", 0];
  200. $where[] = ["id", "not in", $uploadedFileTypes];
  201. $unUploadfiletypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  202. if ($unUploadfiletypes) {
  203. $msg = "以下附件为必传:<br>";
  204. foreach ($unUploadfiletypes as $ft) {
  205. $msg .= "<span style='color:red;'>*</span>" . $ft["name"] . "<br>";
  206. }
  207. throw new ValidateException($msg);
  208. }
  209. $data["id"] = $id;
  210. $data["checkState"] = $info["checkState"] == 2 ? 9 : 1;
  211. if (!$info["firstSubmitTime"]) {
  212. $data["firstSubmitTime"] = date("Y-m-d H:i:s");
  213. }
  214. $data["newSubmitTime"] = date("Y-m-d H:i:s");
  215. EduModel::update($data);
  216. $log["id"] = getStringId();
  217. $log["active"] = 1;
  218. $log["state"] = $data["checkState"];
  219. $log["step"] = 0;
  220. $log["stateChange"] = MainState::getStateDesc($data["checkState"]) . "->" . MainState::getStateDesc(MainState::NEED_CHECK);
  221. $log["type"] = ProjectState::EDUCATION;
  222. $log["mainId"] = $id;
  223. $log["description"] = "确认提交审核";
  224. $log["createUser"] = "申报用户";
  225. $log["createTime"] = date("Y-m-d H:i:s");
  226. TalentLog::create($log);
  227. $response->msg = "提交审核成功";
  228. $response->code = 200;
  229. $response->obj = 1;
  230. return json($response);
  231. } catch (ValidateException $e) {
  232. $response->msg = $e->getMessage();
  233. return json($response);
  234. } catch (\think\Exception $e) {
  235. $response->msg = "发生预料外错误,请联系管理员处理,错误代码:" . $e->getCode();
  236. $logInfo = [
  237. "personId" => $this->user["uid"],
  238. "data" => $data,
  239. "controller" => $this->request->controller(),
  240. "action" => $this->request->action(),
  241. "errCode" => $e->getCode(),
  242. "errMsg" => $e->getMessage()
  243. ];
  244. Log::write($logInfo, "error");
  245. return json($response);
  246. }
  247. }
  248. public function delete() {
  249. $id = $this->request->param("id");
  250. $info = EducationApi::getInfoById($id);
  251. if (!$info || $info["personId"] != $this->user["uid"]) {
  252. return json(["msg" => "操作失败"]);
  253. }
  254. $checkState = $info["checkState"];
  255. if ($checkState != MainState::SAVE) {
  256. return json(["msg" => "该申报已提交审核,无法删除"]);
  257. }
  258. EduModel::delete($id);
  259. $where = [["mainId", "=", $id], ["type", "=", ProjectState::EDUCATION]];
  260. $list = Db::table("new_talent_file")->where($where)->select()->toArray();
  261. foreach ($list as $key => $file) {
  262. if (!empty($file["url"])) {
  263. $filepath = "storage/" . $file["url"];
  264. if (file_exists($filepath)) {
  265. @unlink($filepath);
  266. }
  267. }
  268. Db::table("new_talent_file")->delete($file["id"]);
  269. }
  270. return json(["msg" => "删除成功"]);
  271. }
  272. public function validateIsAdd() {
  273. $response = new \stdClass();
  274. $response->code = 500;
  275. $projectType = ProjectState::EDUCATION;
  276. $source = $this->user["type"];
  277. $batchResult = BatchApi::checkBatchValid(["type" => $projectType], $source);
  278. if ($batchResult["code"] != 200) {
  279. $response->msg = $batchResult["msg"];
  280. return json($response);
  281. }
  282. $batch = $batchResult["batch"];
  283. $where = [];
  284. $where[] = ["card_number", "=", $this->user["idCard"]];
  285. $where[] = ["checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  286. $where[] = ["isEffect", "=", 1];
  287. $list = \app\enterprise\model\Talent::where($where)->select()->toArray();
  288. if (!$list || count($list) == 0) {
  289. $response->msg = "未查询到有效的人才数据(根据证件号码匹配),无法申报";
  290. return json($response);
  291. }
  292. if (count($list) > 1) {
  293. $response->msg = "根据证件号码查询到多条在库数据,无法申报,可联系相关单位取消重复人才资格";
  294. return json($response);
  295. }
  296. $info = $list[0];
  297. if ($this->user["type"] == 1 && (!strtotime($info["certificateExpireTime"]) || strtotime($info["certificateExpireTime"]) < time())) {
  298. $response->msg = "您的人才证书已过期,请进行人才层次变更后再申报";
  299. return json($response);
  300. }
  301. $response->code = 200;
  302. $response->batch = $batch;
  303. return json($response);
  304. }
  305. }