Talent.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. $re_check_companys = $talent_info["re_check_companys"] ? array_filter(explode(",", $talent_info["re_check_companys"])) : [];
  78. $companyIds = \app\common\api\VerifyApi::getNewReCheckCompanyIds($re_check_companys, $companyIds, $pass_companyIds);
  79. $unpass_companyIds = array_diff($companyIds, (array) $pass_companyIds); //排除已经通过的单位
  80. if (!$unpass_companyIds) {
  81. //没有未审部门
  82. return true;
  83. }
  84. //开始驳回操作
  85. $fst_dept_check_time = $talent_info["first_dept_check_time"];
  86. $log_checkState = TalentState::FST_VERIFY_PASS; //当前状态不变
  87. $checkState = TalentState::SCND_SUBMIT; //退回待初审
  88. foreach ($unpass_companyIds as $companyId) {
  89. $fileTypes = $companyAndTypes[$companyId];
  90. $modify_files = array_unique((array_merge((array) $modify_files, (array) $fileTypes)));
  91. $dept_log = TalentLogApi::getLogByCompanyId($talent_info["id"], $companyId, $fst_dept_check_time);
  92. if ($dept_log) {
  93. TalentLogApi::rewrite($dept_log["id"], [$log_checkState, $checkState], "审核超时,系统自动驳回", 1);
  94. } else {
  95. TalentLogApi::write(ProjectState::TALENT, $talent_info["id"], [$log_checkState, $checkState, 3], "审核超时,系统自动驳回", 1, null, null, $companyId); //补一条记录
  96. sleep(1);
  97. }
  98. }
  99. $log_checkState = TalentState::DEPT_VERIFY_REJECT;
  100. $save["id"] = $talent_info["id"];
  101. $save["modify_files"] = implode(",", $modify_files);
  102. $save["checkState"] = $checkState;
  103. $save["highProcess"] = $talent_info["highProcess"] > 3 ? $talent_info["highProcess"] : 3;
  104. $save["first_dept_check_time"] = null;
  105. $save["re_check_companys"] = null;
  106. TalentModel::update($save);
  107. TalentLogApi::write(1, $talent_info["id"], [$log_checkState, $checkState], "审核超时,系统自动驳回,部门审核结束", 1);
  108. }
  109. return true;
  110. }
  111. break;
  112. case 2:
  113. //超过批次提交时间审核失败
  114. $talentInfo = $data["talentInfo"];
  115. $projectType = ProjectState::TALENT; //项目类型
  116. $mainId = $talentInfo["id"]; //申报id
  117. $checkState = TalentState::FST_VERIFY_FAIL; //系统审核失败状态,初审不通过
  118. if ($talentInfo["checkState"] == TalentState::SCND_SAVE) {
  119. $where = [];
  120. $where[] = ["active", "=", 1];
  121. $where[] = ["type", "=", $projectType];
  122. $where[] = ["source", "=", $talentInfo["enterpriseType"]];
  123. $where[] = ["batch", "=", $talentInfo["apply_year"]];
  124. $whereRaw = sprintf("submitEndTime is not null and submitEndTime<>'' and submitEndTime < '%s'", date("Y-m-d H:i:s"));
  125. $batch = \app\common\model\Batch::where($where)->whereRaw($whereRaw)->find();
  126. if ($batch) {
  127. $save["id"] = $mainId;
  128. $save["checkState"] = $checkState;
  129. TalentModel::update($save);
  130. TalentLogApi::write($projectType, $mainId, $checkState, "超过该批次提交截止时间未提交审核,系统自动结束该申报", 1);
  131. }
  132. return true;
  133. }
  134. break;
  135. case 3:
  136. //撤销超时审核失败
  137. $talentInfo = $data["talentInfo"];
  138. $projectType = ProjectState::TALENT; //项目类型
  139. $mainId = $talentInfo["id"]; //申报id
  140. $checkState = TalentState::SCND_SAVE; //系统审核失败状态,初审不通过
  141. $last_log = TalentLogApi::getLastLog($mainId, $projectType, 0, ["active", "=", 1]);
  142. if ($talentInfo["checkState"] == TalentState::FST_VERIFY_FAIL && $last_log["state"] == TalentState::FST_VERIFY_FAIL && $last_log["createUser"] == "系统") {
  143. $where = [];
  144. $where[] = ["active", "=", 1];
  145. $where[] = ["type", "=", $projectType];
  146. $where[] = ["source", "=", $talentInfo["enterpriseType"]];
  147. $where[] = ["batch", "=", $talentInfo["apply_year"]];
  148. $whereRaw = sprintf("submitEndTime is null or submitEndTime<>'' or submitEndTime > '%s'", date("Y-m-d H:i:s"));
  149. $batch = \app\common\model\Batch::where($where)->whereRaw($whereRaw)->find();
  150. $extra_where[] = ["active", "=", 1];
  151. $extra_where[] = ["createUser", "<>", "系统"];
  152. $last_log = TalentLogApi::getLastLogEx($mainId, $projectType, 0, $extra_where);
  153. if ($batch && $last_log) {
  154. $save["id"] = $mainId;
  155. $save["checkState"] = $checkState;
  156. TalentModel::update($save);
  157. TalentLogApi::write($projectType, $mainId, [$last_log["state"], $last_log["new_state"]], "该批次经人社局操作,已延长申报提交截止时间,现由人才办交办,对被自动审核失败的申报进行状态处理,恢复至初审驳回。该申报已处理。", 1);
  158. }
  159. return true;
  160. }
  161. break;
  162. case 4:
  163. //发放人才码后增加积分记录
  164. $mainId = $data["id"];
  165. $where = [];
  166. $where[] = ["ti.id", "=", $mainId];
  167. $where[] = ["ti.checkState", "=", TalentState::CERTIFICATED];
  168. $talentInfo = TalentModel::alias("ti")->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")->field("ti.*,e.type as enterpriseType")->where($where)->find();
  169. $where = [];
  170. $where[] = ["mainId", "=", $mainId];
  171. $where[] = ["mainType", "=", "talent"];
  172. $integralLog = Db::table("new_integral_log")->where($where)->find();
  173. if ($talentInfo && !$integralLog) {
  174. $level = $talentInfo["talent_arrange"];
  175. $name = $talentInfo["name"]; //姓名
  176. $cardType = $talentInfo["card_type"]; //身份证类型
  177. $cardNumber = $talentInfo["card_number"]; //身份证
  178. $type = $talentInfo["enterpriseType"]; //企业类型
  179. $lastPoints = 0; //上次积分
  180. $levelAndPoints = [
  181. 1 => 6000,
  182. 2 => 4000,
  183. 3 => 2000,
  184. 4 => 1000,
  185. 5 => 500,
  186. 6 => 200,
  187. 7 => 100
  188. ];
  189. $levelAndNames = [
  190. 1 => "第一层次",
  191. 2 => "第二层次",
  192. 3 => "第三层次",
  193. 4 => "第四层次",
  194. 5 => "第五层次",
  195. 6 => "第六层次",
  196. 7 => "第七层次",
  197. ];
  198. $gainPoints = $levelAndPoints[$level]; //增加积分
  199. $desc = sprintf("首次通过人才申报,增加基础积分%d。", $levelAndPoints[$level]); //详情
  200. /* 查询是否升级 */
  201. $where = [];
  202. $where[] = ["id", "<>", $mainId];
  203. $where[] = ["name", "=", $name];
  204. $where[] = ["card_type", "=", $cardType];
  205. $where[] = ["card_number", "=", $cardNumber];
  206. $where[] = ["checkState", "=", TalentState::CERTIFICATED];
  207. $talentBeforeInfo = TalentModel::where($where)->order("createTime desc")->find();
  208. if ($talentBeforeInfo && $level < $talentBeforeInfo["talent_arrange"]) {
  209. $beforeLevelName = $levelAndNames[$talentBeforeInfo["talent_arrange"]]; //之前层次
  210. $beforeLevelPoints = $levelAndPoints[$talentBeforeInfo["talent_arrange"]]; //之前基础分
  211. $nowLevelName = $levelAndNames[$level]; //现在层次
  212. $nowLevelPoints = $levelAndPoints[$level]; //现在基础分
  213. $gainPoints -= $beforeLevelPoints;
  214. $desc = sprintf("人才层次晋升(%s->%s),基础积分增加%d(%d->%d)。", $beforeLevelName, $nowLevelName, $gainPoints, $beforeLevelPoints, $nowLevelPoints);
  215. }
  216. /* 查询最后一条积分日志 */
  217. $where = [];
  218. $where[] = ["name", "=", $name];
  219. $where[] = ["card_type", "=", $cardType];
  220. $where[] = ["card_number", "=", $cardNumber];
  221. $last_log = Db::table("new_integral_log")->where($where)->order("createTime desc")->find();
  222. $lastPoints = $last_log["nowPoints"] ?: 0;
  223. $log["id"] = getStringId();
  224. $log["type"] = $type;
  225. $log["mainType"] = "talent";
  226. $log["mainId"] = $mainId;
  227. $log["name"] = $name;
  228. $log["card_type"] = $cardType;
  229. $log["card_number"] = $cardNumber;
  230. $log["talentLevel"] = $level;
  231. $log["lastPoints"] = $lastPoints;
  232. $log["gainPoints"] = $gainPoints;
  233. $log["nowPoints"] = $lastPoints + $gainPoints;
  234. $log["description"] = $desc;
  235. $log["createTime"] = date("Y-m-d H:i:s");
  236. Db::table("new_integral_log")->insert($log);
  237. return true;
  238. }
  239. break;
  240. }
  241. return false;
  242. }
  243. }