TalentBasicChange.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. namespace app\enterprise\controller;
  3. use app\enterprise\common\EnterpriseController;
  4. use app\common\model\TalentBasicChange as TbcModel;
  5. use app\common\api\TalentLogApi;
  6. use app\common\state\ProjectState;
  7. use app\common\model\TalentLog;
  8. use think\facade\Db;
  9. use app\common\api\EnterpriseApi;
  10. /**
  11. * Description of TalentBasicChange
  12. *
  13. * @author sgq
  14. */
  15. class TalentBasicChange extends EnterpriseController {
  16. public function index() {
  17. return view("", ["type" => $this->user["type"]]);
  18. }
  19. public function list() {
  20. $type = $this->user["type"];
  21. $params = \StrUtil::batchGetRequestDecodeParam($this->request);
  22. $order = $params["order"] ?: "desc";
  23. $offset = $params["offset"] ?: 0;
  24. $limit = $params["limit"] ?: 10;
  25. $where = [];
  26. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  27. $where[] = ["delete", "=", 0];
  28. if ($params["oldName"]) {
  29. $where[] = ["oldName", "like", "%" . $params["oldName"] . "%"];
  30. }
  31. if ($params["oldCardType"]) {
  32. $where[] = ["oldCardType", "=", $params["oldCardType"]];
  33. }
  34. if ($params["oldIdCard"]) {
  35. $where[] = ["oldIdCard", "like", "%" . $params["oldIdCard"] . "%"];
  36. }
  37. if ($params["newName"]) {
  38. $where[] = ["newName", "like", "%" . $params["newName"] . "%"];
  39. }
  40. if ($params["newCardType"]) {
  41. $where[] = ["newCardType", "=", $params["newCardType"]];
  42. }
  43. if ($params["newIdCard"]) {
  44. $where[] = ["newIdCard", "like", "%" . $params["newIdCard"] . "%"];
  45. }
  46. if ($params["checkState"]) {
  47. $where[] = ["checkState", "=", $params["checkState"]];
  48. }
  49. $count = TbcModel::where($where)->count();
  50. $list = TbcModel::where($where)->limit($offset, $limit)->order("createTime " . $order)->select()->toArray();
  51. $nationalityMap = \app\common\api\DictApi::selectByParentCode("nationality");
  52. $nationMap = \app\common\api\DictApi::selectByParentCode("nation");
  53. $politicalMap = \app\common\api\DictApi::selectByParentCode("politics");
  54. $cardTypeMap = \app\common\api\DictApi::selectByParentCode("card_type");
  55. foreach ($list as &$item) {
  56. $item["oldNationalityName"] = $nationalityMap[$item["oldNationality"]];
  57. $item["oldNationName"] = $nationMap[$item["oldNation"]];
  58. $item["oldPoliticsName"] = $politicalMap[$item["oldPolitics"]];
  59. $item["oldCardTypName"] = $cardTypeMap[$item["oldCardType"]];
  60. $item["newNationalityName"] = $nationalityMap[$item["newNationality"]];
  61. $item["newNationName"] = $nationMap[$item["newNation"]];
  62. $item["newPoliticsName"] = $politicalMap[$item["newPolitics"]];
  63. $item["newCardTypName"] = $cardTypeMap[$item["newCardType"]];
  64. }unset($item);
  65. return json(["total" => $count, "rows" => $list]);
  66. }
  67. public function apply() {
  68. $request = $this->request;
  69. $id = isset($request["id"]) ? $request["id"] : 0;
  70. $info = TbcModel::where("id", $id)->find();
  71. if ($this->request->isPost()) {
  72. $response = new \stdClass();
  73. $response->code = 500;
  74. $data = $request->param();
  75. $check = $this->dataCheck($data);
  76. if ($check->code == 500) {
  77. return $check;
  78. }
  79. $talentInfo = \app\common\api\VerifyApi::getTalentInfoById($request["talentId"]);
  80. if ($data["id"]) {
  81. unset($data["year"]);
  82. $data["updateUser"] = $this->user["uid"];
  83. $data["updateTime"] = date("Y-m-d H:i:s");
  84. TbcModel::update($data);
  85. $response->code = 200;
  86. $response->msg = "修改成功";
  87. return $response;
  88. } else {
  89. $data["id"] = getStringId();
  90. $data["oldName"] = $talentInfo["name"];
  91. $data["oldNationality"] = $talentInfo["nationality"];
  92. $data["oldNation"] = $talentInfo["nation"];
  93. $data["oldPolitics"] = $talentInfo["politics"];
  94. $data["oldCardType"] = $talentInfo["card_type"];
  95. $data["oldIdCard"] = $talentInfo["card_number"];
  96. $data["oldBirthday"] = $talentInfo["birthday"];
  97. $data["oldEmail"] = $talentInfo["email"];
  98. $data["oldContractTime"] = $talentInfo["labor_contract_rangetime"];
  99. $data["checkState"] = -1;
  100. $data["createUser"] = $this->user["uid"];
  101. $data["createTime"] = date("Y-m-d H:i:s");
  102. TbcModel::create($data);
  103. $user = $this->user;
  104. $log["id"] = getStringId();
  105. $log["active"] = 1;
  106. $log["state"] = 1;
  107. $log["step"] = 0;
  108. $log["stateChange"] = "";
  109. $log["type"] = ProjectState::BASICCHANGE;
  110. $log["mainId"] = $data["id"];
  111. $log["description"] = "添加人才基础信息变更申请";
  112. $log["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  113. $log["createTime"] = date("Y-m-d H:i:s");
  114. TalentLog::create($log);
  115. $response->code = 200;
  116. $response->msg = "添加成功";
  117. $response->obj = $data;
  118. return $response;
  119. }
  120. }
  121. $assigns = [];
  122. if (!$info) {
  123. $info["enterpriseId"] = $this->user["uid"];
  124. $info["type"] = $this->user["type"];
  125. $where = [];
  126. $where[] = ["checkState", "<>", 3];
  127. $changes = TbcModel::where($where)->select()->column("talentId");
  128. unset($where);
  129. $where[] = ["enterprise_id", "=", $this->user["uid"]];
  130. $where[] = ["id", "not in", $changes];
  131. $where[] = ["checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  132. $list = \app\enterprise\model\Talent::where($where)->field("id,name")->select()->toArray();
  133. $assigns["list"] = $list;
  134. }
  135. $assigns["type"] = $this->user["type"];
  136. $assigns["row"] = $info;
  137. return view("", $assigns);
  138. }
  139. public function view() {
  140. $request = $this->request;
  141. $id = isset($request["id"]) ? $request["id"] : 0;
  142. $info = TbcModel::where("id", $id)->find();
  143. return view("apply", ["row" => $info]);
  144. }
  145. public function submitToCheck() {
  146. $response = new \stdClass();
  147. $response->code = 500;
  148. $id = $this->request["id"];
  149. $info = TbcModel::where("id", $id)->find();
  150. if (!$info) {
  151. $response->msg = "提交审核失败,请先填写基础信息";
  152. return $response;
  153. }
  154. if ($info["checkState"] != -1 && $info["checkState"] != 2) {
  155. $response->msg = "不能重复提交审核";
  156. return $response;
  157. }
  158. $check = $this->dataCheck($info);
  159. if ($check->code == 500) {
  160. return $check;
  161. }
  162. $where = [];
  163. $where[] = ["type", "=", $info["type"]];
  164. $where[] = ["project", "=", ProjectState::BASICCHANGE];
  165. $where[] = ["active", "=", 1];
  166. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  167. $sb = [];
  168. $sb[] = "以下为必传附件:";
  169. foreach ($filetypes as $filetype) {
  170. if ($filetype["must"] == 1) {
  171. $where = [];
  172. $where[] = ["mainId", "=", $id];
  173. $where[] = ["typeId", "=", $filetype["id"]];
  174. $count = Db::table("new_talent_file")->where($where)->count();
  175. if ($count == 0) {
  176. $sb[] = $filetype["name"] . ";";
  177. }
  178. }
  179. }
  180. if (count($sb) > 1) {
  181. $response->msg = implode("<br>", $sb);
  182. return $response;
  183. }
  184. $data["id"] = $id;
  185. if (\StrUtil::isEmpOrNull($info["firstSubmitTime"])) {
  186. $data["firstSubmitTime"] = date("Y-m-d H:i:s");
  187. }
  188. $data["newSubmitTime"] = date("Y-m-d H:i:s");
  189. $data["checkMsg"] = "";
  190. $data["checkState"] = $info["checkState"] == 2 ? 9 : 1;
  191. TbcModel::update($data);
  192. $sb = [];
  193. if ($info["checkState"] == -1) {
  194. $sb[] = \app\common\state\MainState::getStateName(-2);
  195. } else {
  196. $sb[] = \app\common\state\MainState::getStateName(2);
  197. }
  198. if ($data["checkState"] == 1) {
  199. $sb[] = \app\common\state\MainState::getStateName(1);
  200. } else {
  201. $sb[] = \app\common\state\MainState::getStateName(9);
  202. }
  203. $user = $this->user;
  204. $log["id"] = getStringId();
  205. $log["active"] = 1;
  206. $log["state"] = 1;
  207. $log["step"] = 0;
  208. $log["stateChange"] = implode("->", $sb);
  209. $log["type"] = ProjectState::BASICCHANGE;
  210. $log["mainId"] = $id;
  211. $log["description"] = "确认提交审核";
  212. $log["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  213. $log["createTime"] = date("Y-m-d H:i:s");
  214. TalentLog::create($log);
  215. $response->code = 200;
  216. $response->msg = "提交审核成功";
  217. $response->obj = 1;
  218. return $response;
  219. }
  220. public function delete() {
  221. $response = new \stdClass();
  222. $response->code = 500;
  223. $info = TbcModel::where("id", $this->request["id"])->find();
  224. if ($info["checkState"] != -1) {
  225. $response->msg = "已提交审核,无法删除";
  226. return $response;
  227. }
  228. $data["id"] = $info["id"];
  229. $data["delete"] = 1;
  230. $data["deleteTime"] = date("Y-m-d H:i:s");
  231. TbcModel::update($data);
  232. $response->code = 200;
  233. $response->msg = "删除成功";
  234. return $response;
  235. }
  236. private function dataCheck($data) {
  237. $response = new \stdClass();
  238. $response->code = 500;
  239. if (\StrUtil::isEmpOrNull($data["newName"])) {
  240. $response->msg = "现姓名不能为空";
  241. return $response;
  242. }
  243. if (\StrUtil::isEmpOrNull($data["newNationality"])) {
  244. $response->msg = "现国籍不能为空";
  245. return $response;
  246. }
  247. if (\StrUtil::isEmpOrNull($data["newNation"])) {
  248. $response->msg = "现民族不能为空";
  249. return $response;
  250. }
  251. if (\StrUtil::isEmpOrNull($data["newBirthday"])) {
  252. $response->msg = "现出生日期不能为空";
  253. return $response;
  254. }
  255. if (\StrUtil::isEmpOrNull($data["newPolitics"])) {
  256. $response->msg = "现政治面貌不能为空";
  257. return $response;
  258. }
  259. if (\StrUtil::isEmpOrNull($data["newCardType"])) {
  260. $response->msg = "现证件类型不能为空";
  261. return $response;
  262. }
  263. if (\StrUtil::isEmpOrNull($data["newIdCard"])) {
  264. $response->msg = "现证件号码不能为空";
  265. return $response;
  266. }
  267. if (\StrUtil::isEmpOrNull($data["newEmail"])) {
  268. $response->msg = "现电子邮箱不能为空";
  269. return $response;
  270. }
  271. if (\StrUtil::isEmpOrNull($data["newContractTime"])) {
  272. $response->msg = "现劳动合同起止时间不能为空";
  273. return $response;
  274. }
  275. if (!preg_match("/[\\w!#$%&'*+\/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+\/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?/", $data["newEmail"])) {
  276. $response->msg = "电子邮箱格式不正确";
  277. return $response;
  278. }
  279. if ($data["newCardType"] == 1 && !\app\common\api\IdCardApi::isValid($data["newIdCard"])) {
  280. $response->msg = "身份证号码不合法";
  281. return $response;
  282. }
  283. if ($data["newCardType"] == 2 && !preg_match("/^[a-zA-Z0-9]{6,10}$/", $data["newIdCard"]) && !preg_match("/^([0-9]{8}|[0-9]{10})$/", $data["newIdCard"])) {
  284. $response->msg = "通行证号码不合法";
  285. return $response;
  286. }
  287. if ($data["newCardType"] == 3 && !preg_match("/^([a-zA-z]|[0-9]){5,17}$/", $data["newIdCard"])) {
  288. $response->msg = "护照格式不合法";
  289. return $response;
  290. }
  291. list($startTime, $endTime) = explode(" - ", $data["newContractTime"]);
  292. if (!strtotime($startTime) || !strtotime($endTime) || strtotime($startTime) > strtotime($endTime)) {
  293. $response->msg = "劳动合同起止时间不合法";
  294. return $response;
  295. }
  296. $response->code = 200;
  297. return $response;
  298. }
  299. }