HouseValidator.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace app\enterprise\validate;
  3. use think\Validate;
  4. /**
  5. * Description of HouseValidator
  6. * @author sgq
  7. */
  8. class HouseValidator extends Validate {
  9. protected $rule = [
  10. "type" => "require",
  11. "name" => "require",
  12. "cardType" => "require",
  13. "idCard" => "require|checkCardNumber",
  14. "declareObject" => "require",
  15. "declareType" => "require|checkDeclareType",
  16. "phone" => "require|mobile",
  17. "marryStatus" => "require"
  18. ];
  19. protected $message = [
  20. "type.require" => "人才类别不能为空",
  21. "name.require" => "姓名不能为空",
  22. "cardType.require" => "证件类型不能为空",
  23. "idCard.require" => "证件号码不能为空",
  24. "declareObject.require" => "申报对象不能为空",
  25. "declareType.require" => "申报类型不能为空",
  26. "phone.require" => "手机号码不能为空",
  27. "phone.mobile" => "手机号格式不正确",
  28. "marryStatus.require" => "婚姻状态不能为空"
  29. ];
  30. protected function checkCardNumber($value, $rule, $data = []) {
  31. if (!$data["cardType"]) {
  32. return "填写证件号码前请先选择证件类型";
  33. }
  34. if ($data["cardType"] == 1) {
  35. $num = strlen($value);
  36. switch ($num) {
  37. case 15:
  38. case 18:
  39. return \app\common\api\IdCardApi::isValid($value) ?: "身份证号码不合法";
  40. break;
  41. default:
  42. //return \app\common\api\IdCardApi::isValidExceptMainland($value) ?: "身份证号码不合法";
  43. break;
  44. }
  45. return "身份证号码不合法";
  46. } else if ($data["cardType"] == 2) {
  47. if (preg_match("/^[a-zA-Z0-9]{6,10}$/", $value) || preg_match("/^([0-9]{8}|[0-9]{10})$/", $value)) {
  48. return true;
  49. }
  50. return "通行证号码不合法";
  51. } else {
  52. if (preg_match("/^([a-zA-z]|[0-9]){5,17}$/", $value)) {
  53. return true;
  54. }
  55. return "护照号码不合法";
  56. }
  57. }
  58. protected function checkDeclareType($value, $rule, $data = []) {
  59. if ($value == 1) {
  60. if (\StrUtil::isEmpOrNull($data["houseAddress"])) {
  61. return "房屋坐落地址不能为空";
  62. }
  63. if (!$data["houseArea"]) {
  64. return "房屋建筑面积不能为空";
  65. }
  66. if (\StrUtil::isEmpOrNull($data["recordTime"])) {
  67. return "商品房购房合同备案时间不能为空";
  68. }
  69. if (!$data["houseMoney"]) {
  70. return "房屋成交金额不能为空";
  71. }
  72. if (!$data["isEnjoyOther"]) {
  73. return "是否享受我市其他政策不能为空";
  74. }
  75. if (\StrUtil::isEmpOrNull($data["realEstateNo"]) && \StrUtil::isEmpOrNull($data["recordNo"])) {
  76. return "不动产权证编号和备案合同编号至少填写一个";
  77. }
  78. if (\StrUtil::isNotEmpAndNull($data["realEstateNo"]) && !preg_match("/^闽(\\(|()[0-9]{4}(\\)|))晋江市不动产权第(\\(|()[0-9]+(\\)|))号$/", $data["realEstateNo"])) {
  79. return "不动产权证编号格式不正确";
  80. }
  81. if (\StrUtil::isNotEmpAndNull($data["recordNo"]) && !preg_match("/^\\d{12}$/", $data["recordNo"])) {
  82. return "备案合同编号格式不正确";
  83. }
  84. }
  85. return true;
  86. }
  87. protected function checkRangeDate($value, $rule, $data = []) {
  88. $title = "";
  89. $format = "[yyyy-MM-dd - yyyy-MM-dd]";
  90. $str = "日期";
  91. switch ($rule) {
  92. case "tax_insurance_month":
  93. $format = "[yyyy-MM - yyyy-MM]";
  94. $str = "月份";
  95. if ($data["talent_type"] == 1) {
  96. $title = "缴交社会保险或个人所得税月份";
  97. }
  98. if ($data["talent_type"] == 2) {
  99. $title = "首次在我市缴交社会保险或个人所得税月份";
  100. }
  101. break;
  102. case "labor_contract_rangetime":
  103. $title = "劳动合同起止时间";
  104. break;
  105. case "salary_pay_month":
  106. $format = "[yyyy-MM - yyyy-MM]";
  107. $str = "月份";
  108. $title = "工资发放月份";
  109. break;
  110. }
  111. $arr = explode(" - ", $value);
  112. $chk1 = strtotime($arr[0]);
  113. $chk2 = strtotime($arr[1]);
  114. if (!$chk1 || !$chk2)
  115. return "{$title}日期范围格式应为{$format}";
  116. if ($chk1 > $chk2)
  117. return "{$title}起始{$str}不能大于结束{$str}";
  118. return true;
  119. }
  120. }