TalentBasicChange.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <?php
  2. namespace app\enterprise\controller;
  3. use app\common\api\TalentState;
  4. use app\enterprise\api\TalentApi;
  5. use app\enterprise\common\EnterpriseController;
  6. use app\common\model\TalentBasicChange as TbcModel;
  7. use app\common\api\TalentLogApi;
  8. use app\common\state\ProjectState;
  9. use app\common\model\TalentLog;
  10. use app\enterprise\model\Talent;
  11. use think\facade\Db;
  12. use app\common\api\EnterpriseApi;
  13. /**
  14. * Description of TalentBasicChange
  15. *
  16. * @author sgq
  17. */
  18. class TalentBasicChange extends EnterpriseController {
  19. public function index() {
  20. return view("", ["type" => $this->user["type"]]);
  21. }
  22. public function list() {
  23. $type = $this->user["type"];
  24. $params = \StrUtil::batchGetRequestDecodeParam($this->request);
  25. $order = $params["order"] ?: "desc";
  26. $offset = $params["offset"] ?: 0;
  27. $limit = $params["limit"] ?: 10;
  28. $where = [];
  29. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  30. $where[] = ["delete", "=", 0];
  31. if ($params["oldName"]) {
  32. $where[] = ["oldName", "like", "%" . $params["oldName"] . "%"];
  33. }
  34. if ($params["oldCardType"]) {
  35. $where[] = ["oldCardType", "=", $params["oldCardType"]];
  36. }
  37. if ($params["oldIdCard"]) {
  38. $where[] = ["oldIdCard", "like", "%" . $params["oldIdCard"] . "%"];
  39. }
  40. if ($params["newName"]) {
  41. $where[] = ["newName", "like", "%" . $params["newName"] . "%"];
  42. }
  43. if ($params["newCardType"]) {
  44. $where[] = ["newCardType", "=", $params["newCardType"]];
  45. }
  46. if ($params["newIdCard"]) {
  47. $where[] = ["newIdCard", "like", "%" . $params["newIdCard"] . "%"];
  48. }
  49. if ($params["checkState"]) {
  50. $where[] = ["checkState", "=", $params["checkState"]];
  51. }
  52. $count = TbcModel::where($where)->count();
  53. $list = TbcModel::where($where)->limit($offset, $limit)->order("createTime " . $order)->select()->toArray();
  54. $nationalityMap = \app\common\api\DictApi::selectByParentCode("nationality");
  55. $nationMap = \app\common\api\DictApi::selectByParentCode("nation");
  56. $politicalMap = \app\common\api\DictApi::selectByParentCode("politics");
  57. $cardTypeMap = \app\common\api\DictApi::selectByParentCode("card_type");
  58. foreach ($list as &$item) {
  59. $item["oldNationalityName"] = $nationalityMap[$item["oldNationality"]];
  60. $item["oldNationName"] = $nationMap[$item["oldNation"]];
  61. $item["oldPoliticsName"] = $politicalMap[$item["oldPolitics"]];
  62. $item["oldCardTypName"] = $cardTypeMap[$item["oldCardType"]];
  63. $item["newNationalityName"] = $nationalityMap[$item["newNationality"]];
  64. $item["newNationName"] = $nationMap[$item["newNation"]];
  65. $item["newPoliticsName"] = $politicalMap[$item["newPolitics"]];
  66. $item["newCardTypName"] = $cardTypeMap[$item["newCardType"]];
  67. }unset($item);
  68. return json(["total" => $count, "rows" => $list]);
  69. }
  70. public function apply() {
  71. $request = $this->request;
  72. $id = isset($request["id"]) ? $request["id"] : 0;
  73. $talent_id = isset($request["talent_id"]) ? $request["talent_id"] : 0;
  74. $info = TbcModel::where("id", $id)->find();
  75. if ($this->request->isPost()) {
  76. $response = new \stdClass();
  77. $response->code = 500;
  78. $data = $request->param();
  79. $check = $this->dataCheck($data);
  80. if ($check->code == 500) {
  81. return $check;
  82. }
  83. $talentInfo = \app\common\api\VerifyApi::getTalentInfoById($request["talentId"]);
  84. if ($data["id"]) {
  85. unset($data["year"]);
  86. $data["updateUser"] = $this->user["uid"];
  87. $data["updateTime"] = date("Y-m-d H:i:s");
  88. TbcModel::update($data);
  89. $response->code = 200;
  90. $response->msg = "修改成功";
  91. return $response;
  92. } else {
  93. $where = [];
  94. $where[] = ["checkState", "<>", 3];
  95. $where[] = ["oldIdCard", "=", $talentInfo["card_number"]];
  96. $exist = TbcModel::where($where)->find();
  97. if ($exist) {
  98. $response->code = 500;
  99. $response->msg = "已经存在变更记录,不能重复添加";
  100. return $response;
  101. }
  102. $data["id"] = getStringId();
  103. $data["oldName"] = $talentInfo["name"];
  104. $data["oldNationality"] = $talentInfo["nationality"];
  105. $data["oldNation"] = $talentInfo["nation"];
  106. $data["oldPolitics"] = $talentInfo["politics"];
  107. $data["oldCardType"] = $talentInfo["card_type"];
  108. $data["oldIdCard"] = $talentInfo["card_number"];
  109. $data["oldBirthday"] = $talentInfo["birthday"];
  110. $data["oldEmail"] = $talentInfo["email"];
  111. $data["oldContractTime"] = $talentInfo["labor_contract_rangetime"];
  112. $data["checkState"] = -1;
  113. $data["createUser"] = $this->user["uid"];
  114. $data["createTime"] = date("Y-m-d H:i:s");
  115. TbcModel::create($data);
  116. $user = $this->user;
  117. $log["id"] = getStringId();
  118. $log["active"] = 1;
  119. $log["state"] = 1;
  120. $log["step"] = 0;
  121. $log["stateChange"] = "";
  122. $log["type"] = ProjectState::BASICCHANGE;
  123. $log["mainId"] = $data["id"];
  124. $log["description"] = "添加人才基础信息变更申请";
  125. $log["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  126. $log["createTime"] = date("Y-m-d H:i:s");
  127. TalentLog::create($log);
  128. $response->code = 200;
  129. $response->msg = "添加成功";
  130. $response->obj = $data;
  131. return $response;
  132. }
  133. }
  134. $assigns = [];
  135. if (!$info) {
  136. $info["enterpriseId"] = $this->user["uid"];
  137. $info["type"] = $this->user["type"];
  138. $where = [];
  139. $where[] = ["checkState", "<>", 3];
  140. $changes = TbcModel::where($where)->select()->column("talentId");
  141. unset($where);
  142. $where[] = ["enterprise_id", "=", $this->user["uid"]];
  143. $where[] = ["id", "not in", $changes];
  144. $where[] = ["checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  145. $list = \app\enterprise\model\Talent::where($where)->field("id,name,card_number,talent_arrange")->select()->toArray();
  146. $checkList = [];
  147. foreach ($list as $item) {
  148. if ($checkList[$item["card_number"]]) {
  149. if ($item["talent_arrange"] < $checkList[$item["card_number"]]["talent_arrange"]) {
  150. $checkList[$item["card_number"]] = $item;
  151. }
  152. } else {
  153. $checkList[$item["card_number"]] = $item;
  154. }
  155. }
  156. sort($checkList);
  157. $assigns["list"] = $checkList;
  158. }
  159. $assigns["type"] = $this->user["type"];
  160. $assigns["row"] = $info;
  161. $assigns['talent_id'] = $talent_id;
  162. return view("", $assigns);
  163. }
  164. public function view() {
  165. $request = $this->request;
  166. $id = isset($request["id"]) ? $request["id"] : 0;
  167. $info = TbcModel::where("id", $id)->find();
  168. return view("apply", ["row" => $info]);
  169. }
  170. public function submitToCheck() {
  171. $response = new \stdClass();
  172. $response->code = 500;
  173. $id = $this->request["id"];
  174. $info = TbcModel::where("id", $id)->find();
  175. if (!$info) {
  176. $response->msg = "提交审核失败,请先填写基础信息";
  177. return $response;
  178. }
  179. if ($info["checkState"] != -1 && $info["checkState"] != 2) {
  180. $response->msg = "不能重复提交审核";
  181. return $response;
  182. }
  183. $check = $this->dataCheck($info);
  184. if ($check->code == 500) {
  185. return $check;
  186. }
  187. $where = [];
  188. $where[] = ["type", "=", $info["type"]];
  189. $where[] = ["project", "=", ProjectState::BASICCHANGE];
  190. $where[] = ["active", "=", 1];
  191. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  192. $sb = [];
  193. $sb[] = "以下为必传附件:";
  194. foreach ($filetypes as $filetype) {
  195. if ($filetype["must"] == 1) {
  196. $where = [];
  197. $where[] = ["mainId", "=", $id];
  198. $where[] = ["typeId", "=", $filetype["id"]];
  199. $count = Db::table("new_talent_file")->where($where)->count();
  200. if ($count == 0) {
  201. $sb[] = $filetype["name"] . ";";
  202. }
  203. }
  204. }
  205. if (count($sb) > 1) {
  206. $response->msg = implode("<br>", $sb);
  207. return $response;
  208. }
  209. $data["id"] = $id;
  210. if (\StrUtil::isEmpOrNull($info["firstSubmitTime"])) {
  211. $data["firstSubmitTime"] = date("Y-m-d H:i:s");
  212. }
  213. $data["newSubmitTime"] = date("Y-m-d H:i:s");
  214. $data["checkMsg"] = "";
  215. $data["checkState"] = $info["checkState"] == 2 ? 9 : 1;
  216. TbcModel::update($data);
  217. $sb = [];
  218. if ($info["checkState"] == -1) {
  219. $sb[] = \app\common\state\MainState::getStateName(-2);
  220. } else {
  221. $sb[] = \app\common\state\MainState::getStateName(2);
  222. }
  223. if ($data["checkState"] == 1) {
  224. $sb[] = \app\common\state\MainState::getStateName(1);
  225. } else {
  226. $sb[] = \app\common\state\MainState::getStateName(9);
  227. }
  228. $user = $this->user;
  229. $log["id"] = getStringId();
  230. $log["active"] = 1;
  231. $log["state"] = 1;
  232. $log["step"] = 0;
  233. $log["stateChange"] = implode("->", $sb);
  234. $log["type"] = ProjectState::BASICCHANGE;
  235. $log["mainId"] = $id;
  236. $log["description"] = "确认提交审核";
  237. $log["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  238. $log["createTime"] = date("Y-m-d H:i:s");
  239. TalentLog::create($log);
  240. $response->code = 200;
  241. $response->msg = "提交审核成功";
  242. $response->obj = 1;
  243. return $response;
  244. }
  245. public function delete() {
  246. $response = new \stdClass();
  247. $response->code = 500;
  248. $info = TbcModel::where("id", $this->request["id"])->find();
  249. if ($info["checkState"] != -1) {
  250. $response->msg = "已提交审核,无法删除";
  251. return $response;
  252. }
  253. $data["id"] = $info["id"];
  254. $data["delete"] = 1;
  255. $data["deleteTime"] = date("Y-m-d H:i:s");
  256. TbcModel::update($data);
  257. $response->code = 200;
  258. $response->msg = "删除成功";
  259. return $response;
  260. }
  261. private function dataCheck($data) {
  262. $response = new \stdClass();
  263. $response->code = 500;
  264. if (\StrUtil::isEmpOrNull($data["newName"])) {
  265. $response->msg = "现姓名不能为空";
  266. return $response;
  267. }
  268. if (\StrUtil::isEmpOrNull($data["newNationality"])) {
  269. $response->msg = "现国籍不能为空";
  270. return $response;
  271. }
  272. if (\StrUtil::isEmpOrNull($data["newNation"])) {
  273. $response->msg = "现民族不能为空";
  274. return $response;
  275. }
  276. if (\StrUtil::isEmpOrNull($data["newBirthday"])) {
  277. $response->msg = "现出生日期不能为空";
  278. return $response;
  279. }
  280. if (\StrUtil::isEmpOrNull($data["newPolitics"])) {
  281. $response->msg = "现政治面貌不能为空";
  282. return $response;
  283. }
  284. if (\StrUtil::isEmpOrNull($data["newCardType"])) {
  285. $response->msg = "现证件类型不能为空";
  286. return $response;
  287. }
  288. if (\StrUtil::isEmpOrNull($data["newIdCard"])) {
  289. $response->msg = "现证件号码不能为空";
  290. return $response;
  291. }
  292. if (\StrUtil::isEmpOrNull($data["newEmail"])) {
  293. $response->msg = "现电子邮箱不能为空";
  294. return $response;
  295. }
  296. if (\StrUtil::isEmpOrNull($data["newContractStartTime"])) {
  297. $response->msg = "现劳动合同开始时间不能为空";
  298. return $response;
  299. }
  300. if (\StrUtil::isEmpOrNull($data["newContractEndTime"])) {
  301. $response->msg = "现劳动合同结束时间不能为空";
  302. return $response;
  303. }
  304. if (!preg_match("/[\\w!#$%&'*+\/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+\/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?/", $data["newEmail"])) {
  305. $response->msg = "电子邮箱格式不正确";
  306. return $response;
  307. }
  308. if ($data["newCardType"] == 1 && !\app\common\api\IdCardApi::isValid($data["newIdCard"])) {
  309. $response->msg = "身份证号码不合法";
  310. return $response;
  311. }
  312. if ($data["newCardType"] == 2 && !preg_match("/^[a-zA-Z0-9]{6,10}$/", $data["newIdCard"]) && !preg_match("/^([0-9]{8}|[0-9]{10})$/", $data["newIdCard"])) {
  313. $response->msg = "通行证号码不合法";
  314. return $response;
  315. }
  316. if ($data["newCardType"] == 3 && !preg_match("/^([a-zA-z]|[0-9]){5,17}$/", $data["newIdCard"])) {
  317. $response->msg = "护照格式不合法";
  318. return $response;
  319. }
  320. //list($startTime, $endTime) = explode(" - ", $data["newContractTime"]);
  321. $startTime = $data["newContractStartTime"];
  322. $endTime = $data["newContractEndTime"];
  323. if (!strtotime($startTime) || !strtotime($endTime) || strtotime($startTime) > strtotime($endTime)) {
  324. $response->msg = "劳动合同起止时间不合法";
  325. return $response;
  326. }
  327. $response->code = 200;
  328. return $response;
  329. }
  330. public function htindex() {
  331. return view("", ["type" => $this->user["type"]]);
  332. }
  333. public function htEndList() {
  334. $offset = trim($this->request->param("offset")) ?: 0;
  335. $limit = trim($this->request->param("limit")) ?: 10;
  336. $name = trim($this->request->param("name"));
  337. $idCard = trim($this->request->param("card_number"));
  338. $where = [];
  339. $where[] = ["ti.delete", "=", 0];
  340. $where[] = ["ti.active", "=", 1];
  341. $where[] = ["ti.checkState", "=", TalentState::CERTIFICATED];
  342. if (session("user")["usertype"] == 2) {
  343. $where[] = ["ti.enterprise_id", "=", session("user")["uid"]];
  344. }
  345. if ($name) {
  346. $where[] = ["ti.name", "like", "%" . $name . "%"];
  347. }
  348. if ($idCard) {
  349. $where[] = ["ti.card_number", "like", "%" . $idCard . "%"];
  350. }
  351. //dump($where);die;
  352. $now = date("Y-m-d", time());
  353. //$where[] = ["trim(SUBSTRING_INDEX(ti.labor_contract_rangetime,'-',-3))", "<", $now];
  354. $count = Talent::alias("ti")->field("ti.id,ti.name,ti.card_number,ti.labor_contract_rangetime")->leftJoin("un_talent_basic_change tbc", "ti.id = tbc.talentId")->where($where)->whereRaw("trim(SUBSTRING_INDEX(ti.labor_contract_rangetime,'-',-3)) < '{$now}' and tbc.id is null")->count();
  355. $list = Talent::alias("ti")->field("ti.id,ti.name,ti.card_number,ti.labor_contract_rangetime")->leftJoin("un_talent_basic_change tbc", "ti.id = tbc.talentId")->where($where)->whereRaw("trim(SUBSTRING_INDEX(ti.labor_contract_rangetime,'-',-3)) < '{$now}' and tbc.id is null")->limit($offset, $limit)->select()->toArray();
  356. //echo Talent::getLastSql();die;
  357. return json(["total" => $count, "rows" => $list]);
  358. }
  359. public function htEndExport() {
  360. $where = [];
  361. $where[] = ["ti.delete", "=", 0];
  362. $where[] = ["ti.active", "=", 1];
  363. $where[] = ["ti.checkState", "=", TalentState::CERTIFICATED];
  364. if (session("user")["usertype"] == 2) {
  365. $where[] = ["ti.enterprise_id", "=", session("user")["uid"]];
  366. }
  367. $now = date("Y-m-d", time());
  368. $count = Talent::alias("ti")->field("ti.id,ti.name,ti.card_number,ti.labor_contract_rangetime")->leftJoin("un_talent_basic_change tbc", "ti.id = tbc.talentId")->where($where)->whereRaw("trim(SUBSTRING_INDEX(ti.labor_contract_rangetime,'-',-3)) < '{$now}' and tbc.id is null")->count();
  369. if ($count > 0) {
  370. $columns = [
  371. '姓名',
  372. '证件号码',
  373. '劳动合同时间'
  374. ];
  375. $setting = [];
  376. $setting["freeze"] = "A2";
  377. $setting["filter"] = sprintf("A1:%s1", getExcelColumnByIndex(count($columns) - 1));
  378. $lists = Talent::alias("ti")->field("ti.id,ti.name,ti.card_number,ti.labor_contract_rangetime")->leftJoin("un_talent_basic_change tbc", "ti.id = tbc.talentId")->where($where)->whereRaw("trim(SUBSTRING_INDEX(ti.labor_contract_rangetime,'-',-3)) < '{$now}' and tbc.id is null")->select()->toArray();
  379. $datas = [];
  380. foreach ($lists as $v) {
  381. $item = [
  382. $v['name'],
  383. $v['card_number'],
  384. $v['labor_contract_rangetime']
  385. ];
  386. array_push($datas, $item);
  387. }
  388. export($columns, $datas, "合同到期列表导出", $setting);
  389. } else {
  390. echo "<script>parent.layer.alert('没有可以导出的数据');window.history.go(-1);</script>";
  391. }
  392. }
  393. }