Education.php 14 KB

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