TalentBasicChange.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\common\AdminController;
  4. use app\common\model\TalentBasicChange as TbcModel;
  5. use app\common\api\DictApi;
  6. use app\common\state\MainState;
  7. use app\common\model\TalentLog;
  8. use app\common\state\ProjectState;
  9. use think\facade\Db;
  10. /**
  11. * Description of TalentBasicChange
  12. *
  13. * @author sgq
  14. */
  15. class TalentBasicChange extends AdminController {
  16. public function index() {
  17. return view("", ["type" => $this->user["type"]]);
  18. }
  19. public function list() {
  20. $params = $this->request->param();
  21. $offset = $params["offset"] ?: 0;
  22. $order = $params["order"] ?: "desc";
  23. $limit = $params["limit"] ?: 10;
  24. $where = $this->setTalentBasic($params);
  25. $where[] = ["type", "=", $this->user["type"]];
  26. $where[] = ["delete", "=", 0];
  27. $count = TbcModel::where($where)->count();
  28. $list = TbcModel::where($where)->limit($offset, $limit)->order("createTime {$order}")->select()->toArray();
  29. $nationalityMap = DictApi::selectByParentCode("nationality");
  30. $nationMap = DictApi::selectByParentCode("nation");
  31. $politicalMap = DictApi::selectByParentCode("politics");
  32. $cardTypeMap = DictApi::selectByParentCode("card_type");
  33. $epMaps = \app\common\model\Enterprise::column("name", "id");
  34. foreach ($list as $key => $item) {
  35. $list[$key]["oldNationalityName"] = $nationalityMap[$item["oldNationality"]];
  36. $list[$key]["oldNationName"] = $nationMap[$item["oldNation"]];
  37. $list[$key]["oldPoliticsName"] = $politicalMap[$item["oldPolitics"]];
  38. $list[$key]["oldCardTypeName"] = $cardTypeMap[$item["oldCardType"]];
  39. $list[$key]["newNationalityName"] = $nationalityMap[$item["newNationality"]];
  40. $list[$key]["newNationName"] = $nationMap[$item["newNation"]];
  41. $list[$key]["newPoliticsName"] = $politicalMap[$item["newPolitics"]];
  42. $list[$key]["newCardTypeName"] = $cardTypeMap[$item["newCardType"]];
  43. $list[$key]["enterpriseName"] = $epMaps[$item["enterpriseId"]];
  44. if ($item["checkState"] == -1) {
  45. $list[$key]["checkStateName"] = "待提交";
  46. }
  47. if ($item["checkState"] == 1) {
  48. $list[$key]["checkStateName"] = "待审核";
  49. }
  50. if ($item["checkState"] == 2) {
  51. $list[$key]["checkStateName"] = "审核驳回";
  52. }
  53. if ($item["checkState"] == 3) {
  54. $list[$key]["checkStateName"] = "已通过";
  55. }
  56. if ($item["checkState"] == 9) {
  57. $list[$key]["checkStateName"] = "重新提交";
  58. }
  59. }
  60. return json(["rows" => $list, "total" => $count]);
  61. }
  62. public function check() {
  63. $id = $this->request["id"];
  64. $info = TbcModel::where("id", $id)->find();
  65. return view("check", ["type" => $this->user["type"], "row" => $info]);
  66. }
  67. public function submitToCheck() {
  68. $responseObj = new \stdClass();
  69. $responseObj->code = 500;
  70. $id = $this->request["id"];
  71. $checkState = $this->request["checkState"];
  72. $checkMsg = $this->request["checkMsg"];
  73. $info = TbcModel::where("id", $id)->find();
  74. if (!$info) {
  75. $responseObj->msg = "系统错误,请联系管理员";
  76. return $responseObj;
  77. }
  78. if (strlen($info["talentId"]) == 19) {
  79. //旧系统申请兼容处理
  80. unset($where);
  81. $where[] = ["enterprise_id", "=", $info["enterpriseId"]];
  82. $where[] = ["card_type", "=", $info["oldCardType"]];
  83. $where[] = ["card_number", "=", $info["oldIdCard"]];
  84. $where[] = ["checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  85. $where[] = ["active", "=", 1];
  86. $where[] = ["delete", "=", 0];
  87. $ti = \app\enterprise\model\Talent::where($where)->order("createTime desc")->find();
  88. if (!$ti) {
  89. $responseObj->msg = "未匹配到人才数据";
  90. return $responseObj;
  91. }
  92. $info["talentId"] = $ti["id"];
  93. }
  94. if (!$checkState) {
  95. $responseObj->msg = "请选择审核状态";
  96. return $responseObj;
  97. }
  98. Db::startTrans();
  99. try {
  100. //添加日志
  101. $user = $this->user;
  102. $log["id"] = getStringId();
  103. $log["active"] = 1;
  104. $log["state"] = $checkState;
  105. $log["step"] = 11;
  106. $log["stateChange"] = MainState::getStateName($info["checkState"]) . "->" . MainState::getStateName($checkState);
  107. $log["type"] = ProjectState::BASICCHANGE;
  108. $log["mainId"] = $id;
  109. $log["description"] = $checkMsg;
  110. $log["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  111. $log["createTime"] = date("Y-m-d H:i:s");
  112. $updTalentBasic["id"] = $id;
  113. $updTalentBasic["checkState"] = $checkState;
  114. $updTalentBasic["checkMsg"] = $checkMsg;
  115. if ($checkState == 3) {
  116. //修改人才库信息
  117. $upd["id"] = $info["talentId"];
  118. $upd["name"] = $info["newName"];
  119. $upd["birthday"] = $info["newBirthday"];
  120. $upd["nationality"] = $info["newNationality"];
  121. $upd["nation"] = $info["newNation"];
  122. $upd["politics"] = $info["newPolitics"];
  123. $upd["card_type"] = $info["newCardType"];
  124. $upd["card_number"] = $info["newIdCard"];
  125. $upd["email"] = $info["newEmail"];
  126. $upd["labor_contract_rangetime"] = $info["newContractTime"];
  127. Db::table("new_talent_info")->save($upd);
  128. $talentLog["id"] = getStringId();
  129. $talentLog["active"] = 1;
  130. $talentLog["step"] = 24;
  131. $talentLog["type"] = ProjectState::TALENT;
  132. $talentLog["mainId"] = $info["talentId"];
  133. $talentLog["description"] = "基础信息变更通过,同步到人才库";
  134. $talentLog["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  135. $talentLog["createTime"] = date("Y-m-d H:i:s");
  136. Db::table("new_talent_checklog")->insert($talentLog);
  137. }
  138. Db::table("new_talent_checklog")->insert($log);
  139. Db::table("un_talent_basic_change")->save($updTalentBasic);
  140. $responseObj->code = 200;
  141. $responseObj->msg = "审核成功";
  142. Db::commit();
  143. return $responseObj;
  144. } catch (\think\db\exception\DbException $e) {
  145. $responseObj->msg = $e->getMessage();
  146. Db::rollback();
  147. return $responseObj;
  148. }
  149. }
  150. public function export() {
  151. $request = $this->request;
  152. $data["enterpriseName"] = \StrUtil::getRequestDecodeParam($request, "enterpriseName");
  153. $data["oldName"] = \StrUtil::getRequestDecodeParam($request, "oldName");
  154. $data["oldCardType"] = \StrUtil::getRequestDecodeParam($request, "oldCardType");
  155. $data["oldIdCard"] = \StrUtil::getRequestDecodeParam($request, "oldIdCard");
  156. $data["newName"] = \StrUtil::getRequestDecodeParam($request, "newName");
  157. $data["newCardType"] = \StrUtil::getRequestDecodeParam($request, "newCardType");
  158. $data["newIdCard"] = \StrUtil::getRequestDecodeParam($request, "newIdCard");
  159. $data["checkState"] = \StrUtil::getRequestDecodeParam($request, "checkState");
  160. $where = $this->setTalentBasic($data);
  161. $where[] = ["type", "=", $this->user["type"]];
  162. $where[] = ["delete", "=", 0];
  163. $list = TbcModel::where($where)->select()->toArray();
  164. $nationalityMap = DictApi::selectByParentCode("nationality");
  165. $nationMap = DictApi::selectByParentCode("nation");
  166. $politicalMap = DictApi::selectByParentCode("politics");
  167. $cardTypeMap = DictApi::selectByParentCode("card_type");
  168. $epMaps = \app\common\model\Enterprise::column("name", "id");
  169. $title = ["申报单位", "原姓名", "原出生日期", "原国家/地区", "原民族", "原政治面貌", "原证件类型", "原证件号码", "原电子邮箱", "原劳动合同起止时间",
  170. "现姓名", "现出生日期", "现国家/地区", "现民族", "现政治面貌", "现证件类型", "现证件号码", "现电子邮箱", "现劳动合同起止时间", "首次提交时间", "最新提交时间", "审核状态"];
  171. $keys = ["enterpriseName", "oldName", "oldBirthday", "oldNationalityName", "oldNationName", "oldPoliticsName", "oldCardTypeName", "oldIdCard", "oldEmail", "oldContractTime",
  172. "newName", "newBirthday", "newNationalityName", "newNationName", "newPoliticsName", "newCardTypeName", "newIdCard", "newEmail", "newContractTime", "firstSubmitTime", "newSubmitTime", "checkStateName"];
  173. $rows = [];
  174. foreach ($list as &$item) {
  175. $item["oldNationalityName"] = $nationalityMap[$item["oldNationality"]];
  176. $item["oldNationName"] = $nationMap[$item["oldNation"]];
  177. $item["oldPoliticsName"] = $politicalMap[$item["oldPolitics"]];
  178. $item["oldCardTypeName"] = $cardTypeMap[$item["oldCardType"]];
  179. $item["newNationalityName"] = $nationalityMap[$item["newNationality"]];
  180. $item["newNationName"] = $nationMap[$item["newNation"]];
  181. $item["newPoliticsName"] = $politicalMap[$item["newPolitics"]];
  182. $item["newCardTypeName"] = $cardTypeMap[$item["newCardType"]];
  183. $item["enterpriseName"] = $epMaps[$item["enterpriseId"]];
  184. switch ($item["checkState"]) {
  185. case -1:
  186. $item["checkStateName"] = "待提交";
  187. break;
  188. case 1:
  189. $item["checkStateName"] = "待审核";
  190. break;
  191. case 2:
  192. $item["checkStateName"] = "审核驳回";
  193. break;
  194. case 3:
  195. $item["checkStateName"] = "已通过";
  196. break;
  197. case 9:
  198. $item["checkStateName"] = "重新提交";
  199. break;
  200. }
  201. $row = [];
  202. for ($i = 0; $i < count($keys); $i++) {
  203. $row[] = $item[$keys[$i]];
  204. }
  205. $rows[] = $row;
  206. }unset($item);
  207. if (!$rows) {
  208. return json(["msg" => "没有可导出的内容"]);
  209. }
  210. $fileName = "基础信息变更列表";
  211. export($title, $rows, $fileName);
  212. }
  213. private function setTalentBasic($talentBasicInfo) {
  214. $where = [];
  215. if (\StrUtil::isNotEmpAndNull($talentBasicInfo["enterpriseName"])) {
  216. $whr = [];
  217. $whr[] = ["name", "like", "%{$talentBasicInfo["enterpriseName"]}%"];
  218. $ids = \app\common\model\Enterprise::where($whr)->column("id");
  219. $where[] = ["enterpriseName", "in", $ids];
  220. }
  221. if (\StrUtil::isNotEmpAndNull($talentBasicInfo["oldName"])) {
  222. $where[] = ["oldName", "like", "%" . $talentBasicInfo["oldName"] . "%"];
  223. }
  224. if (\StrUtil::isNotEmpAndNull($talentBasicInfo["oldCardType"])) {
  225. $where[] = ["oldCardType", "=", $talentBasicInfo["oldCardType"]];
  226. }
  227. if (\StrUtil::isNotEmpAndNull($talentBasicInfo["oldIdCard"])) {
  228. $where[] = ["oldIdCard", "like", "%" . $talentBasicInfo["oldIdCard"] . "%"];
  229. }
  230. if (\StrUtil::isNotEmpAndNull($talentBasicInfo["newName"])) {
  231. $where[] = ["newName", "like", "%" . $talentBasicInfo["newName"] . "%"];
  232. }
  233. if (\StrUtil::isNotEmpAndNull($talentBasicInfo["newCardType"])) {
  234. $where[] = ["newCardType", "=", $talentBasicInfo["newCardType"]];
  235. }
  236. if (\StrUtil::isNotEmpAndNull($talentBasicInfo["newIdCard"])) {
  237. $where[] = ["newIdCard", "like", "%" . $talentBasicInfo["newIdCard"] . "%"];
  238. }
  239. if ($talentBasicInfo["checkState"] != null) {
  240. $where[] = ["checkState", "=", $talentBasicInfo["checkState"]];
  241. }
  242. return $where;
  243. }
  244. }