TalentWorkUnitChange.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\common\AdminController;
  4. use app\common\model\TalentWorkUnitChange as TwcModel;
  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. use app\common\api\EnterpriseApi;
  11. /**
  12. * Description of TalentWorkUnitChange
  13. *
  14. * @author sgq
  15. */
  16. class TalentWorkUnitChange extends AdminController {
  17. public function index() {
  18. return view("", ["type" => $this->user["type"]]);
  19. }
  20. public function list() {
  21. $params = $this->request->param();
  22. $offset = $params["offset"] ?: 0;
  23. $order = $params["order"] ?: "desc";
  24. $limit = $params["limit"] ?: 10;
  25. $where = $this->setTalentWorkunitChange($params);
  26. $where[] = ["type", "=", $this->user["type"]];
  27. $where[] = ["delete", "=", 0];
  28. //获取字典表人才层次
  29. $levelMap = DictApi::selectByParentCode("talent_arrange");
  30. $epMaps = \app\common\model\Enterprise::column("name", "id");
  31. $count = TwcModel::where($where)->count();
  32. $list = TwcModel::where($where)->limit($offset, $limit)->order("createTime {$order}")->select()->toArray();
  33. foreach ($list as $key => $item) {
  34. $list[$key]["talentArrangeName"] = $levelMap[$item["talentArrange"]];
  35. $list[$key]["oldEnterpriseName"] = $epMaps[$item["oldEnterpriseId"]];
  36. $list[$key]["newEnterpriseName"] = $epMaps[$item["newEnterpriseId"]];
  37. if ($item["checkState"] == -2) {
  38. $list[$key]["checkStateName"] = "审核不通过";
  39. }
  40. if ($item["checkState"] == -1) {
  41. $list[$key]["checkStateName"] = "待提交";
  42. }
  43. if ($item["checkState"] == 1) {
  44. $list[$key]["checkStateName"] = "待审核";
  45. }
  46. if ($item["checkState"] == 2) {
  47. $list[$key]["checkStateName"] = "审核驳回";
  48. }
  49. if ($item["checkState"] == 3) {
  50. $list[$key]["checkStateName"] = "已通过";
  51. }
  52. if ($item["checkState"] == 9) {
  53. $list[$key]["checkStateName"] = "重新提交";
  54. }
  55. }
  56. return json(["rows" => $list, "total" => $count]);
  57. }
  58. public function check() {
  59. $id = $this->request["id"];
  60. $info = TwcModel::where("id", $id)->find();
  61. $info["talentArrangeName"] = DictApi::selectByParentCode("talent_arrange")[$info["talentArrange"]];
  62. $epOld = EnterpriseApi::getOne($info["oldEnterpriseId"]);
  63. $epNew = EnterpriseApi::getOne($info["newEnterpriseId"]);
  64. $info["oldEnterpriseName"] = $epOld["name"];
  65. $info["newEnterpriseName"] = $epNew["name"];
  66. return view("check", ["type" => $this->user["type"], "row" => $info]);
  67. }
  68. public function submitToCheck() {
  69. $responseObj = new \stdClass();
  70. $responseObj->code = 500;
  71. $id = $this->request["id"];
  72. $checkState = $this->request["checkState"];
  73. $checkMsg = $this->request["checkMsg"];
  74. $info = TwcModel::where("id", $id)->find();
  75. if (!$info) {
  76. $responseObj->msg = "系统错误,请联系管理员";
  77. return $responseObj;
  78. }
  79. if (!$checkState) {
  80. $responseObj->msg = "请选择审核状态";
  81. return $responseObj;
  82. }
  83. $tmpState = $checkState == -2 ? -1 : $checkState;
  84. Db::startTrans();
  85. try {
  86. //添加日志
  87. $user = $this->user;
  88. $log["id"] = getStringId();
  89. $log["active"] = 1;
  90. $log["state"] = $tmpState;
  91. $log["step"] = 11;
  92. $log["stateChange"] = MainState::getStateName($info["checkState"]) . "->" . MainState::getStateName($tmpState);
  93. $log["type"] = ProjectState::WORKCHANGE;
  94. $log["mainId"] = $id;
  95. $log["description"] = $checkMsg;
  96. $log["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  97. $log["createTime"] = date("Y-m-d H:i:s");
  98. $updWorkChange["id"] = $id;
  99. $updWorkChange["checkState"] = $checkState;
  100. $updWorkChange["checkMsg"] = $checkMsg;
  101. if ($checkState == 3) {
  102. //修改人才库信息
  103. $upd["id"] = $info["talentId"];
  104. $upd["enterprise_id"] = $info["newEnterpriseId"];
  105. $upd["labor_contract_rangetime"] = $info["starttime"] . " - " . $info["endtime"];
  106. $upd["cur_entry_time"] = $info["anyTime"];
  107. $upd["active"] = 1;
  108. $upd["cur_quit_time"] = null;
  109. $upd["position"] = $info["newPost"];
  110. Db::table("new_talent_info")->save($upd);
  111. $talentLog["id"] = getStringId();
  112. $talentLog["active"] = 1;
  113. $talentLog["step"] = 21;
  114. $talentLog["type"] = ProjectState::TALENT;
  115. $talentLog["mainId"] = $info["talentId"];
  116. $talentLog["description"] = "工作单位变更通过,同步到人才库";
  117. $talentLog["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  118. $talentLog["createTime"] = date("Y-m-d H:i:s");
  119. Db::table("new_talent_checklog")->insert($talentLog);
  120. $updWorkChange["passTime"] = date("Y-m-d H:i:s");
  121. }
  122. Db::table("new_talent_checklog")->insert($log);
  123. Db::table("un_talent_workunit_change")->save($updWorkChange);
  124. $responseObj->code = 200;
  125. $responseObj->msg = "审核成功";
  126. Db::commit();
  127. return $responseObj;
  128. } catch (\think\db\exception\DbException $e) {
  129. $responseObj->msg = $e->getMessage();
  130. Db::rollback();
  131. return $responseObj;
  132. }
  133. }
  134. public function export() {
  135. $request = $this->request;
  136. $data["talentName"] = \StrUtil::getRequestDecodeParam($request, "talentName");
  137. $data["idCard"] = \StrUtil::getRequestDecodeParam($request, "idCard");
  138. $data["oldEnterpriseName"] = \StrUtil::getRequestDecodeParam($request, "oldEnterpriseName");
  139. $data["newEnterpriseName"] = \StrUtil::getRequestDecodeParam($request, "newEnterpriseName");
  140. $data["checkState"] = \StrUtil::getRequestDecodeParam($request, "checkState");
  141. $where = $this->setTalentWorkunitChange($data);
  142. $where[] = ["type", "=", $this->user["type"]];
  143. $where[] = ["delete", "=", 0];
  144. $list = TwcModel::where($where)->select()->toArray();
  145. $levelMap = DictApi::selectByParentCode("talent_arrange");
  146. $epMaps = \app\common\model\Enterprise::column("name", "id");
  147. if ($this->user["type"] == 1) {
  148. $title = ["姓名", "证件号码", "人才层次", "原工作单位", "离职时间", "离职申报原因", "新工作单位",
  149. "合同开始时间", "合同结束时间", "入职/变更时间", "单位变更申报原因", "手机号码", "审核状态", "审核意见", "审核通过时间"];
  150. $keys = ["talentName", "idCard", "talentArrangeName", "oldEnterpriseName", "quitTime", "quitReason", "newEnterpriseName",
  151. "starttime", "endtime", "anyTime", "anyReason", "phone", "checkStateName", "checkMsg", "passTime"];
  152. } else {
  153. $title = ["姓名", "证件号码", "人才层次", "原工作单位", "离职时间", "新工作单位",
  154. "合同开始时间", "合同结束时间", "入职/变更时间", "手机号码", "审核状态", "审核意见", "审核通过时间"];
  155. $keys = ["talentName", "idCard", "talentArrangeName", "oldEnterpriseName", "quitTime", "newEnterpriseName",
  156. "starttime", "endtime", "anyTime", "phone", "checkStateName", "checkMsg", "passTime"];
  157. }
  158. $rows = [];
  159. foreach ($list as &$item) {
  160. $item["talentArrangeName"] = $levelMap[$item["talentArrange"]];
  161. $item["oldEnterpriseName"] = $epMaps[$item["oldEnterpriseId"]];
  162. $item["newEnterpriseName"] = $epMaps[$item["newEnterpriseId"]];
  163. switch ($item["checkState"]) {
  164. case -1:
  165. $item["checkStateName"] = "待提交";
  166. break;
  167. case 1:
  168. $item["checkStateName"] = "待审核";
  169. break;
  170. case 2:
  171. $item["checkStateName"] = "审核驳回";
  172. break;
  173. case 3:
  174. $item["checkStateName"] = "已通过";
  175. break;
  176. case 9:
  177. $item["checkStateName"] = "重新提交";
  178. break;
  179. }
  180. $row = [];
  181. for ($i = 0; $i < count($keys); $i++) {
  182. $row[] = $item[$keys[$i]];
  183. }
  184. $rows[] = $row;
  185. }unset($item);
  186. if (!$rows) {
  187. return json(["msg" => "没有可导出的内容"]);
  188. }
  189. $fileName = "工作单位变更列表";
  190. export($title, $rows, $fileName);
  191. }
  192. private function setTalentWorkunitChange($twcInfo) {
  193. $where = [];
  194. if (\StrUtil::isNotEmpAndNull($twcInfo["talentName"])) {
  195. $where[] = ["talentName", "=", $twcInfo["talentName"]];
  196. }
  197. if (\StrUtil::isNotEmpAndNull($twcInfo["idCard"])) {
  198. $where[] = ["idCard", "=", $twcInfo["IdCard"]];
  199. }
  200. if (\StrUtil::isNotEmpAndNull($twcInfo["oldEnterpriseName"])) {
  201. $whr = [];
  202. $whr[] = ["name", "like", "%{$params["oldEnterpriseName"]}%"];
  203. $ids = \app\common\model\Enterprise::where($whr)->column("id");
  204. $where[] = ["oldEnterpriseId", "in", $ids];
  205. }
  206. if (\StrUtil::isNotEmpAndNull($twcInfo["newEnterpriseName"])) {
  207. $whr = [];
  208. $whr[] = ["name", "like", "%{$params["newEnterpriseName"]}%"];
  209. $ids = \app\common\model\Enterprise::where($whr)->column("id");
  210. $where[] = ["newEnterpriseId", "in", $ids];
  211. }
  212. if ($twcInfo["checkState"] != null) {
  213. $where[] = ["checkState", "=", $talentQuitInfo["checkState"]];
  214. }
  215. return $where;
  216. }
  217. }