TalentInfo.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace app\enterprise\validate;
  3. use think\Validate;
  4. use app\common\api\TalentState;
  5. /**
  6. * Description of TalentInfo
  7. * 先不用。分两步等下通不过
  8. * @author sgq
  9. */
  10. class TalentInfo extends Validate {
  11. protected $rule = [
  12. "name" => "regex:/^[\x{4e00}-\x{9fa5}]+$/u",
  13. "nation" => "checkInSelect:nation,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57",
  14. "card_type" => "between:1,3",
  15. "card_number" => "checkCardNumber|checkUnique:new_talent_info",
  16. "sex" => "between:1,2",
  17. "politics" => "checkInSelect:politics,01,02,03,04,05,06,07,08,09,10,11,12,13,14",
  18. "birthday" => "dateFormat:Y-m-d",
  19. "nationality" => "checkInSelect:nationality,cn,cn_hk,cn_mc,cn_tw,us,en,jp,co,nl,sg,other",
  20. "talent_type" => "between:1,3",
  21. "tax_insurance_month" => "checkRangeDate:tax_insurance_month",
  22. "labor_contract_rangetime" => "checkRangeDate:labor_contract_rangetime",
  23. "fst_work_time" => "dateFormat:Y-m-d",
  24. "pre_import_type" => "between:1,2",
  25. "experience" => "max:200",
  26. "education" => "max:200",
  27. "phone" => "mobile|checkUnique:new_talent_info",
  28. "email" => "email|checkUnique:new_talent_info",
  29. "highest_degree" => "checkInSelect:highest_degree,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21",
  30. "study_abroad" => "between:1,2",
  31. "import_way" => "between:1,3",
  32. "cur_entry_time" => "dateFormat:Y-m-d",
  33. "source" => "between:1,5",
  34. "fujian_highcert_pubtime" => "dateFormat:Y-m-d",
  35. "fujian_highcert_exptime" => "dateFormat:Y-m-d",
  36. "quanzhou_highcert_pubtime" => "dateFormat:Y-m-d",
  37. "quanzhou_highcert_exptime" => "dateFormat:Y-m-d",
  38. "talent_arrange" => "between:1,7",
  39. "bank" => "regex:/^[\x{4e00}-\x{9fa5}]+银行$/u",
  40. "bank_number" => "regex:/^\d+$/",
  41. "bank_branch_name" => "regex:/^[\x{4e00}-\x{9fa5}]+银行[\x{4e00}-\x{9fa5}]+省?[\x{4e00}-\x{9fa5}]+市[\x{4e00}-\x{9fa5}]+$/u",
  42. "bank_account" => "regex:/^\d+$/",
  43. ];
  44. protected $message = [
  45. "name.regex" => "姓名只能是中文",
  46. "card_type.between" => "不存在的证件类型,请在列表中选择",
  47. "card_number.checkUnique" => "身份证已经存在",
  48. "sex.between" => "性别只能在预设列表中选择",
  49. "politics.between" => "政治面貌只能在预设列表中选择",
  50. "birthday.dateFormat" => "生日必需是有效日期格式[yyyy-MM-dd]",
  51. "talent_type.between" => "不存在的人才类型,请在列表中选择",
  52. "fst_work_time.dateFormat" => "来晋工作时间必需是有效的日期格式[yyyy-MM-dd]",
  53. "pre_import_type.between" => "预引进类型只能在预设列表中选择",
  54. "experience.max" => "工作经历不能超过200个字符,请简明扼要的描述您的工作经历",
  55. "education.max" => "教育背景不能超过200个字符,请简明扼要的描述您的教育背景",
  56. "phone.mobile" => "请填写正确的手机号",
  57. "phone.checkUnique" => "手机号已经存在",
  58. "email.email" => "电子邮箱格式错误",
  59. "email.checkUnique" => "电子邮箱已经存在",
  60. "highest_degree.between" => "最高学历只能在预设列表中选择",
  61. "study_abroad.between" => "留学经历只能选择是与否",
  62. "import_way.between" => "不存在的引进方式,请在列表中选择",
  63. "cur_entry_time.dateFormat" => "本单位入职时间必需是有效的日期格式[yyyy-MM-dd]",
  64. "source.between" => "不存在的申报来源,请在列表中选择",
  65. "fujian_highcert_pubtime.dateFormat" => "福建省高层次人才证书发证日期必需是有效的日期格式[yyyy-MM-dd]",
  66. "fujian_highcert_exptime.dateFormat" => "福建省高层次人才证书有效期必需是有效的日期格式[yyyy-MM-dd]",
  67. "quanzhou_highcert_pubtime.dateFormat" => "泉州高层次人才证书发证日期必需是有效的日期格式[yyyy-MM-dd]",
  68. "quanzhou_highcert_exptime.dateFormat" => "泉州高层次人才证书有效期必需是有效的日期格式[yyyy-MM-dd]",
  69. "talent_arrange" => "不存在的人才层次,请在列表中选择",
  70. "bank.regex" => "开户银行格式应为[XX银行]",
  71. "bank_number.regex" => "银行行号只能是数字",
  72. "bank_branch_name.regex" => "开户银行网点格式应为[XX银行XX省XX市XX行/处]",
  73. "bank_account.regex" => "银行账号只能是数字",
  74. ];
  75. protected function checkUnique($value, $rule, $data = [], $field) {
  76. $db = $this->db->name($rule);
  77. $pk = $db->getPk();
  78. $map = [];
  79. $map[] = [$field, "=", $data[$field]];
  80. $map[] = ["checkState", "not in", [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL, TalentState::ZX_FAIL, TalentState::ANNOUNCED_REVERIFY_FAIL, TalentState::PUBLISH_FAIL]];
  81. if ($data[$pk]) {
  82. $map[] = [$pk, "<>", $data[$pk]];
  83. }
  84. if ($db->where($map)->field($pk)->find()) {
  85. return false;
  86. }
  87. return true;
  88. }
  89. protected function checkInSelect($value, $rule, $data = []) {
  90. $title = "";
  91. $select = explode(",", $rule);
  92. $type = array_shift($select);
  93. switch ($type) {
  94. case "nation":
  95. $title = "民族";
  96. break;
  97. case "politics":
  98. $title = "政治面貌";
  99. break;
  100. case "nationality":
  101. $title = "国籍/地区";
  102. break;
  103. case "highest_degree":
  104. $title = "最高学历";
  105. break;
  106. }
  107. return in_array($value, $select) ?: "{$title}只能在预设列表中选择";
  108. }
  109. protected function checkCardNumber($value, $rule, $data = []) {
  110. if (!$data["card_type"]) {
  111. return "填写证件号码前请先选择证件类型";
  112. }
  113. if ($data["card_type"] == 1) {
  114. $num = strlen($value);
  115. switch ($num) {
  116. case 15:
  117. case 18:
  118. return \app\common\api\IdCardApi::isValid($value) ?: "身份证号码不合法";
  119. break;
  120. default:
  121. //return \app\common\api\IdCardApi::isValidExceptMainland($value) ?: "身份证号码不合法";
  122. break;
  123. }
  124. }
  125. return "身份证号码不合法";
  126. }
  127. protected function checkRangeDate($value, $rule, $data = []) {
  128. $title = "";
  129. $format = "[yyyy-MM-dd - yyyy-MM-dd]";
  130. $str = "日期";
  131. switch ($rule) {
  132. case "tax_insurance_month":
  133. $format = "[yyyy-MM - yyyy-MM]";
  134. $str = "月份";
  135. if ($data["talent_type"] == 1) {
  136. $title = "缴交社会保险或个人所得税月份";
  137. }
  138. if ($data["talent_type"] == 2) {
  139. $title = "首次在我市缴交社会保险或个人所得税月份";
  140. }
  141. break;
  142. case "labor_contract_rangetime":
  143. $title = "劳动合同起止时间";
  144. break;
  145. }
  146. $arr = explode(" - ", $value);
  147. $chk1 = strtotime($arr[0]);
  148. $chk2 = strtotime($arr[1]);
  149. if (!$chk1 || !$chk2)
  150. return "{$title}日期范围格式应为{$format}";
  151. if ($chk1 > $chk2)
  152. return "{$title}起始{$str}不能大于结束{$str}";
  153. return true;
  154. }
  155. }