EducationSchoolValidator.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\person\validate;
  3. use think\Validate;
  4. use app\common\model\EducationSchool;
  5. /**
  6. * Description of EducationSchoolValidator
  7. * @author sgq
  8. */
  9. class EducationSchoolValidator extends Validate {
  10. protected $rule = [
  11. "enterpriseName" => "require",
  12. "enterpriseAddress" => "require",
  13. "address" => "require",
  14. "phone" => "require|mobile",
  15. "cName" => "require",
  16. "cSex" => "require",
  17. "cIdcard" => "require|checkIdCard",
  18. "cBirthday" => "require",
  19. "cRelation" => "require",
  20. "nowSchool" => "require",
  21. "nowGrade" => "require",
  22. "project" => "require|checkApplySchool",
  23. "companyStreet" => "require",
  24. "houseStreet" => "require",
  25. "year" => "require|checkExistThisYear",
  26. "personId" => "require",
  27. "talentId" => "require"
  28. ];
  29. protected $message = [
  30. "enterpriseName.require" => "工作单位不能为空",
  31. "enterpriseAddress.require" => "工作单位详细地址不能为空",
  32. "address.require" => "现居地址不能为空",
  33. "phone.require" => "联系电话不能为空",
  34. "phone.mobile" => "联系电话格式不合法",
  35. "cName.require" => "子女姓名不能为空",
  36. "cSex.require" => "子女性别不能为空",
  37. "cIdcard.require" => "子女证件号码不能为空",
  38. "cBirthday.require" => "子女出生日期不能为空",
  39. "cRelation.require" => "与申报人关系不能为空",
  40. "nowSchool.require" => "现就读学校不能为空",
  41. "nowGrade.require" => "现就读年级不能为空",
  42. "project.require" => "申报项目不能为空",
  43. "companyStreet.require" => "工作单位所属镇街不能为空",
  44. "houseStreet.require" => "房产所在镇街不能为空",
  45. "year.require" => "批次不能为空",
  46. "personId.require" => "申报人信息不能为空",
  47. "talentId.require" => "申报人人才申报信息不能为空",
  48. ];
  49. protected function checkExistThisYear($value, $rule, $data = []) {
  50. $where[] = ["year", "=", $value];
  51. $where[] = ["personId", "=", $data["personId"]];
  52. $where[] = ["cIdcard", "=", $data["cIdcard"]];
  53. if ($data["id"]) {
  54. $where[] = ["id", "<>", $data["id"]];
  55. }
  56. $count = EducationSchool::where($where)->count();
  57. if ($count > 0) {
  58. return "该子女当年度已有申报记录,添加失败";
  59. }
  60. return true;
  61. }
  62. protected function checkApplySchool($value, $rule, $data = []) {
  63. if ($value == 1 && \StrUtil::isEmpOrNull($data["applySchool"])) {
  64. return "拟申请学校不能为空";
  65. }
  66. return true;
  67. }
  68. protected function checkIdCard($value, $rule, $data = []) {
  69. if (!\app\common\api\IdCardApi::isValid($value) && !preg_match("/^([a-zA-z]|[0-9]){5,17}$/", $value) && !preg_match("/^[a-zA-Z0-9]{6,10}$/", $value) && !preg_match("/^([0-9]{8}|[0-9]{10})$/", $value))
  70. return "子女证件号码不合法!";
  71. return true;
  72. }
  73. }