TalentBasicChange.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. Db::table("new_talent_info")->save($upd);
  127. $talentLog["id"] = getStringId();
  128. $talentLog["active"] = 1;
  129. $talentLog["step"] = 24;
  130. $talentLog["type"] = ProjectState::TALENT;
  131. $talentLog["mainId"] = $info["talentId"];
  132. $talentLog["description"] = "基础信息变更通过,同步到人才库";
  133. $talentLog["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  134. $talentLog["createTime"] = date("Y-m-d H:i:s");
  135. Db::table("new_talent_checklog")->insert($talentLog);
  136. }
  137. Db::table("new_talent_checklog")->insert($log);
  138. Db::table("un_talent_basic_change")->save($updTalentBasic);
  139. $responseObj->code = 200;
  140. $responseObj->msg = "审核成功";
  141. Db::commit();
  142. return $responseObj;
  143. } catch (\think\db\exception\DbException $e) {
  144. $responseObj->msg = $e->getMessage();
  145. Db::rollback();
  146. return $responseObj;
  147. }
  148. }
  149. public function export() {
  150. $request = $this->request;
  151. $data["enterpriseName"] = \StrUtil::getRequestDecodeParam($request, "enterpriseName");
  152. $data["oldName"] = \StrUtil::getRequestDecodeParam($request, "oldName");
  153. $data["oldCardType"] = \StrUtil::getRequestDecodeParam($request, "oldCardType");
  154. $data["oldIdCard"] = \StrUtil::getRequestDecodeParam($request, "oldIdCard");
  155. $data["newName"] = \StrUtil::getRequestDecodeParam($request, "newName");
  156. $data["newCardType"] = \StrUtil::getRequestDecodeParam($request, "newCardType");
  157. $data["newIdCard"] = \StrUtil::getRequestDecodeParam($request, "newIdCard");
  158. $data["checkState"] = \StrUtil::getRequestDecodeParam($request, "checkState");
  159. $where = $this->setTalentBasic($data);
  160. $where[] = ["type", "=", $this->user["type"]];
  161. $where[] = ["delete", "=", 0];
  162. $list = TbcModel::where($where)->select()->toArray();
  163. $nationalityMap = DictApi::selectByParentCode("nationality");
  164. $nationMap = DictApi::selectByParentCode("nation");
  165. $politicalMap = DictApi::selectByParentCode("politics");
  166. $cardTypeMap = DictApi::selectByParentCode("card_type");
  167. $epMaps = \app\common\model\Enterprise::column("name", "id");
  168. $title = ["申报单位", "原姓名", "原出生日期", "原国家/地区", "原民族", "原政治面貌", "原证件类型", "原证件号码", "原电子邮箱",
  169. "现姓名", "现出生日期", "现国家/地区", "现民族", "现政治面貌", "现证件类型", "现证件号码", "现电子邮箱", "首次提交时间", "最新提交时间", "审核状态"];
  170. $keys = ["enterpriseName", "oldName", "oldBirthday", "oldNationalityName", "oldNationName", "oldPoliticsName", "oldCardTypeName", "oldIdCard", "oldEmail",
  171. "newName", "newBirthday", "newNationalityName", "newNationName", "newPoliticsName", "newCardTypeName", "newIdCard", "newEmail", "firstSubmitTime", "newSubmitTime", "checkStateName"];
  172. $rows = [];
  173. foreach ($list as &$item) {
  174. $item["oldNationalityName"] = $nationalityMap[$item["oldNationality"]];
  175. $item["oldNationName"] = $nationMap[$item["oldNation"]];
  176. $item["oldPoliticsName"] = $politicalMap[$item["oldPolitics"]];
  177. $item["oldCardTypeName"] = $cardTypeMap[$item["oldCardType"]];
  178. $item["newNationalityName"] = $nationalityMap[$item["newNationality"]];
  179. $item["newNationName"] = $nationMap[$item["newNation"]];
  180. $item["newPoliticsName"] = $politicalMap[$item["newPolitics"]];
  181. $item["newCardTypeName"] = $cardTypeMap[$item["newCardType"]];
  182. $item["enterpriseName"] = $epMaps[$item["enterpriseId"]];
  183. switch ($item["checkState"]) {
  184. case -1:
  185. $item["checkStateName"] = "待提交";
  186. break;
  187. case 1:
  188. $item["checkStateName"] = "待审核";
  189. break;
  190. case 2:
  191. $item["checkStateName"] = "审核驳回";
  192. break;
  193. case 3:
  194. $item["checkStateName"] = "已通过";
  195. break;
  196. case 9:
  197. $item["checkStateName"] = "重新提交";
  198. break;
  199. }
  200. $row = [];
  201. for ($i = 0; $i < count($keys); $i++) {
  202. $row[] = $item[$keys[$i]];
  203. }
  204. $rows[] = $row;
  205. }unset($item);
  206. if (!$rows) {
  207. return json(["msg" => "没有可导出的内容"]);
  208. }
  209. $fileName = "基础信息变更列表";
  210. export($title, $rows, $fileName);
  211. }
  212. private function setTalentBasic($talentBasicInfo) {
  213. $where = [];
  214. if (\StrUtil::isNotEmpAndNull($talentBasicInfo["enterpriseName"])) {
  215. $whr = [];
  216. $whr[] = ["name", "like", "%{$talentBasicInfo["enterpriseName"]}%"];
  217. $ids = \app\common\model\Enterprise::where($whr)->column("id");
  218. $where[] = ["enterpriseName", "in", $ids];
  219. }
  220. if (\StrUtil::isNotEmpAndNull($talentBasicInfo["oldName"])) {
  221. $where[] = ["oldName", "like", "%" . $talentBasicInfo["oldName"] . "%"];
  222. }
  223. if (\StrUtil::isNotEmpAndNull($talentBasicInfo["oldCardType"])) {
  224. $where[] = ["oldCardType", "=", $talentBasicInfo["oldCardType"]];
  225. }
  226. if (\StrUtil::isNotEmpAndNull($talentBasicInfo["oldIdCard"])) {
  227. $where[] = ["oldIdCard", "like", "%" . $talentBasicInfo["oldIdCard"] . "%"];
  228. }
  229. if (\StrUtil::isNotEmpAndNull($talentBasicInfo["newName"])) {
  230. $where[] = ["newName", "like", "%" . $talentBasicInfo["newName"] . "%"];
  231. }
  232. if (\StrUtil::isNotEmpAndNull($talentBasicInfo["newCardType"])) {
  233. $where[] = ["newCardType", "=", $talentBasicInfo["newCardType"]];
  234. }
  235. if (\StrUtil::isNotEmpAndNull($talentBasicInfo["newIdCard"])) {
  236. $where[] = ["newIdCard", "like", "%" . $talentBasicInfo["newIdCard"] . "%"];
  237. }
  238. if ($talentBasicInfo["checkState"] != null) {
  239. $where[] = ["checkState", "=", $talentBasicInfo["checkState"]];
  240. }
  241. return $where;
  242. }
  243. }