Education.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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["description"] = "";
  148. $log["createUser"] = "申报用户";
  149. $log["createTime"] = date("Y-m-d H:i:s");
  150. TalentLog::create($log);
  151. $response->code = 200;
  152. $response->obj = $data;
  153. return json($response);
  154. } catch (ValidateException $e) {
  155. $response->msg = $e->getMessage();
  156. return json($response);
  157. } catch (\think\Exception $e) {
  158. $response->msg = "发生预料外错误,请联系管理员处理,错误代码:" . $e->getCode();
  159. $logInfo = [
  160. "personId" => $this->user["uid"],
  161. "data" => $data,
  162. "controller" => $this->request->controller(),
  163. "action" => $this->request->action(),
  164. "errCode" => $e->getCode(),
  165. "errMsg" => $e->getMessage()
  166. ];
  167. Log::write($logInfo, "error");
  168. return json($response);
  169. }
  170. }
  171. /**
  172. * 提交表单
  173. */
  174. public function submitToCheck() {
  175. $response = new \stdClass();
  176. $response->code = 500;
  177. try {
  178. $id = $this->request["id"];
  179. $info = EducationApi::getInfoById($id);
  180. if (!$info) {
  181. throw new ValidateException("提交审核失败,请先填写基础信息");
  182. }
  183. if ($info["personId"] != $this->user["uid"]) {
  184. throw new ValidateException("没有对应的子女择校申报信息");
  185. }
  186. $batch = BatchApi::checkBatchValid(["type" => ProjectState::EDUCATION, "year" => $info["year"], "first_submit_time" => $info["firstSubmitTime"]], $this->user["type"]);
  187. if ($batch["code"] != 200) {
  188. throw new ValidateException($batch["msg"]);
  189. }
  190. validate(EducationSchoolValidator::class)->check($info);
  191. $where = [];
  192. $where[] = ["mainId", "=", $id];
  193. $where[] = ["type", "=", ProjectState::EDUCATION];
  194. $uploadedFileTypes = Db::table("new_talent_file")->where($where)->column("distinct typeId");
  195. $where = [];
  196. $where[] = ["project", "=", ProjectState::EDUCATION];
  197. $where[] = ["type", "=", $this->user["type"]];
  198. $where[] = ["must", "=", 1];
  199. $where[] = ["active", "=", 1];
  200. $where[] = ["delete", "=", 0];
  201. $where[] = ["id", "not in", $uploadedFileTypes];
  202. $unUploadfiletypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  203. if ($unUploadfiletypes) {
  204. $msg = "以下附件为必传:<br>";
  205. foreach ($unUploadfiletypes as $ft) {
  206. $msg .= "<span style='color:red;'>*</span>" . $ft["name"] . "<br>";
  207. }
  208. throw new ValidateException($msg);
  209. }
  210. $data["id"] = $id;
  211. $data["checkState"] = $info["checkState"] == 2 ? 9 : 1;
  212. if (!$info["firstSubmitTime"]) {
  213. $data["firstSubmitTime"] = date("Y-m-d H:i:s");
  214. }
  215. $data["newSubmitTime"] = date("Y-m-d H:i:s");
  216. EduModel::update($data);
  217. $log["id"] = getStringId();
  218. $log["active"] = 1;
  219. $log["state"] = $data["checkState"];
  220. $log["step"] = 0;
  221. $log["stateChange"] = MainState::getStateDesc($data["checkState"]) . "->" . MainState::getStateDesc(MainState::NEED_CHECK);
  222. $log["type"] = ProjectState::EDUCATION;
  223. $log["mainId"] = $id;
  224. $log["description"] = "确认提交审核";
  225. $log["createUser"] = "申报用户";
  226. $log["createTime"] = date("Y-m-d H:i:s");
  227. TalentLog::create($log);
  228. $response->msg = "提交审核成功";
  229. $response->code = 200;
  230. $response->obj = 1;
  231. return json($response);
  232. } catch (ValidateException $e) {
  233. $response->msg = $e->getMessage();
  234. return json($response);
  235. } catch (\think\Exception $e) {
  236. $response->msg = "发生预料外错误,请联系管理员处理,错误代码:" . $e->getCode();
  237. $logInfo = [
  238. "personId" => $this->user["uid"],
  239. "data" => $data,
  240. "controller" => $this->request->controller(),
  241. "action" => $this->request->action(),
  242. "errCode" => $e->getCode(),
  243. "errMsg" => $e->getMessage()
  244. ];
  245. Log::write($logInfo, "error");
  246. return json($response);
  247. }
  248. }
  249. public function delete() {
  250. $id = $this->request->param("id");
  251. $info = EducationApi::getInfoById($id);
  252. if (!$info || $info["personId"] != $this->user["uid"]) {
  253. return json(["msg" => "操作失败"]);
  254. }
  255. $checkState = $info["checkState"];
  256. if ($checkState != MainState::SAVE) {
  257. return json(["msg" => "该申报已提交审核,无法删除"]);
  258. }
  259. EduModel::delete($id);
  260. $where = [["mainId", "=", $id], ["type", "=", ProjectState::EDUCATION]];
  261. $list = Db::table("new_talent_file")->where($where)->select()->toArray();
  262. foreach ($list as $key => $file) {
  263. if (!empty($file["url"])) {
  264. $filepath = "storage/" . $file["url"];
  265. if (file_exists($filepath)) {
  266. @unlink($filepath);
  267. }
  268. }
  269. Db::table("new_talent_file")->delete($file["id"]);
  270. }
  271. return json(["msg" => "删除成功"]);
  272. }
  273. public function validateIsAdd() {
  274. $response = new \stdClass();
  275. $response->code = 500;
  276. $projectType = ProjectState::EDUCATION;
  277. $source = $this->user["type"];
  278. $batchResult = BatchApi::checkBatchValid(["type" => $projectType], $source);
  279. if ($batchResult["code"] != 200) {
  280. $response->msg = $batchResult["msg"];
  281. return json($response);
  282. }
  283. $batch = $batchResult["batch"];
  284. $where = [];
  285. $where[] = ["card_number", "=", $this->user["idCard"]];
  286. $where[] = ["checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  287. $where[] = ["isEffect", "=", 1];
  288. $list = \app\enterprise\model\Talent::where($where)->select()->toArray();
  289. if (!$list || count($list) == 0) {
  290. $response->msg = "未查询到有效的人才数据(根据证件号码匹配),无法申报";
  291. return json($response);
  292. }
  293. if (count($list) > 1) {
  294. $response->msg = "根据证件号码查询到多条在库数据,无法申报,可联系相关单位取消重复人才资格";
  295. return json($response);
  296. }
  297. $info = $list[0];
  298. if ($this->user["type"] == 1 && (!strtotime($info["certificateExpireTime"]) || strtotime($info["certificateExpireTime"]) < time())) {
  299. $response->msg = "您的人才证书已过期,请进行人才层次变更后再申报";
  300. return json($response);
  301. }
  302. $response->code = 200;
  303. $response->batch = $batch;
  304. return json($response);
  305. }
  306. }