TalentApi.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. namespace app\enterprise\api;
  3. use app\enterprise\model\Talent;
  4. use app\common\api\DictApi;
  5. use app\common\api\TalentConditionApi;
  6. use app\common\api\TalentLogApi;
  7. use app\common\api\TalentState;
  8. use app\enterprise\model\TalentTypeChange;
  9. use think\facade\Db;
  10. /**
  11. * Description of TalentApi
  12. *
  13. * @author sgq
  14. */
  15. class TalentApi {
  16. /**
  17. * 判断是否可以编辑
  18. * @param type $id
  19. * @return boolean
  20. */
  21. public static function checkIsEditable($id) {
  22. $info = Talent::findOrEmpty($id)->toArray();
  23. if ($info["delete"] == 1 || !in_array($info["checkState"], [0, TalentState::FST_SAVE, TalentState::BASE_REVERIFY_PASS, TalentState::SCND_SAVE]))
  24. return false;
  25. return true;
  26. }
  27. static public function chkIsOwner($id, $uid) {
  28. $info = self::getOne($id);
  29. if ($info["enterprise_id"] != $uid)
  30. return null;
  31. return $info;
  32. }
  33. public static function getOne($id) {
  34. $one = Talent::findOrEmpty($id);
  35. return $one;
  36. }
  37. public static function getList($request, $step = 0) {
  38. $order = trim($request->param("order")) ?: "desc";
  39. $offset = trim($request->param("offset")) ?: 0;
  40. $limit = trim($request->param("limit")) ?: 10;
  41. $name = trim($request->param("name"));
  42. $idCard = trim($request->param("card_number"));
  43. $sex = trim($request->param("sex"));
  44. $nation = trim($request->param("nation"));
  45. $nationality = trim($request->param("nationality"));
  46. $talentArrange = trim($request->param("talent_arrange"));
  47. $checkState = trim($request->param("checkState"));
  48. $type = session("user")["type"];
  49. $where = [];
  50. $where[] = ["delete", "=", 0];
  51. if (session("user")["usertype"] == 2) {
  52. $where[] = ["enterprise_id", "=", session("user")["uid"]];
  53. }
  54. //$where[] = ["isImport", "=", $request->param("import") ?: 0];
  55. if ($step) {
  56. switch ($step) {
  57. case 1:
  58. $where[] = ["checkState", "in", [TalentState::FST_SAVE, TalentState::BASE_VERIFY_PASS, TalentState::BASE_REVERIFY_REJECT, TalentState::BASE_REVERIFY_FAIL, TalentState::BASE_REJECT, TalentState::FST_SUBMIT, TalentState::BASE_VERIFY_FAIL]];
  59. switch ($checkState) {
  60. case -1:
  61. $where[] = ["checkState", "in", [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL]];
  62. break;
  63. case 1:
  64. $where[] = ["checkState", "=", TalentState::FST_SAVE];
  65. break;
  66. case 2:
  67. $where[] = ["checkState", "in", [TalentState::BASE_REJECT, TalentState::BASE_REVERIFY_REJECT]];
  68. break;
  69. case 3:
  70. $where[] = ["checkState", "in", [TalentState::FST_SUBMIT, TalentState::BASE_VERIFY_PASS]];
  71. break;
  72. }
  73. break;
  74. case 2:
  75. $where[] = ["checkState", "not in", [TalentState::BASE_REVERIFY_REJECT, TalentState::BASE_REVERIFY_FAIL, TalentState::BASE_VERIFY_FAIL]];
  76. switch ($checkState) {
  77. case -1:
  78. $where[] = ["checkState", "in", [TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL, TalentState::ZX_FAIL, TalentState::ANNOUNCED_REVERIFY_FAIL, TalentState::PUBLISH_FAIL]];
  79. break;
  80. case 1:
  81. $where[] = ["checkState", "in", [TalentState::SCND_SAVE, TalentState::FST_SAVE]];
  82. break;
  83. case 2:
  84. $where[] = ["checkState", "in", [TalentState::BASE_REJECT, TalentState::FST_VERIFY_REJECT, TalentState::DEPT_VERIFY_REJECT, TalentState::REVERIFY_REJECT]];
  85. break;
  86. case 3:
  87. $where[] = ["checkState", "in", [TalentState::FST_SUBMIT, TalentState::SCND_SUBMIT, TalentState::BASE_VERIFY_PASS, TalentState::FST_VERIFY_PASS, TalentState::DEPT_VERIFY_PASS, TalentState::REVERIFY_PASS, TalentState::ZX_PASS,
  88. TalentState::ANNOUNCED_REVERIFY_PASS, TalentState::PUBLISH_PASS]];
  89. break;
  90. case 4:
  91. $where[] = ["checkState", "=", TalentState::CERTIFICATED];
  92. break;
  93. }
  94. break;
  95. case 3:
  96. $where[] = ["checkState", "=", TalentState::CERTIFICATED];
  97. break;
  98. }
  99. if ($name) {
  100. $where[] = ["name", "like", "%" . $name . "%"];
  101. }
  102. if ($idCard) {
  103. $where[] = ["card_number", "like", "%" . $idCard . "%"];
  104. }
  105. if ($sex) {
  106. $where[] = ["sex", "=", $sex];
  107. }
  108. if ($nation) {
  109. $where[] = ["nation", "=", $nation];
  110. }
  111. if ($nationality) {
  112. $where[] = ["nationality", "=", $nationality];
  113. }
  114. if ($talentArrange) {
  115. $where[] = ["talent_arrange", "=", $talentArrange];
  116. }
  117. $count = Talent::where($where)->count();
  118. $list = Talent::where($where)->limit($offset, $limit)->order("createTime " . $order)->select()->toArray();
  119. $talentTagList = DictApi::selectByParentCode("enterprise_tag"); //单位标签
  120. $talentArangeList = DictApi::selectByParentCode("talent_arrange"); //人才层次
  121. $industries = DictApi::selectByParentCode("industry_field"); //产业
  122. $enterprise = \app\common\model\Enterprise::find(session("user")["uid"]);
  123. foreach ($list as $key => $item) {
  124. $condition = TalentConditionApi::getOne($item["talent_condition"]);
  125. $list[$key]["talentArrangeName"] = isset($talentArangeList[$item["talent_arrange"]]) ? $talentArangeList[$item["talent_arrange"]] : "";
  126. $list[$key]["identifyConditionText"] = $condition["name"];
  127. if (!$item["isMatchZhiren"]) {
  128. $list[$key]["companyIds"] = $condition["companyIds"];
  129. }
  130. $list[$key]["type"] = $enterprise["type"];
  131. $list[$key]["enterpriseName"] = $enterprise["name"];
  132. $list[$key]["industryName"] = $industries[$enterprise["industryFieldNew"]];
  133. $list[$key]["enterpriseTagName"] = $talentTagList[$enterprise["enterpriseTag"]];
  134. $last_log = TalentLogApi::getLastLog($item["id"], 1, 0, ["active", "=", 1]);
  135. $list[$key]["real_state"] = $last_log["state"];
  136. $list[$key]["last_state"] = $last_log["last_state"];
  137. }
  138. return ["total" => $count, "rows" => $list];
  139. }
  140. }
  141. public static function getTypeChangeList($request) {
  142. $order = trim($request->param("order")) ?: "desc";
  143. $offset = trim($request->param("offset")) ?: 0;
  144. $limit = trim($request->param("limit")) ?: 10;
  145. $talentName = trim($request->param("talentName"));
  146. $oldTalentArrange = trim($request->param("oldTalentArrange"));
  147. $newTalentArrange = trim($request->param("newTalentArrange"));
  148. $checkState = trim($request->param("checkState"));
  149. $oldIdentifyCondition = trim($request->param("oldIdentifyCondition"));
  150. $newIdentifyCondition = trim($request->param("newIdentifyCondition"));
  151. $where = [];
  152. $where[] = ["enterpriseId", "=", session("user")["uid"]];
  153. $where[] = ["delete", "=", 0];
  154. $where[] = ["createTime", ">=", "2022-10-01 00:00:00"];
  155. //$whereRaw = "length(talentId) <> 19";
  156. if ($talentName) {
  157. $where[] = ["talentName", "like", "%" . $talentName . "%"];
  158. }
  159. if ($oldTalentArrange) {
  160. $where[] = ["oldTalentArrange", "=", $oldTalentArrange];
  161. }
  162. if ($newTalentArrange) {
  163. $where[] = ["newTalentArrange", "=", $newTalentArrange];
  164. }
  165. if ($checkState) {
  166. $where[] = ["checkState", "=", $checkState];
  167. }
  168. if ($oldIdentifyCondition) {
  169. $where[] = ["oldIdentifyCondition", "=", $oldIdentifyCondition];
  170. }
  171. if ($newIdentifyCondition) {
  172. $where[] = ["newIdentifyCondition", "=", $newIdentifyCondition];
  173. }
  174. $count = TalentTypeChange::where($where)->count();
  175. $list = TalentTypeChange::where($where)->limit($offset, $limit)->order("createTime " . $order)->select()->toArray();
  176. $talentArangeList = DictApi::selectByParentCode("talent_arrange"); //人才层次
  177. foreach ($list as $k => $v) {
  178. if (strlen($v["oldIdentifyCondition"]) == 19) {
  179. $condition = Db::table("un_identify_condition")->find($v["oldIdentifyCondition"]);
  180. $list[$k]["oldIdentifyCondition"] = $condition["name"];
  181. } else if ($v["oldIdentifyCondition"]) {
  182. $condition = TalentConditionApi::getOne($v["oldIdentifyCondition"]);
  183. $list[$k]["oldIdentifyCondition"] = $condition["name"];
  184. }
  185. if (strlen($v["newIdentifyCondition"]) == 19) {
  186. $condition = Db::table("un_identify_condition")->find($v["newIdentifyCondition"]);
  187. $list[$k]["newIdentifyCondition"] = $condition["name"];
  188. } else if ($v["newIdentifyCondition"]) {
  189. $condition = TalentConditionApi::getOne($v["newIdentifyCondition"]);
  190. $list[$k]["newIdentifyCondition"] = $condition["name"];
  191. }
  192. $list[$k]["oldTalentArrangeName"] = array_key_exists($v["oldTalentArrange"], $talentArangeList) ? $talentArangeList[$v["oldTalentArrange"]] : "";
  193. $list[$k]["newTalentArrangeName"] = array_key_exists($v["newTalentArrange"], $talentArangeList) ? $talentArangeList[$v["newTalentArrange"]] : "";
  194. }
  195. return ["total" => $count, "rows" => $list];
  196. }
  197. public static function getHospitalExamineList($request) {
  198. $user = session("user");
  199. if ($user["isGeneral"] == 1) {
  200. $order = trim($request->param("order")) ?: "desc";
  201. $offset = trim($request->param("offset")) ?: 0;
  202. $limit = trim($request->param("limit")) ?: 10;
  203. $name = trim($request->param("name"));
  204. $idCard = trim($request->param("card_number"));
  205. $sex = trim($request->param("sex"));
  206. $nation = trim($request->param("nation"));
  207. $talentArrange = trim($request->param("talent_arrange"));
  208. $checkState = trim($request->param("checkState"));
  209. $where = [];
  210. $where[] = ["ti.delete", "=", 0];
  211. $where[] = ["e.type", "=", $user["type"]];
  212. $where[] = ["e.isGeneral", "=", 2];
  213. $where[] = ["e.medicalCommunityId", "=", $user["medicalCommunityId"]];
  214. $where[] = ["ti.first_submit_time", "EXP", \think\facade\Db::raw("is not null")];
  215. if ($name) {
  216. $where[] = ["ti.name", "like", "%" . $name . "%"];
  217. }
  218. if ($idCard) {
  219. $where[] = ["ti.card_number", "like", "%" . $idCard . "%"];
  220. }
  221. if ($sex) {
  222. $where[] = ["ti.sex", "=", $sex];
  223. }
  224. if ($nation) {
  225. $where[] = ["ti.nation", "=", $nation];
  226. }
  227. if ($talentArrange) {
  228. $where[] = ["ti.talent_arrange", "=", $talentArrange];
  229. }
  230. $whereRaw = sprintf("tl.state in (%s,%s) or tl.state >= %s", TalentState::FST_SUBMIT, TalentState::BASE_REJECT, TalentState::SCND_SUBMIT);
  231. switch ($checkState) {
  232. case 1:
  233. $where[] = ["tl.state", "=", TalentState::FST_SUBMIT];
  234. break;
  235. case 2:
  236. $where[] = ["tl.state", "=", TalentState::BASE_REJECT];
  237. break;
  238. case 3:
  239. $where[] = ["tl.state", ">=", TalentState::SCND_SUBMIT];
  240. break;
  241. }
  242. $count = Talent::where($where)->whereRaw($whereRaw)->alias("ti")
  243. ->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")
  244. ->leftJoin("(select 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")
  245. ->count();
  246. $list = Talent::where($where)->whereRaw($whereRaw)->alias("ti")
  247. ->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")
  248. ->leftJoin("(select 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")
  249. ->field("ti.*,e.name as enterpriseName,e.type")
  250. ->limit($offset, $limit)->order("ti.createTime " . $order)->select()->toArray();
  251. $talentArangeList = DictApi::selectByParentCode("talent_arrange"); //人才层次
  252. foreach ($list as $key => $item) {
  253. $condition = TalentConditionApi::getOne($item["talent_condition"]);
  254. $list[$key]["talentArrangeName"] = isset($talentArangeList[$item["talent_arrange"]]) ? $talentArangeList[$item["talent_arrange"]] : "";
  255. $list[$key]["talentConditionName"] = $condition["name"];
  256. $last_log = TalentLogApi::getLastLog($item["id"], 1, 0, ["active", "=", 1]);
  257. $list[$key]["real_state"] = $last_log["state"];
  258. $list[$key]["last_state"] = $last_log["last_state"];
  259. }
  260. return ["total" => $count, "rows" => $list];
  261. }
  262. return [];
  263. }
  264. }