Talent.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <?php
  2. namespace app\job;
  3. use think\queue\Job;
  4. use think\facade\Log;
  5. use think\facade\Db;
  6. use app\common\api\ChuanglanSmsApi;
  7. use app\common\model\MessageRecord;
  8. use app\common\api\TalentLogApi;
  9. use app\common\api\TalentConditionApi;
  10. use app\common\api\TalentState;
  11. use app\enterprise\model\Talent as TalentModel;
  12. use app\common\state\ProjectState;
  13. use app\common\state\CommonConst;
  14. /**
  15. * Description of Talent
  16. *
  17. * @author sgq
  18. */
  19. class Talent {
  20. public function fire(Job $job, $data) {
  21. if ($this->deal($data)) {
  22. $job->delete();
  23. return true;
  24. }
  25. if ($job->attempts() >= 3) {
  26. $job->delete();
  27. return false;
  28. }
  29. $job->release(10); //10秒后重试
  30. }
  31. /**
  32. * 处理业务逻辑
  33. * @param type $data
  34. * @return bool
  35. */
  36. public function deal($data): bool {
  37. switch ($data["type"]) {
  38. case 1:
  39. //部门超时驳回
  40. $mainId = $data["id"];
  41. $where[] = ["ti.id", "=", $mainId];
  42. $where[] = ["ti.checkState", "=", TalentState::FST_VERIFY_PASS];
  43. $where[] = ["ti.pass_dept_check", "=", 0];
  44. $talent_info = TalentModel::alias("ti")
  45. ->leftJoin("new_talent_condition tc", "tc.id=ti.talent_condition")
  46. ->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")
  47. ->leftJoin("(select description,mainId,last_state,new_state,state,createTime from new_talent_checklog where md5(concat(createTime,mainId,`type`)) in (select md5(concat(max(createTime),mainId,`type`)) from `new_talent_checklog` where `type`=1 and `step` is null and active=1 and typeFileId is null group by mainId,`type`)) tl", "`tl`.`mainId`=ti.id")
  48. ->where($where)->field("ti.*,tc.companyIds,tc.companyWithFileType,e.type as enterpriseType")->find();
  49. if ($talent_info && !in_array($talent_info["enterpriseType"], [CommonConst::ENTERPRISE_WJ, CommonConst::ENTERPRISE_GJ])) {
  50. $weekDay = date("w"); //0周日,6周六
  51. if ($weekDay == 6) {
  52. $delay = 2 * 24 * 3600;
  53. queue("app\job\Talent", ["type" => 1, "id" => $mainId], $delay);
  54. return true;
  55. }
  56. if (!$weekDay || $weekDay == 0) {
  57. $delay = 1 * 24 * 3600;
  58. queue("app\job\Talent", ["type" => 1, "id" => $mainId], $delay);
  59. return true;
  60. }
  61. $modify_files = array_filter(explode(",", $talent_info["modify_files"]));
  62. $companyAndTypes = [];
  63. $companyWithFileType = array_filter(explode(";", $talent_info["companyWithFileType"]));
  64. foreach ($companyWithFileType as $c) {
  65. list($companyId, $fileTypesStr) = array_filter(explode(":", $c));
  66. $companyAndTypes[$companyId] = array_filter(explode(",", $fileTypesStr));
  67. }
  68. $companyIds = array_filter(explode(",", $talent_info["companyIds"]));
  69. if ($companyIds) {
  70. /* if ($talent_info["re_check_companys"]) {
  71. $unpass_companyIds = array_filter(explode(",", $talent_info["re_check_companys"]));
  72. } else {
  73. //这边去除已经审核通过的单位,主要通过日志是否存在记录。
  74. $pass_companyIds = TalentLogApi::getPassDepts($talent_info["id"]); //已经通过的单位
  75. $unpass_companyIds = array_diff($companyIds, (array) $pass_companyIds); //排除已经通过的单位
  76. } */
  77. $pass_companyIds = TalentLogApi::getPassDepts($talent_info["id"]); //已经通过的单位
  78. $re_check_companys = $talent_info["re_check_companys"] ? array_filter(explode(",", $talent_info["re_check_companys"])) : [];
  79. $companyIds = \app\common\api\VerifyApi::getNewReCheckCompanyIds($re_check_companys, $companyIds, $pass_companyIds);
  80. $unpass_companyIds = array_diff($companyIds, (array) $pass_companyIds); //排除已经通过的单位
  81. if (!$unpass_companyIds) {
  82. //没有未审部门
  83. return true;
  84. }
  85. //开始驳回操作
  86. $fst_dept_check_time = $talent_info["first_dept_check_time"];
  87. $log_checkState = TalentState::FST_VERIFY_PASS; //当前状态不变
  88. $checkState = TalentState::SCND_SUBMIT; //退回待初审
  89. foreach ($unpass_companyIds as $companyId) {
  90. $fileTypes = $companyAndTypes[$companyId];
  91. $modify_files = array_unique((array_merge((array) $modify_files, (array) $fileTypes)));
  92. $dept_log = TalentLogApi::getLogByCompanyId($talent_info["id"], $companyId, $fst_dept_check_time);
  93. if ($dept_log) {
  94. TalentLogApi::rewrite($dept_log["id"], [$log_checkState, $checkState], "审核超时,系统自动驳回", 1);
  95. } else {
  96. TalentLogApi::write(ProjectState::TALENT, $talent_info["id"], [$log_checkState, $checkState, 3], "审核超时,系统自动驳回", 1, null, null, $companyId); //补一条记录
  97. sleep(1);
  98. }
  99. }
  100. $log_checkState = TalentState::DEPT_VERIFY_REJECT;
  101. $save["id"] = $talent_info["id"];
  102. $save["modify_files"] = implode(",", $modify_files);
  103. $save["checkState"] = $checkState;
  104. $save["highProcess"] = $talent_info["highProcess"] > 3 ? $talent_info["highProcess"] : 3;
  105. $save["first_dept_check_time"] = null;
  106. $save["re_check_companys"] = null;
  107. TalentModel::update($save);
  108. TalentLogApi::write(1, $talent_info["id"], [$log_checkState, $checkState], "审核超时,系统自动驳回,部门审核结束", 1);
  109. }
  110. return true;
  111. }
  112. break;
  113. case 2:
  114. //超过批次提交时间审核失败
  115. $talentInfo = $data["talentInfo"];
  116. $projectType = ProjectState::TALENT; //项目类型
  117. $mainId = $talentInfo["id"]; //申报id
  118. $checkState = TalentState::FST_VERIFY_FAIL; //系统审核失败状态,初审不通过
  119. if ($talentInfo["checkState"] == TalentState::SCND_SAVE) {
  120. $where = [];
  121. $where[] = ["active", "=", 1];
  122. $where[] = ["type", "=", $projectType];
  123. $where[] = ["source", "=", $talentInfo["enterpriseType"]];
  124. $where[] = ["batch", "=", $talentInfo["apply_year"]];
  125. $whereRaw = sprintf("submitEndTime is not null and submitEndTime<>'' and submitEndTime < '%s'", date("Y-m-d H:i:s"));
  126. $batch = \app\common\model\Batch::where($where)->whereRaw($whereRaw)->find();
  127. if ($batch) {
  128. $save["id"] = $mainId;
  129. $save["checkState"] = $checkState;
  130. TalentModel::update($save);
  131. TalentLogApi::write($projectType, $mainId, $checkState, "超过该批次提交截止时间未提交审核,系统自动结束该申报", 1);
  132. }
  133. return true;
  134. }
  135. break;
  136. case 3:
  137. //撤销超时审核失败
  138. $talentInfo = $data["talentInfo"];
  139. $projectType = ProjectState::TALENT; //项目类型
  140. $mainId = $talentInfo["id"]; //申报id
  141. $checkState = TalentState::SCND_SAVE; //系统审核失败状态,初审不通过
  142. $last_log = TalentLogApi::getLastLog($mainId, $projectType, 0, ["active", "=", 1]);
  143. if ($talentInfo["checkState"] == TalentState::FST_VERIFY_FAIL && $last_log["state"] == TalentState::FST_VERIFY_FAIL && $last_log["createUser"] == "系统") {
  144. $where = [];
  145. $where[] = ["active", "=", 1];
  146. $where[] = ["type", "=", $projectType];
  147. $where[] = ["source", "=", $talentInfo["enterpriseType"]];
  148. $where[] = ["batch", "=", $talentInfo["apply_year"]];
  149. $whereRaw = sprintf("submitEndTime is null or submitEndTime<>'' or submitEndTime > '%s'", date("Y-m-d H:i:s"));
  150. $batch = \app\common\model\Batch::where($where)->whereRaw($whereRaw)->find();
  151. $extra_where[] = ["active", "=", 1];
  152. $extra_where[] = ["createUser", "<>", "系统"];
  153. $last_log = TalentLogApi::getLastLogEx($mainId, $projectType, 0, $extra_where);
  154. if ($batch && $last_log) {
  155. $save["id"] = $mainId;
  156. $save["checkState"] = $checkState;
  157. TalentModel::update($save);
  158. TalentLogApi::write($projectType, $mainId, [$last_log["state"], $last_log["new_state"]], "该批次经人社局操作,已延长申报提交截止时间,现由人才办交办,对被自动审核失败的申报进行状态处理,恢复至初审驳回。该申报已处理。", 1);
  159. }
  160. return true;
  161. }
  162. break;
  163. case 4:
  164. //发放人才码后增加积分记录
  165. try {
  166. $mainId = $data["id"];
  167. $where = [];
  168. $where[] = ["ti.id", "=", $mainId];
  169. $where[] = ["ti.checkState", "=", TalentState::CERTIFICATED];
  170. $talentInfo = TalentModel::alias("ti")->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")->field("ti.*,e.type as enterpriseType")->where($where)->find();
  171. $where = [];
  172. $where[] = ["mainId", "=", $mainId];
  173. $where[] = ["mainType", "=", "talent"];
  174. $integralLog = Db::table("new_integral_log")->where($where)->find();
  175. if ($talentInfo && !$integralLog) {
  176. $level = $talentInfo["talent_arrange"];
  177. $name = $talentInfo["name"]; //姓名
  178. $cardType = $talentInfo["card_type"]; //身份证类型
  179. $cardNumber = $talentInfo["card_number"]; //身份证
  180. $type = $talentInfo["enterpriseType"]; //企业类型
  181. $lastPoints = 0; //上次积分
  182. $gainPoints = CommonConst::getLayerPointsByLayer($level); //增加积分
  183. $desc = sprintf("经人才申报审核通过,认定为集成电路(%s)优秀人才,基础分变更为%d分。", CommonConst::getLayerNameByLayer($level), $gainPoints); //详情
  184. /* 查询是否升级 */
  185. $where = [];
  186. $where[] = ["id", "<>", $mainId];
  187. //$where[] = ["name", "=", $name];
  188. $where[] = ["card_type", "=", $cardType];
  189. $where[] = ["card_number", "=", $cardNumber];
  190. $where[] = ["checkState", "=", TalentState::CERTIFICATED];
  191. $talentBeforeInfo = TalentModel::where($where)->order("createTime desc")->find();
  192. if ($talentBeforeInfo && $level < $talentBeforeInfo["talent_arrange"]) {
  193. $beforeLevelName = CommonConst::getLayerNameByLayer($talentBeforeInfo["talent_arrange"]); //之前层次
  194. $beforeLevelPoints = CommonConst::getLayerPointsByLayer($talentBeforeInfo["talent_arrange"]); //之前基础分
  195. $nowLevelName = CommonConst::getLayerNameByLayer($level); //现在层次
  196. $nowLevelPoints = CommonConst::getLayerPointsByLayer($level); //现在基础分
  197. $gainPoints -= $beforeLevelPoints;
  198. $desc = sprintf("人才层次晋升(%s->%s),基础分增加%d(%d->%d)分。", $beforeLevelName, $nowLevelName, $gainPoints, $beforeLevelPoints, $nowLevelPoints);
  199. }
  200. /* 查询最后一条积分日志 */
  201. $where = [];
  202. //$where[] = ["name", "=", $name];
  203. $where[] = ["card_type", "=", $cardType];
  204. $where[] = ["card_number", "=", $cardNumber];
  205. $last_log = Db::table("new_integral_log")->where($where)->order("createTime desc")->find();
  206. $lastPoints = $last_log["nowPoints"] ?: 0;
  207. $log["id"] = getStringId();
  208. $log["type"] = $type;
  209. $log["mainType"] = "talent";
  210. $log["mainId"] = $mainId;
  211. $log["enterprise_id"] = $talentInfo["enterprise_id"];
  212. $log["name"] = $name;
  213. $log["card_type"] = $cardType;
  214. $log["card_number"] = $cardNumber;
  215. $log["talentLevel"] = $level;
  216. $log["lastPoints"] = $lastPoints;
  217. $log["gainPoints"] = $gainPoints;
  218. $log["nowPoints"] = $lastPoints + $gainPoints;
  219. $log["description"] = $desc;
  220. $log["createTime"] = date("Y-m-d H:i:s");
  221. Db::table("new_integral_log")->insert($log);
  222. return true;
  223. }
  224. } catch (\Exception $e) {
  225. Log::write($e->getMessage(), "error");
  226. }
  227. break;
  228. case 5:
  229. //人才层次变更变更积分
  230. try {
  231. $mainId = $data["id"];
  232. $where = [];
  233. $where[] = ["id", "=", $mainId];
  234. $where[] = ["checkState", "=", \app\common\state\MainState::PASS];
  235. $where[] = ["isPublic", "=", 6];
  236. $talentTypeChange = \app\enterprise\model\TalentTypeChange::where($where)->find();
  237. if (strlen($talentTypeChange["talentId"]) == 19) {
  238. $where = [];
  239. $where[] = ["card_number", "=", $talentTypeChange["idCard"]];
  240. $where[] = ["checkState", "=", TalentState::CERTIFICATED];
  241. $talentInfo = TalentModel::where($where)->find();
  242. } else {
  243. $where = [];
  244. $where[] = ["id", "=", $talentTypeChange["talentId"]];
  245. $where[] = ["checkState", "=", TalentState::CERTIFICATED];
  246. $talentInfo = TalentModel::where($where)->find();
  247. }
  248. $where = [];
  249. $where[] = ["mainId", "=", $mainId];
  250. $where[] = ["mainType", "=", "talentTypeChange"];
  251. $integralLog = Db::table("new_integral_log")->where($where)->find();
  252. if ($talentTypeChange && $talentInfo && !$integralLog) {
  253. $newLevel = $talentTypeChange["newTalentArrange"];
  254. $oldLevel = $talentTypeChange["oldTalentArrange"];
  255. $name = $talentInfo["name"]; //姓名
  256. $cardType = $talentInfo["card_type"]; //身份证类型
  257. $cardNumber = $talentInfo["card_number"]; //身份证
  258. $type = $talentTypeChange["type"]; //企业类型
  259. $lastPoints = 0; //上次积分
  260. //$gainPoints = CommonConst::getLayerPointsByLayer($level); //增加积分
  261. //$desc = sprintf("经人才申报审核通过,认定为集成电路(%s)优秀人才,基础分变更为%d分。", CommonConst::getLayerNameByLayer($level), $gainPoints); //详情
  262. /* 查询是否升级 */
  263. if ($newLevel < $oldLevel) {
  264. $beforeLevelName = CommonConst::getLayerNameByLayer($oldLevel); //之前层次
  265. $beforeLevelPoints = CommonConst::getLayerPointsByLayer($oldLevel); //之前基础分
  266. $nowLevelName = CommonConst::getLayerNameByLayer($newLevel); //现在层次
  267. $nowLevelPoints = CommonConst::getLayerPointsByLayer($newLevel); //现在基础分
  268. $gainPoints = $nowLevelPoints - $beforeLevelPoints;
  269. $desc = sprintf("人才层次变更(%s->%s),基础分增加%d(%d->%d)分。", $beforeLevelName, $nowLevelName, $gainPoints, $beforeLevelPoints, $nowLevelPoints);
  270. /* 查询最后一条积分日志 */
  271. $where = [];
  272. //$where[] = ["name", "=", $name];
  273. $where[] = ["card_type", "=", $cardType];
  274. $where[] = ["card_number", "=", $cardNumber];
  275. $last_log = Db::table("new_integral_log")->where($where)->order("createTime desc")->find();
  276. $lastPoints = $last_log["nowPoints"] ?: 0;
  277. $log["id"] = getStringId();
  278. $log["type"] = $type;
  279. $log["mainType"] = "talentTypeChange";
  280. $log["mainId"] = $mainId;
  281. $log["enterprise_id"] = $talentInfo["enterprise_id"];
  282. $log["name"] = $name;
  283. $log["card_type"] = $cardType;
  284. $log["card_number"] = $cardNumber;
  285. $log["talentLevel"] = $newLevel;
  286. $log["lastPoints"] = $lastPoints;
  287. $log["gainPoints"] = $gainPoints;
  288. $log["nowPoints"] = $lastPoints + $gainPoints;
  289. $log["description"] = $desc;
  290. $log["createTime"] = date("Y-m-d H:i:s");
  291. Db::table("new_integral_log")->insert($log);
  292. return true;
  293. }
  294. }
  295. } catch (\Exception $e) {
  296. Log::write($e->getMessage(), "error");
  297. }
  298. break;
  299. case 6://卫健批量审核
  300. $condition = null;
  301. $upddata["pass_dept_check"] = 0;
  302. $talent_info = \app\common\api\VerifyApi::getTalentInfoById($data["id"]);
  303. if ($talent_info && $talent_info["checkState"] == TalentState::SCND_SUBMIT) {
  304. if ($data["checkState"] == 3) {
  305. //审核成功,并取消设置越过部门并审
  306. $log_checkState = $checkState = TalentState::FST_VERIFY_PASS; //初审成功
  307. } else {
  308. //审核驳回并记录需要修改的字段和上传文件
  309. if (in_array("talent_condition", $data["fields"])) {
  310. $condition = TalentConditionApi::getOne($talent_info["talent_condition"]);
  311. $data["files"] = array_merge($data["files"], (array) explode(",", $condition["bindFileTypes"]));
  312. }
  313. if ($talent_info["enterpriseType"] == CommonConst::ENTERPRISE_WJ) {
  314. if ($data["checkState"] == 6) {
  315. //驳回到分院
  316. if ($talent_info["isGeneral"] == 1) {
  317. //总院不能驳回到分院,自动变更为退回总院
  318. $checkState = TalentState::SCND_SAVE;
  319. } else {
  320. $checkState = TalentState::FST_SAVE;
  321. }
  322. } else {
  323. if ($talent_info["isGeneral"] == 1) {
  324. $checkState = TalentState::SCND_SAVE; //退回材料编辑状态
  325. } else {
  326. if (\app\common\api\Nhc::hasGeneralHospital($talent_info["medicalCommunityId"])) {
  327. $checkState = TalentState::FST_SUBMIT;
  328. } else {
  329. $checkState = TalentState::FST_SAVE;
  330. }
  331. }
  332. }
  333. } else {
  334. $checkState = TalentState::SCND_SAVE; //退回材料编辑状态
  335. }
  336. $log_checkState = TalentState::FST_VERIFY_REJECT; //日志记录拒绝状态
  337. }
  338. $nowProcess = 3;
  339. if ($checkState == TalentState::FST_VERIFY_PASS) {
  340. $upddata["highProcess"] = $nowProcess > $talent_info["highProcess"] ? $nowProcess : $talent_info["highProcess"];
  341. }
  342. $userIds = [];
  343. if ($log_checkState == TalentState::FST_VERIFY_PASS) {
  344. $upddata["first_dept_check_time"] = date("Y-m-d H:i:s");
  345. $condition = $condition ? $condition : TalentConditionApi::getOne($talent_info["talent_condition"]);
  346. $companyIds = array_filter(explode(",", $condition["companyIds"])); //该条件下需要审核的所有单位
  347. if ($talent_info["re_check_companys"]) {
  348. $unpass_companyIds = array_filter(explode(",", $talent_info["re_check_companys"]));
  349. } else {
  350. //这边去除已经审核通过的单位,主要通过日志是否存在记录。
  351. $pass_companyIds = TalentLogApi::getPassDepts($data["id"]); //已经通过的单位
  352. $unpass_companyIds = array_diff($companyIds, (array) $pass_companyIds); //排除已经通过的单位
  353. if (!$unpass_companyIds) {
  354. $data["pass_dept_check"] = 1; //部门已经全部审核过了,跳过部门审核
  355. }
  356. }
  357. if ($unpass_companyIds) {
  358. sort($unpass_companyIds);
  359. $delay = 9 * 24 * 3600; //9天的秒数
  360. queue("app\job\Talent", ["type" => 1, "id" => $data["id"]], $delay); //加入部门审核超期处理队列,延迟7天执行
  361. TalentLogApi::writeDeptLogs($data["id"], $unpass_companyIds, TalentState::FST_VERIFY_PASS);
  362. /*
  363. //初审通过发送短信通知并审部门
  364. $codes = ["talentInfo_depCheck"];
  365. $menuIds = MenuApi::getMenuIdsByCodes($codes);
  366. $where = [];
  367. $where[] = ["menuid", "in", $menuIds];
  368. $roleIds = SysRelation::where($where)->group("roleid")->having("count(*)=" . count($codes))->column("roleid");
  369. $where = [];
  370. $where[] = ["status", "=", 1];
  371. //$where[] = ["type", "=", $this->user["type"]];
  372. $where[] = ["companyId", "in", $unpass_companyIds];
  373. $where[] = ["roleid", "<>", 1];
  374. $regstr = ",(" . implode("|", $roleIds) . "),";
  375. $whereRaw = "concat(',',roleid,',') REGEXP '$regstr'";
  376. $userIds = User::where($where)->whereRaw($whereRaw)->column("id");
  377. */
  378. }
  379. }
  380. $log = TalentLogApi::getLastLog($data["id"], 1);
  381. if (!$log && !$talent_info["oldId"])
  382. return json(["msg" => "日志数据异常,保存失败"]);
  383. if ($log["active"] === 0) {
  384. TalentLogApi::rewrite($log["id"], [$log_checkState, $checkState], $data["checkMsg"], 1, $data["user"]);
  385. } else {
  386. TalentLogApi::write(1, $data["id"], [$log_checkState, $checkState], $data["checkMsg"], 1, null, null, null, $data["user"]);
  387. }
  388. $upddata["id"] = $talent_info["id"];
  389. $upddata["modify_files"] = $data["files"] ? implode(",", $data["files"]) : "";
  390. $upddata["modify_fields"] = $data["fields"] ? implode(",", $data["fields"]) : "";
  391. $upddata["checkState"] = $checkState;
  392. TalentModel::update($upddata);
  393. return true;
  394. }
  395. break;
  396. }
  397. return false;
  398. }
  399. }