TalentWorkUnitChange.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. private function setTalentWorkunitChange($twcInfo) {
  135. $where = [];
  136. if (\StrUtil::isNotEmpAndNull($twcInfo["talentName"])) {
  137. $where[] = ["talentName", "=", $twcInfo["talentName"]];
  138. }
  139. if (\StrUtil::isNotEmpAndNull($twcInfo["idCard"])) {
  140. $where[] = ["idCard", "=", $twcInfo["IdCard"]];
  141. }
  142. if (\StrUtil::isNotEmpAndNull($twcInfo["oldEnterpriseName"])) {
  143. $whr = [];
  144. $whr[] = ["name", "like", "%{$params["oldEnterpriseName"]}%"];
  145. $ids = \app\common\model\Enterprise::where($whr)->column("id");
  146. $where[] = ["oldEnterpriseId", "in", $ids];
  147. }
  148. if (\StrUtil::isNotEmpAndNull($twcInfo["newEnterpriseName"])) {
  149. $whr = [];
  150. $whr[] = ["name", "like", "%{$params["newEnterpriseName"]}%"];
  151. $ids = \app\common\model\Enterprise::where($whr)->column("id");
  152. $where[] = ["newEnterpriseId", "in", $ids];
  153. }
  154. if ($twcInfo["checkState"] != null) {
  155. $where[] = ["checkState", "=", $talentQuitInfo["checkState"]];
  156. }
  157. return $where;
  158. }
  159. }