TeacherModel.class.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace Admin\Model;
  3. use Think\Model;
  4. /**
  5. * 教师模型
  6. * @author Devil
  7. * @blog http://gong.gg/
  8. * @version 0.0.1
  9. * @datetime 2016-12-01T21:51:08+0800
  10. */
  11. class TeacherModel extends CommonModel
  12. {
  13. // 数据自动校验
  14. protected $_validate = array(
  15. // 添加,编辑
  16. array('username', 'CheckUserName', '{%teacher_username_format}', 1, 'callback', 3),
  17. array('id_card', 'CheckIdCard', '{%common_view_id_card_format}', 1, 'callback', 3),
  18. array('gender', array(0,1,2), '{%common_gender_tips}', 1, 'in', 3),
  19. array('birthday', 'CheckBirthday', '{%teacher_birthday_format}', 2, 'callback', 3),
  20. array('state', array(0,1,2,3,4), '{%common_teacher_state_tips}', 1, 'in', 3),
  21. array('mobile', 'CheckMobile', '{%common_mobile_format_error}', 1, 'callback', 3),
  22. array('tel', 'CheckTel', '{%common_view_tel_error}', 2, 'callback', 3),
  23. array('email', 'CheckEmail', '{%common_email_format_error}', 2, 'callback', 3),
  24. // 添加
  25. array('id_card', 'UniqueIdCard', '{%common_is_exist_id_card_tips}', 1, 'callback', 1),
  26. // 编辑
  27. array('id_card', 'NoExistIdCard', '{%common_no_exist_id_card_tips}', 1, 'callback', 2),
  28. );
  29. /**
  30. * [UniqueIdCard 身份证必须唯一]
  31. * @author Devil
  32. * @blog http://gong.gg/
  33. * @version 0.0.1
  34. * @datetime 2016-12-29T17:12:27+0800
  35. * @return [boolean] [存在false, 不存在true]
  36. */
  37. public function UniqueIdCard()
  38. {
  39. $id = $this->db(0)->where(array('id_card'=>I('id_card')))->getField('id');
  40. return empty($id);
  41. }
  42. /**
  43. * [CheckUserName 姓名校验]
  44. * @author Devil
  45. * @blog http://gong.gg/
  46. * @version 0.0.1
  47. * @datetime 2016-12-13T19:29:30+0800
  48. */
  49. public function CheckUserName()
  50. {
  51. $len = Utf8Strlen(I('username'));
  52. return ($len >= 2 && $len <= 16);
  53. }
  54. /**
  55. * [CheckIdCard 身份证号码校验]
  56. * @author Devil
  57. * @blog http://gong.gg/
  58. * @version 0.0.1
  59. * @datetime 2016-12-13T15:12:32+0800
  60. */
  61. public function CheckIdCard()
  62. {
  63. return (preg_match('/'.L('common_regex_id_card').'/', I('id_card')) == 1) ? true : false;
  64. }
  65. /**
  66. * [CheckBirthday 生日校验]
  67. * @author Devil
  68. * @blog http://gong.gg/
  69. * @version 0.0.1
  70. * @datetime 2016-12-13T15:12:32+0800
  71. */
  72. public function CheckBirthday()
  73. {
  74. return (preg_match('/'.L('common_regex_birthday').'/', I('birthday')) == 1) ? true : false;
  75. }
  76. /**
  77. * [CheckMobile 手机号码校验]
  78. * @author Devil
  79. * @blog http://gong.gg/
  80. * @version 0.0.1
  81. * @datetime 2016-12-13T15:12:32+0800
  82. */
  83. public function CheckMobile()
  84. {
  85. return (preg_match('/'.L('common_regex_mobile').'/', I('mobile')) == 1) ? true : false;
  86. }
  87. /**
  88. * [CheckTel 联系方式校验]
  89. * @author Devil
  90. * @blog http://gong.gg/
  91. * @version 0.0.1
  92. * @datetime 2016-12-13T15:12:32+0800
  93. */
  94. public function CheckTel()
  95. {
  96. return (preg_match('/'.L('common_regex_tel').'/', I('tel')) == 1) ? true : false;
  97. }
  98. /**
  99. * [CheckEmail 电子邮箱校验]
  100. * @author Devil
  101. * @blog http://gong.gg/
  102. * @version 0.0.1
  103. * @datetime 2016-12-13T15:12:32+0800
  104. */
  105. public function CheckEmail()
  106. {
  107. return (preg_match('/'.L('common_regex_email').'/', I('email')) == 1) ? true : false;
  108. }
  109. /**
  110. * [NoExistIdCard 身份证号码是否存在]
  111. * @author Devil
  112. * @blog http://gong.gg/
  113. * @version 0.0.1
  114. * @datetime 2016-12-10T14:09:40+0800
  115. * @return [boolean] [存在true, 不存在false]
  116. */
  117. public function NoExistIdCard()
  118. {
  119. $id = $this->db(0)->where(array('id_card'=>I('id_card')))->getField('id');
  120. return !empty($id);
  121. }
  122. }
  123. ?>