123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace app\enterprise\validate;
- use think\Validate;
- /**
- * Description of HouseValidator
- * @author sgq
- */
- class HouseValidator extends Validate {
- protected $rule = [
- "type" => "require",
- "name" => "require",
- "cardType" => "require",
- "idCard" => "require|checkCardNumber",
- "declareObject" => "require",
- "declareType" => "require|checkDeclareType",
- "phone" => "require|mobile",
- "marryStatus" => "require"
- ];
- protected $message = [
- "type.require" => "人才类别不能为空",
- "name.require" => "姓名不能为空",
- "cardType.require" => "证件类型不能为空",
- "idCard.require" => "证件号码不能为空",
- "declareObject.require" => "申报对象不能为空",
- "declareType.require" => "申报类型不能为空",
- "phone.require" => "手机号码不能为空",
- "phone.mobile" => "手机号格式不正确",
- "marryStatus.require" => "婚姻状态不能为空"
- ];
- protected function checkCardNumber($value, $rule, $data = []) {
- if (!$data["cardType"]) {
- return "填写证件号码前请先选择证件类型";
- }
- if ($data["cardType"] == 1) {
- $num = strlen($value);
- switch ($num) {
- case 15:
- case 18:
- return \app\common\api\IdCardApi::isValid($value) ?: "身份证号码不合法";
- break;
- default:
- //return \app\common\api\IdCardApi::isValidExceptMainland($value) ?: "身份证号码不合法";
- break;
- }
- return "身份证号码不合法";
- } else if ($data["cardType"] == 2) {
- if (preg_match("/^[a-zA-Z0-9]{6,10}$/", $value) || preg_match("/^([0-9]{8}|[0-9]{10})$/", $value)) {
- return true;
- }
- return "通行证号码不合法";
- } else {
- if (preg_match("/^([a-zA-z]|[0-9]){5,17}$/", $value)) {
- return true;
- }
- return "护照号码不合法";
- }
- }
- protected function checkDeclareType($value, $rule, $data = []) {
- if ($value == 1) {
- if (\StrUtil::isEmpOrNull($data["houseAddress"])) {
- return "房屋坐落地址不能为空";
- }
- if (!$data["houseArea"]) {
- return "房屋建筑面积不能为空";
- }
- if (\StrUtil::isEmpOrNull($data["recordTime"])) {
- return "商品房购房合同备案时间不能为空";
- }
- if (!$data["houseMoney"]) {
- return "房屋成交金额不能为空";
- }
- if (!$data["isEnjoyOther"]) {
- return "是否享受我市其他政策不能为空";
- }
- if (\StrUtil::isEmpOrNull($data["realEstateNo"]) && \StrUtil::isEmpOrNull($data["recordNo"])) {
- return "不动产权证编号和备案合同编号至少填写一个";
- }
- if (\StrUtil::isNotEmpAndNull($data["realEstateNo"]) && !preg_match("/^闽(\\(|()[0-9]{4}(\\)|))晋江市不动产权第(\\(|()[0-9]+(\\)|))号$/", $data["realEstateNo"])) {
- return "不动产权证编号格式不正确";
- }
- if (\StrUtil::isNotEmpAndNull($data["recordNo"]) && !preg_match("/^\\d{12}$/", $data["recordNo"])) {
- return "备案合同编号格式不正确";
- }
- }
- return true;
- }
- protected function checkRangeDate($value, $rule, $data = []) {
- $title = "";
- $format = "[yyyy-MM-dd - yyyy-MM-dd]";
- $str = "日期";
- switch ($rule) {
- case "tax_insurance_month":
- $format = "[yyyy-MM - yyyy-MM]";
- $str = "月份";
- if ($data["talent_type"] == 1) {
- $title = "缴交社会保险或个人所得税月份";
- }
- if ($data["talent_type"] == 2) {
- $title = "首次在我市缴交社会保险或个人所得税月份";
- }
- break;
- case "labor_contract_rangetime":
- $title = "劳动合同起止时间";
- break;
- case "salary_pay_month":
- $format = "[yyyy-MM - yyyy-MM]";
- $str = "月份";
- $title = "工资发放月份";
- break;
- }
- $arr = explode(" - ", $value);
- $chk1 = strtotime($arr[0]);
- $chk2 = strtotime($arr[1]);
- if (!$chk1 || !$chk2)
- return "{$title}日期范围格式应为{$format}";
- if ($chk1 > $chk2)
- return "{$title}起始{$str}不能大于结束{$str}";
- return true;
- }
- }
|