Education.php 19 KB

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