TalentBasicChange.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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["checkState"] = -1;
  99. $data["createUser"] = $this->user["uid"];
  100. $data["createTime"] = date("Y-m-d H:i:s");
  101. TbcModel::create($data);
  102. $user = $this->user;
  103. $log["id"] = getStringId();
  104. $log["active"] = 1;
  105. $log["state"] = 1;
  106. $log["step"] = 0;
  107. $log["stateChange"] = "";
  108. $log["type"] = ProjectState::BASICCHANGE;
  109. $log["mainId"] = $data["id"];
  110. $log["description"] = "添加人才基础信息变更申请";
  111. $log["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  112. $log["createTime"] = date("Y-m-d H:i:s");
  113. TalentLog::create($log);
  114. $response->code = 200;
  115. $response->msg = "添加成功";
  116. $response->obj = $data;
  117. return $response;
  118. }
  119. }
  120. $assigns = [];
  121. if (!$info) {
  122. $info["enterpriseId"] = $this->user["uid"];
  123. $info["type"] = $this->user["type"];
  124. $where = [];
  125. $where[] = ["checkState", "<>", 3];
  126. $changes = TbcModel::where($where)->select()->column("talentId");
  127. unset($where);
  128. $where[] = ["enterprise_id", "=", $this->user["uid"]];
  129. $where[] = ["id", "not in", $changes];
  130. $where[] = ["checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  131. $list = \app\enterprise\model\Talent::where($where)->field("id,name")->select()->toArray();
  132. $assigns["list"] = $list;
  133. }
  134. $assigns["type"] = $this->user["type"];
  135. $assigns["row"] = $info;
  136. return view("", $assigns);
  137. }
  138. public function view() {
  139. $request = $this->request;
  140. $id = isset($request["id"]) ? $request["id"] : 0;
  141. $info = TbcModel::where("id", $id)->find();
  142. return view("apply", ["row" => $info]);
  143. }
  144. public function submitToCheck() {
  145. $response = new \stdClass();
  146. $response->code = 500;
  147. $id = $this->request["id"];
  148. $info = TbcModel::where("id", $id)->find();
  149. if (!$info) {
  150. $response->msg = "提交审核失败,请先填写基础信息";
  151. return $response;
  152. }
  153. if ($info["checkState"] != -1 && $info["checkState"] != 2) {
  154. $response->msg = "不能重复提交审核";
  155. return $response;
  156. }
  157. $check = $this->dataCheck($info);
  158. if ($check->code == 500) {
  159. return $check;
  160. }
  161. $where = [];
  162. $where[] = ["type", "=", $info["type"]];
  163. $where[] = ["project", "=", ProjectState::BASICCHANGE];
  164. $where[] = ["active", "=", 1];
  165. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  166. $sb = [];
  167. $sb[] = "以下为必传附件:";
  168. foreach ($filetypes as $filetype) {
  169. if ($filetype["must"] == 1) {
  170. $where = [];
  171. $where[] = ["mainId", "=", $id];
  172. $where[] = ["typeId", "=", $filetype["id"]];
  173. $count = Db::table("new_talent_file")->where($where)->count();
  174. if ($count == 0) {
  175. $sb[] = $filetype["name"] . ";";
  176. }
  177. }
  178. }
  179. if (count($sb) > 1) {
  180. $response->msg = implode("<br>", $sb);
  181. return $response;
  182. }
  183. $data["id"] = $id;
  184. if (\StrUtil::isEmpOrNull($info["firstSubmitTime"])) {
  185. $data["firstSubmitTime"] = date("Y-m-d H:i:s");
  186. }
  187. $data["newSubmitTime"] = date("Y-m-d H:i:s");
  188. $data["checkMsg"] = "";
  189. $data["checkState"] = $info["checkState"] == 2 ? 9 : 1;
  190. TbcModel::update($data);
  191. $sb = [];
  192. if ($info["checkState"] == -1) {
  193. $sb[] = \app\common\state\MainState::getStateName(-2);
  194. } else {
  195. $sb[] = \app\common\state\MainState::getStateName(2);
  196. }
  197. if ($data["checkState"] == 1) {
  198. $sb[] = \app\common\state\MainState::getStateName(1);
  199. } else {
  200. $sb[] = \app\common\state\MainState::getStateName(9);
  201. }
  202. $user = $this->user;
  203. $log["id"] = getStringId();
  204. $log["active"] = 1;
  205. $log["state"] = 1;
  206. $log["step"] = 0;
  207. $log["stateChange"] = implode("->", $sb);
  208. $log["type"] = ProjectState::BASICCHANGE;
  209. $log["mainId"] = $id;
  210. $log["description"] = "确认提交审核";
  211. $log["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  212. $log["createTime"] = date("Y-m-d H:i:s");
  213. TalentLog::create($log);
  214. $response->code = 200;
  215. $response->msg = "提交审核成功";
  216. $response->obj = 1;
  217. return $response;
  218. }
  219. public function delete() {
  220. $response = new \stdClass();
  221. $response->code = 500;
  222. $info = TbcModel::where("id", $this->request["id"])->find();
  223. if ($info["checkState"] != -1) {
  224. $response->msg = "已提交审核,无法删除";
  225. return $response;
  226. }
  227. $data["id"] = $info["id"];
  228. $data["delete"] = 1;
  229. $data["deleteTime"] = date("Y-m-d H:i:s");
  230. TbcModel::update($data);
  231. $response->code = 200;
  232. $response->msg = "删除成功";
  233. return $response;
  234. }
  235. private function dataCheck($data) {
  236. $response = new \stdClass();
  237. $response->code = 500;
  238. if (\StrUtil::isEmpOrNull($data["newName"])) {
  239. $response->msg = "现姓名不能为空";
  240. return $response;
  241. }
  242. if (\StrUtil::isEmpOrNull($data["newNationality"])) {
  243. $response->msg = "现国籍不能为空";
  244. return $response;
  245. }
  246. if (\StrUtil::isEmpOrNull($data["newNation"])) {
  247. $response->msg = "现民族不能为空";
  248. return $response;
  249. }
  250. if (\StrUtil::isEmpOrNull($data["newBirthday"])) {
  251. $response->msg = "现出生日期不能为空";
  252. return $response;
  253. }
  254. if (\StrUtil::isEmpOrNull($data["newPolitics"])) {
  255. $response->msg = "现政治面貌不能为空";
  256. return $response;
  257. }
  258. if (\StrUtil::isEmpOrNull($data["newCardType"])) {
  259. $response->msg = "现证件类型不能为空";
  260. return $response;
  261. }
  262. if (\StrUtil::isEmpOrNull($data["newIdCard"])) {
  263. $response->msg = "现证件号码不能为空";
  264. return $response;
  265. }
  266. if (\StrUtil::isEmpOrNull($data["newEmail"])) {
  267. $response->msg = "现电子邮箱不能为空";
  268. return $response;
  269. }
  270. if (!preg_match("/[\\w!#$%&'*+\/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+\/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?/", $data["newEmail"])) {
  271. $response->msg = "电子邮箱格式不正确";
  272. return $response;
  273. }
  274. if ($data["newCardType"] == 1 && !\app\common\api\IdCardApi::isValid($data["newIdCard"])) {
  275. $response->msg = "身份证号码不合法";
  276. return $response;
  277. }
  278. if ($data["newCardType"] == 2 && !preg_match("/^[a-zA-Z0-9]{6,10}$/", $data["newIdCard"]) && !preg_match("/^([0-9]{8}|[0-9]{10})$/", $data["newIdCard"])) {
  279. $response->msg = "通行证号码不合法";
  280. return $response;
  281. }
  282. if ($data["newCardType"] == 3 && !preg_match("/^([a-zA-z]|[0-9]){5,17}$/", $data["newIdCard"])) {
  283. $response->msg = "护照格式不合法";
  284. return $response;
  285. }
  286. $response->code = 200;
  287. return $response;
  288. }
  289. }