TalentBasicChange.php 17 KB

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