HouseValidator.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. "declareType" => "require|checkDeclareType",
  15. "phone" => "require|mobile",
  16. "marryStatus" => "require"
  17. ];
  18. protected $message = [
  19. "type.require" => "人才类别不能为空",
  20. "name.require" => "姓名不能为空",
  21. "cardType.require" => "证件类型不能为空",
  22. "idCard.require" => "证件号码不能为空",
  23. "declareType.require" => "申报类型不能为空",
  24. "phone.require" => "手机号码不能为空",
  25. "phone.mobile" => "手机号格式不正确",
  26. "marryStatus.require" => "婚姻状态不能为空"
  27. ];
  28. protected function checkCardNumber($value, $rule, $data = []) {
  29. if (!$data["cardType"]) {
  30. return "填写证件号码前请先选择证件类型";
  31. }
  32. if ($data["cardType"] == 1) {
  33. $num = strlen($value);
  34. switch ($num) {
  35. case 15:
  36. case 18:
  37. return \app\common\api\IdCardApi::isValid($value) ?: "身份证号码不合法";
  38. break;
  39. default:
  40. //return \app\common\api\IdCardApi::isValidExceptMainland($value) ?: "身份证号码不合法";
  41. break;
  42. }
  43. return "身份证号码不合法";
  44. } else if ($data["cardType"] == 2) {
  45. if (preg_match("/^[a-zA-Z0-9]{6,10}$/", $value) || preg_match("/^([0-9]{8}|[0-9]{10})$/", $value)) {
  46. return true;
  47. }
  48. return "通行证号码不合法";
  49. } else {
  50. if (preg_match("/^([a-zA-z]|[0-9]){5,17}$/", $value)) {
  51. return true;
  52. }
  53. return "护照号码不合法";
  54. }
  55. }
  56. protected function checkDeclareType($value, $rule, $data = []) {
  57. if ($value == 1) {
  58. if (\StrUtil::isEmpOrNull($data["houseAddress"])) {
  59. return "房屋坐落地址不能为空";
  60. }
  61. if (!$data["houseArea"]) {
  62. return "房屋建筑面积不能为空";
  63. }
  64. if (\StrUtil::isEmpOrNull($data["recordTime"])) {
  65. return "商品房购房合同备案时间不能为空";
  66. }
  67. if (!$data["houseMoney"]) {
  68. return "房屋成交金额不能为空";
  69. }
  70. if (!$data["isEnjoyOther"]) {
  71. return "是否享受我市其他政策不能为空";
  72. }
  73. if (\StrUtil::isEmpOrNull($data["realEstateNo"]) && \StrUtil::isEmpOrNull($data["recordNo"])) {
  74. return "不动产权证编号和备案合同编号至少填写一个";
  75. }
  76. if (\StrUtil::isNotEmpAndNull($data["realEstateNo"]) && !preg_match("/^闽(\\(|()[0-9]{4}(\\)|))晋江市不动产权第(\\(|()[0-9]+(\\)|))号$/", $data["realEstateNo"])) {
  77. return "不动产权证编号格式不正确";
  78. }
  79. if (\StrUtil::isNotEmpAndNull($data["recordNo"]) && !preg_match("/^\\d{12}$/", $data["recordNo"])) {
  80. return "备案合同编号格式不正确";
  81. }
  82. }
  83. return true;
  84. }
  85. }