Talent.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. /**
  14. * Description of Talent
  15. *
  16. * @author sgq
  17. */
  18. class Talent {
  19. public function fire(Job $job, $data) {
  20. if ($this->deal($data)) {
  21. $job->delete();
  22. return true;
  23. }
  24. if ($job->attempts() >= 3) {
  25. $job->delete();
  26. return false;
  27. }
  28. $job->release(10); //10秒后重试
  29. }
  30. /**
  31. * 处理业务逻辑
  32. * @param type $data
  33. * @return bool
  34. */
  35. public function deal($data): bool {
  36. switch ($data["type"]) {
  37. case 1:
  38. //部门超时驳回
  39. $mainId = $data["id"];
  40. $where[] = ["ti.id", "=", $mainId];
  41. $where[] = ["ti.checkState", "=", TalentState::FST_VERIFY_PASS];
  42. $where[] = ["ti.pass_dept_check", "=", 0];
  43. $talent_info = TalentModel::alias("ti")
  44. ->leftJoin("new_talent_condition tc", "tc.id=ti.talent_condition")
  45. ->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")
  46. ->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")
  47. ->where($where)->field("ti.*,tc.companyIds,tc.companyWithFileType")->find();
  48. if ($talent_info) {
  49. $weekDay = date("w"); //0周日,6周六
  50. if ($weekDay == 6) {
  51. $delay = 2 * 24 * 3600;
  52. queue("app\job\Talent", ["type" => 1, "id" => $mainId], $delay);
  53. return true;
  54. }
  55. if (!$weekDay || $weekDay == 0) {
  56. $delay = 1 * 24 * 3600;
  57. queue("app\job\Talent", ["type" => 1, "id" => $mainId], $delay);
  58. return true;
  59. }
  60. $modify_files = array_filter(explode(",", $talent_info["modify_files"]));
  61. $companyAndTypes = [];
  62. $companyWithFileType = array_filter(explode(";", $talent_info["companyWithFileType"]));
  63. foreach ($companyWithFileType as $c) {
  64. list($companyId, $fileTypesStr) = array_filter(explode(":", $c));
  65. $companyAndTypes[$companyId] = array_filter(explode(",", $fileTypesStr));
  66. }
  67. $companyIds = array_filter(explode(",", $talent_info["companyIds"]));
  68. if ($companyIds) {
  69. /* if ($talent_info["re_check_companys"]) {
  70. $unpass_companyIds = array_filter(explode(",", $talent_info["re_check_companys"]));
  71. } else {
  72. //这边去除已经审核通过的单位,主要通过日志是否存在记录。
  73. $pass_companyIds = TalentLogApi::getPassDepts($talent_info["id"]); //已经通过的单位
  74. $unpass_companyIds = array_diff($companyIds, (array) $pass_companyIds); //排除已经通过的单位
  75. } */
  76. $pass_companyIds = TalentLogApi::getPassDepts($talent_info["id"]); //已经通过的单位
  77. $companyIds = \app\common\api\VerifyApi::getNewReCheckCompanyIds($talent_info["re_check_companys"], $companyIds, $pass_companyIds);
  78. $unpass_companyIds = array_diff($companyIds, (array) $pass_companyIds); //排除已经通过的单位
  79. if (!$unpass_companyIds) {
  80. //没有未审部门
  81. return true;
  82. }
  83. //开始驳回操作
  84. $fst_dept_check_time = $talent_info["first_dept_check_time"];
  85. $log_checkState = TalentState::FST_VERIFY_PASS; //当前状态不变
  86. $checkState = TalentState::SCND_SUBMIT; //退回待初审
  87. foreach ($unpass_companyIds as $companyId) {
  88. $fileTypes = $companyAndTypes[$companyId];
  89. $modify_files = array_unique((array_merge((array) $modify_files, (array) $fileTypes)));
  90. $dept_log = TalentLogApi::getLogByCompanyId($talent_info["id"], $companyId, $fst_dept_check_time);
  91. if ($dept_log) {
  92. TalentLogApi::rewrite($dept_log["id"], [$log_checkState, $checkState], "审核超时,系统自动驳回", 1);
  93. } else {
  94. TalentLogApi::write(ProjectState::TALENT, $talent_info["id"], [$log_checkState, $checkState, 3], "审核超时,系统自动驳回", 1, null, null, $companyId); //补一条记录
  95. sleep(1);
  96. }
  97. }
  98. $log_checkState = TalentState::DEPT_VERIFY_REJECT;
  99. $save["id"] = $talent_info["id"];
  100. $save["modify_files"] = implode(",", $modify_files);
  101. $save["checkState"] = $checkState;
  102. $save["highProcess"] = $talent_info["highProcess"] > 3 ? $talent_info["highProcess"] : 3;
  103. $save["first_dept_check_time"] = null;
  104. $save["re_check_companys"] = null;
  105. TalentModel::update($save);
  106. TalentLogApi::write(1, $talent_info["id"], [$log_checkState, $checkState], "审核超时,系统自动驳回,部门审核结束", 1);
  107. }
  108. return true;
  109. }
  110. break;
  111. case 2:
  112. //超过批次提交时间审核失败
  113. $talentInfo = $data["talentInfo"];
  114. $projectType = ProjectState::TALENT; //项目类型
  115. $mainId = $talentInfo["id"]; //申报id
  116. $checkState = TalentState::FST_VERIFY_FAIL; //系统审核失败状态,初审不通过
  117. if ($talentInfo["checkState"] == TalentState::SCND_SAVE) {
  118. $where = [];
  119. $where[] = ["active", "=", 1];
  120. $where[] = ["type", "=", $projectType];
  121. $where[] = ["source", "=", $talentInfo["enterpriseType"]];
  122. $where[] = ["batch", "=", $talentInfo["apply_year"]];
  123. $whereRaw = sprintf("submitEndTime is not null and submitEndTime<>'' and submitEndTime < '%s'", date("Y-m-d H:i:s"));
  124. $batch = \app\common\model\Batch::where($where)->whereRaw($whereRaw)->find();
  125. if ($batch) {
  126. $save["id"] = $mainId;
  127. $save["checkState"] = $checkState;
  128. TalentModel::update($save);
  129. TalentLogApi::write($projectType, $mainId, $checkState, "超过该批次提交截止时间未提交审核,系统自动结束该申报", 1);
  130. }
  131. return true;
  132. }
  133. break;
  134. case 3:
  135. //撤销超时审核失败
  136. $talentInfo = $data["talentInfo"];
  137. $projectType = ProjectState::TALENT; //项目类型
  138. $mainId = $talentInfo["id"]; //申报id
  139. $checkState = TalentState::SCND_SAVE; //系统审核失败状态,初审不通过
  140. $last_log = TalentLogApi::getLastLog($mainId, $projectType, 0, ["active", "=", 1]);
  141. if ($talentInfo["checkState"] == TalentState::FST_VERIFY_FAIL && $last_log["state"] == TalentState::FST_VERIFY_FAIL && $last_log["createUser"] == "系统") {
  142. $where = [];
  143. $where[] = ["active", "=", 1];
  144. $where[] = ["type", "=", $projectType];
  145. $where[] = ["source", "=", $talentInfo["enterpriseType"]];
  146. $where[] = ["batch", "=", $talentInfo["apply_year"]];
  147. $whereRaw = sprintf("submitEndTime is null or submitEndTime<>'' or submitEndTime > '%s'", date("Y-m-d H:i:s"));
  148. $batch = \app\common\model\Batch::where($where)->whereRaw($whereRaw)->find();
  149. $extra_where[] = ["active", "=", 1];
  150. $extra_where[] = ["createUser", "<>", "系统"];
  151. $last_log = TalentLogApi::getLastLogEx($mainId, $projectType, 0, $extra_where);
  152. if ($batch && $last_log) {
  153. $save["id"] = $mainId;
  154. $save["checkState"] = $checkState;
  155. TalentModel::update($save);
  156. TalentLogApi::write($projectType, $mainId, [$last_log["state"], $last_log["new_state"]], "该批次已经延长申报提交截止时间同时选择恢复被自动审核失败的申报,该申报已恢复至保存未提交状态", 1);
  157. }
  158. return true;
  159. }
  160. break;
  161. }
  162. return false;
  163. }
  164. }