LivingAllowance.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 if ($data["cardType"] == 3) {
  100. if (preg_match("/^([a-zA-z]|[0-9]){5,17}$/", $value)) {
  101. return true;
  102. }
  103. return "护照号码不合法";
  104. } else if ($data["cardType"] == 4) {
  105. if (preg_match("/^[1-9]\d{5}[0-9]{3}\d{3}[0-9Xx]$/", $value)) {
  106. return true;
  107. }
  108. return "港澳居民居住证不合法";
  109. }
  110. }
  111. protected function checkInJJTime($value, $rule, $data = []) {
  112. if ($value == 1 && !$data["firstInJJTime"]) {
  113. return "首次来晋时间不能为空";
  114. }
  115. if ($value == 2 && !$data["backJJBusinessTime"]) {
  116. return "返晋创业时间不能为空";
  117. }
  118. return true;
  119. }
  120. protected function checkIndustryFieldNew($value, $rule, $data = []) {
  121. if ($data["type"] == 1 && !$value) {
  122. return "产业领域不能为空";
  123. }
  124. return true;
  125. }
  126. protected function checkIndustryField($value, $rule, $data = []) {
  127. if ($data["type"] == 1 && !$value) {
  128. return "行业领域不能为空";
  129. }
  130. return true;
  131. }
  132. protected function checkRangeDate($value, $rule, $data = []) {
  133. $title = "";
  134. $format = "[yyyy-MM-dd - yyyy-MM-dd]";
  135. $str = "日期";
  136. switch ($rule) {
  137. case "tax_insurance_month":
  138. $format = "[yyyy-MM - yyyy-MM]";
  139. $str = "月份";
  140. if ($data["talent_type"] == 1) {
  141. $title = "缴交社会保险或个人所得税月份";
  142. }
  143. if ($data["talent_type"] == 2) {
  144. $title = "首次在我市缴交社会保险或个人所得税月份";
  145. }
  146. break;
  147. case "labor_contract_rangetime":
  148. $title = "劳动合同起止时间";
  149. break;
  150. case "salary_pay_month":
  151. $format = "[yyyy-MM - yyyy-MM]";
  152. $str = "月份";
  153. $title = "工资发放月份";
  154. break;
  155. }
  156. $arr = explode(" - ", $value);
  157. $chk1 = strtotime($arr[0]);
  158. $chk2 = strtotime($arr[1]);
  159. if (!$chk1 || !$chk2)
  160. return "{$title}日期范围格式应为{$format}";
  161. if ($chk1 > $chk2)
  162. return "{$title}起始{$str}不能大于结束{$str}";
  163. return true;
  164. }
  165. }