TalentBankChange.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\common\AdminController;
  4. use app\common\model\TalentBankChange 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 TalentBankChange
  12. *
  13. * @author sgq
  14. */
  15. class TalentBankChange 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->setTalentBank($params);
  25. $where[] = ["type", "=", $this->user["type"]];
  26. //获取字典表人才层次
  27. $levelMap = DictApi::selectByParentCode("talent_arrange");
  28. $typeMap = DictApi::selectByParentCode("enterprise_tag");
  29. $count = TbcModel::where($where)->count();
  30. $list = TbcModel::where($where)->limit($offset, $limit)->order("createTime {$order}")->select()->toArray();
  31. foreach ($list as $key => $item) {
  32. $list[$key]["talentArrangeName"] = $levelMap[$item["talentArrange"]];
  33. $list[$key]["talentTypeName"] = $typeMap[$item["talentType"]];
  34. }
  35. return json(["rows" => $list, "total" => $count]);
  36. }
  37. public function check() {
  38. $id = $this->request["id"];
  39. $info = TbcModel::where("id", $id)->find();
  40. $info["talentArrangeName"] = DictApi::selectByParentCode("talent_arrange")[$info["talentArrange"]];
  41. if (\StrUtil::isNotEmpAndNull($info["talentType"])) {
  42. $info["talentTypeName"] = DictApi::selectByParentCode("enterprise_tag")[$info["talentType"]];
  43. }
  44. return view("check", ["type" => $this->user["type"], "row" => $info]);
  45. }
  46. public function submitToCheck() {
  47. $responseObj = new \stdClass();
  48. $responseObj->code = 500;
  49. $id = $this->request["id"];
  50. $checkState = $this->request["checkState"];
  51. $checkMsg = $this->request["checkMsg"];
  52. $info = TbcModel::where("id", $id)->find();
  53. if (!$info) {
  54. $responseObj->msg = "系统错误,请联系管理员";
  55. return $responseObj;
  56. }
  57. if (!$checkState) {
  58. $responseObj->msg = "请选择审核状态";
  59. return $responseObj;
  60. }
  61. Db::startTrans();
  62. try {
  63. //添加日志
  64. $user = $this->user;
  65. $log["id"] = getStringId();
  66. $log["active"] = 1;
  67. $log["state"] = $checkState;
  68. $log["step"] = 11;
  69. $log["stateChange"] = MainState::getStateName($info["checkState"]) . "->" . MainState::getStateName($checkState);
  70. $log["type"] = ProjectState::BANKCHANGE;
  71. $log["mainId"] = $id;
  72. $log["description"] = $checkMsg;
  73. $log["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  74. $log["createTime"] = date("Y-m-d H:i:s");
  75. $updTalentQuit["id"] = $id;
  76. $updTalentQuit["checkState"] = $checkState;
  77. $updTalentQuit["checkMsg"] = $checkMsg;
  78. if ($checkState == 3) {
  79. //修改人才库信息
  80. $upd["id"] = $info["talentId"];
  81. $upd["active"] = 2;
  82. $upd["cur_quit_time"] = $info["quitTime"];
  83. Db::table("new_talent_info")->save($upd);
  84. $talentLog["id"] = getStringId();
  85. $talentLog["active"] = 1;
  86. $talentLog["step"] = 22;
  87. $talentLog["type"] = ProjectState::TALENT;
  88. $talentLog["mainId"] = $info["talentId"];
  89. $talentLog["description"] = "离职变更通过,同步到人才库";
  90. $talentLog["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  91. $talentLog["createTime"] = date("Y-m-d H:i:s");
  92. Db::table("new_talent_checklog")->insert($talentLog);
  93. $updTalentQuit["passTime"] = date("Y-m-d H:i:s");
  94. }
  95. Db::table("new_talent_checklog")->insert($log);
  96. Db::table("un_talent_quit")->save($updTalentQuit);
  97. $responseObj->code = 200;
  98. $responseObj->msg = "审核成功";
  99. Db::commit();
  100. return $responseObj;
  101. } catch (\think\db\exception\DbException $e) {
  102. $responseObj->msg = $e->getMessage();
  103. Db::rollback();
  104. return $responseObj;
  105. }
  106. }
  107. private function setTalentBank($data) {
  108. $where = [];
  109. if (\StrUtil::isNotEmpAndNull($data["talentName"])) {
  110. $where[] = ["talentName", "=", $data["talentName"]];
  111. }
  112. if (\StrUtil::isNotEmpAndNull($data["idCard"])) {
  113. $where[] = ["idCard", "=", $data["IdCard"]];
  114. }
  115. if (\StrUtil::isNotEmpAndNull($data["enterpriseName"])) {
  116. $where[] = ["enterpriseName", "=", $data["enterpriseName"]];
  117. }
  118. if (\StrUtil::isNotEmpAndNull($data["talentArrange"])) {
  119. $where[] = ["talentArrange", "=", $data["talentArrange"]];
  120. }
  121. if ($data["checkState"] != null) {
  122. $where[] = ["checkState", "=", $data["checkState"]];
  123. }
  124. return $where;
  125. }
  126. }