TalentWorkUnitChange.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. //获取字典表人才层次
  28. $levelMap = DictApi::selectByParentCode("talent_arrange");
  29. $epMaps = \app\common\model\Enterprise::column("name", "id");
  30. $count = TwcModel::where($where)->count();
  31. $list = TwcModel::where($where)->limit($offset, $limit)->order("createTime {$order}")->select()->toArray();
  32. foreach ($list as $key => $item) {
  33. $list[$key]["talentArrangeName"] = $levelMap[$item["talentArrange"]];
  34. $list[$key]["oldEnterpriseName"] = $epMaps[$item["oldEnterpriseId"]];
  35. $list[$key]["newEnterpriseName"] = $epMaps[$item["newEnterpriseId"]];
  36. if ($item["checkState"] == -2) {
  37. $list[$key]["checkStateName"] = "审核不通过";
  38. }
  39. if ($item["checkState"] == -1) {
  40. $list[$key]["checkStateName"] = "待提交";
  41. }
  42. if ($item["checkState"] == 1) {
  43. $list[$key]["checkStateName"] = "待审核";
  44. }
  45. if ($item["checkState"] == 2) {
  46. $list[$key]["checkStateName"] = "审核驳回";
  47. }
  48. if ($item["checkState"] == 3) {
  49. $list[$key]["checkStateName"] = "已通过";
  50. }
  51. if ($item["checkState"] == 9) {
  52. $list[$key]["checkStateName"] = "重新提交";
  53. }
  54. }
  55. return json(["rows" => $list, "total" => $count]);
  56. }
  57. public function check() {
  58. $id = $this->request["id"];
  59. $info = TwcModel::where("id", $id)->find();
  60. $info["talentArrangeName"] = DictApi::selectByParentCode("talent_arrange")[$info["talentArrange"]];
  61. $epOld = EnterpriseApi::getOne($info["oldEnterpriseId"]);
  62. $epNew = EnterpriseApi::getOne($info["newEnterpriseId"]);
  63. $info["oldEnterpriseName"] = $epOld["name"];
  64. $info["newEnterpriseName"] = $epNew["name"];
  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 = TwcModel::where("id", $id)->find();
  74. if (!$info) {
  75. $responseObj->msg = "系统错误,请联系管理员";
  76. return $responseObj;
  77. }
  78. if (!$checkState) {
  79. $responseObj->msg = "请选择审核状态";
  80. return $responseObj;
  81. }
  82. $tmpState = $checkState == -2 ? -1 : $checkState;
  83. Db::startTrans();
  84. try {
  85. //添加日志
  86. $user = $this->user;
  87. $log["id"] = getStringId();
  88. $log["active"] = 1;
  89. $log["state"] = $tmpState;
  90. $log["step"] = 11;
  91. $log["stateChange"] = MainState::getStateName($info["checkState"]) . "->" . MainState::getStateName($tmpState);
  92. $log["type"] = ProjectState::WORKCHANGE;
  93. $log["mainId"] = $id;
  94. $log["description"] = $checkMsg;
  95. $log["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  96. $log["createTime"] = date("Y-m-d H:i:s");
  97. $updWorkChange["id"] = $id;
  98. $updWorkChange["checkState"] = $checkState;
  99. $updWorkChange["checkMsg"] = $checkMsg;
  100. if ($checkState == 3) {
  101. //修改人才库信息
  102. $upd["id"] = $info["talentId"];
  103. $upd["enterprise_id"] = $info["newEnterpriseId"];
  104. $upd["labor_contract_rangetime"] = $info["starttime"] . " - " . $info["endtime"];
  105. $upd["cur_entry_time"] = $info["anyTime"];
  106. $upd["active"] = 1;
  107. $upd["cur_quit_time"] = null;
  108. $upd["position"] = $info["newPost"];
  109. Db::table("new_talent_info")->save($upd);
  110. $talentLog["id"] = getStringId();
  111. $talentLog["active"] = 1;
  112. $talentLog["step"] = 21;
  113. $talentLog["type"] = ProjectState::TALENT;
  114. $talentLog["mainId"] = $info["talentId"];
  115. $talentLog["description"] = "工作单位变更通过,同步到人才库";
  116. $talentLog["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  117. $talentLog["createTime"] = date("Y-m-d H:i:s");
  118. Db::table("new_talent_checklog")->insert($talentLog);
  119. $updWorkChange["passTime"] = date("Y-m-d H:i:s");
  120. }
  121. Db::table("new_talent_checklog")->insert($log);
  122. Db::table("un_talent_workunit_change")->save($updWorkChange);
  123. $responseObj->code = 200;
  124. $responseObj->msg = "审核成功";
  125. Db::commit();
  126. return $responseObj;
  127. } catch (\think\db\exception\DbException $e) {
  128. $responseObj->msg = $e->getMessage();
  129. Db::rollback();
  130. return $responseObj;
  131. }
  132. }
  133. private function setTalentWorkunitChange($twcInfo) {
  134. $where = [];
  135. if (\StrUtil::isNotEmpAndNull($twcInfo["talentName"])) {
  136. $where[] = ["talentName", "=", $twcInfo["talentName"]];
  137. }
  138. if (\StrUtil::isNotEmpAndNull($twcInfo["idCard"])) {
  139. $where[] = ["idCard", "=", $twcInfo["IdCard"]];
  140. }
  141. if (\StrUtil::isNotEmpAndNull($twcInfo["oldEnterpriseName"])) {
  142. $whr = [];
  143. $whr[] = ["name", "like", "%{$params["oldEnterpriseName"]}%"];
  144. $ids = \app\common\model\Enterprise::where($whr)->column("id");
  145. $where[] = ["oldEnterpriseId", "in", $ids];
  146. }
  147. if (\StrUtil::isNotEmpAndNull($twcInfo["newEnterpriseName"])) {
  148. $whr = [];
  149. $whr[] = ["name", "like", "%{$params["newEnterpriseName"]}%"];
  150. $ids = \app\common\model\Enterprise::where($whr)->column("id");
  151. $where[] = ["newEnterpriseId", "in", $ids];
  152. }
  153. if ($twcInfo["checkState"] != null) {
  154. $where[] = ["checkState", "=", $talentQuitInfo["checkState"]];
  155. }
  156. return $where;
  157. }
  158. }