LivingAllowance.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace app\enterprise\validate;
  3. use think\Validate;
  4. /**
  5. * Description of LivingAllowance
  6. * @author sgq
  7. */
  8. class LivingAllowance extends Validate {
  9. protected $rule = [
  10. "type" => "require",
  11. "idCard" => "require|checkCardNumber",
  12. "cardType" => "require",
  13. "name" => "require",
  14. "sex" => "require",
  15. "nation" => "require",
  16. "nationality" => "require",
  17. "provinceCode" => "require",
  18. "cityCode" => "require",
  19. "birthday" => "require",
  20. "address" => "require",
  21. "politics" => "require",
  22. "highEducation" => "require",
  23. "major" => "require",
  24. "post" => "require|regex:/^[\x{4e00}-\x{9fa5}]+$/u",
  25. "phone" => "require|mobile",
  26. "email" => "require|email",
  27. "bank" => "require|regex:/^[\x{4e00}-\x{9fa5}]*银行$/u",
  28. "bankNetwork" => "require|regex:/^[\x{4e00}-\x{9fa5}]*银行[\x{4e00}-\x{9fa5}]*省?[\x{4e00}-\x{9fa5}]+市[\x{4e00}-\x{9fa5}]*$/u",
  29. "bankAccount" => "require|regex:/^\d+$/",
  30. "entryTime" => "require",
  31. "startTime" => "require",
  32. "endTime" => "require",
  33. "mainHonours" => "require",
  34. "educationAndResume" => "require",
  35. "bankNumber" => "require|regex:/^\d+$/",
  36. "introductionMethod" => "require|checkInJJTime",
  37. "industryFieldNew" => "checkIndustryFieldNew",
  38. "industryField" => "checkIndustryField",
  39. "socialSecurity" => "require"
  40. ];
  41. protected $message = [
  42. "type.require" => "人才类别不能为空",
  43. "idCard.require" => "证件号码不能为空",
  44. "cardType.require" => "证件类型不能为空",
  45. "name.require" => "姓名不能为空",
  46. "sex.require" => "性别不能为空",
  47. "nation.require" => "民族不能为空",
  48. "nationality.require" => "国籍/地区不能为空",
  49. "provinceCode.require" => "籍贯-省不能为空",
  50. "cityCode.require" => "籍贯-市不能为空",
  51. "birthday.require" => "出生日期不能为空",
  52. "address.require" => "现居地址不能为空",
  53. "politics.require" => "政治面貌不能为空",
  54. "highEducation.require" => "最高学历不能为空",
  55. "major.require" => "专业不能为空",
  56. "post.require" => "职务不能为空",
  57. "post.regex" => "职务必须为汉字",
  58. "phone.require" => "手机号码不能为空",
  59. "phone.mobile" => "手机号格式不正确",
  60. "email.require" => "电子邮箱不能为空",
  61. "email.email" => "电子邮箱格式不正确",
  62. "bank.require" => "开户银行不能为空",
  63. "bank.regex" => "开户银行格式不正确",
  64. "bankNetwork.require" => "开户银行网点不能为空",
  65. "bankNetwor.regex" => "开户银行网点格式不正确",
  66. "bankAccount.require" => "银行账号不能为空",
  67. "bacnkAccount.regex" => "银行账户格式不合法",
  68. "entryTime.require" => "入职时间不能为空",
  69. "startTime.require" => "工作合同开始时间不能为空",
  70. "endTime.require" => "工作合同结束时间不能为空",
  71. "mainHonours.require" => "主要业绩及取得的荣誉不能为空",
  72. "educationAndResume.require" => "教育背景及工作简历不能为空",
  73. "bankNumber.require" => "银行行号不能为空",
  74. "bankNumber.regex" => "银行行号格式不合法",
  75. "introductionMethod.require" => "引进方式不能为空",
  76. "socialSecurity.require" => "社保缴交情况不能为空"
  77. ];
  78. protected function checkCardNumber($value, $rule, $data = []) {
  79. if (!$data["cardType"]) {
  80. return "填写证件号码前请先选择证件类型";
  81. }
  82. if ($data["cardType"] == 1) {
  83. $num = strlen($value);
  84. switch ($num) {
  85. case 15:
  86. case 18:
  87. return \app\common\api\IdCardApi::isValid($value) ?: "身份证号码不合法";
  88. break;
  89. default:
  90. //return \app\common\api\IdCardApi::isValidExceptMainland($value) ?: "身份证号码不合法";
  91. break;
  92. }
  93. return "身份证号码不合法";
  94. } else if ($data["cardType"] == 2) {
  95. if (preg_match("/^[a-zA-Z0-9]{6,10}$/", $value) || preg_match("/^([0-9]{8}|[0-9]{10})$/", $value)) {
  96. return true;
  97. }
  98. return "通行证号码不合法";
  99. } else {
  100. if (preg_match("/^([a-zA-z]|[0-9]){5,17}$/", $value)) {
  101. return true;
  102. }
  103. return "护照号码不合法";
  104. }
  105. }
  106. protected function checkInJJTime($value, $rule, $data = []) {
  107. if ($value == 1 && !$data["firstInJJTime"]) {
  108. return "首次来晋时间不能为空";
  109. }
  110. if ($value == 2 && !$data["backJJBusinessTime"]) {
  111. return "返晋创业时间不能为空";
  112. }
  113. return true;
  114. }
  115. protected function checkIndustryFieldNew($value, $rule, $data = []) {
  116. if ($data["type"] == 1 && !$value) {
  117. return "产业领域不能为空";
  118. }
  119. return true;
  120. }
  121. protected function checkIndustryField($value, $rule, $data = []) {
  122. if ($data["type"] == 1 && !$value) {
  123. return "行业领域不能为空";
  124. }
  125. return true;
  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. case "salary_pay_month":
  146. $format = "[yyyy-MM - yyyy-MM]";
  147. $str = "月份";
  148. $title = "工资发放月份";
  149. break;
  150. }
  151. $arr = explode(" - ", $value);
  152. $chk1 = strtotime($arr[0]);
  153. $chk2 = strtotime($arr[1]);
  154. if (!$chk1 || !$chk2)
  155. return "{$title}日期范围格式应为{$format}";
  156. if ($chk1 > $chk2)
  157. return "{$title}起始{$str}不能大于结束{$str}";
  158. return true;
  159. }
  160. }