TalentQuit.php 5.6 KB

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