Talent.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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")->find();
  49. if ($talent_info) {
  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. }
  229. return false;
  230. }
  231. }