TalentBasicChange.php 18 KB

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