HouseValidator.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. }