UserModel.class.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 UserModel extends CommonModel
  12. {
  13. // 数据自动校验
  14. protected $_validate = array(
  15. // 添加,编辑
  16. array('nickname', 'CheckNickName', '{%user_nickname_format}', 2, 'callback', 3),
  17. array('gender', array(0,1,2), '{%common_gender_tips}', 2, 'in', 3),
  18. array('birthday', 'CheckBirthday', '{%user_birthday_format}', 2, 'callback', 3),
  19. array('signature', 'CheckSignature', '{%user_signature_format}', 2, 'callback', 3),
  20. array('describe', 'CheckDescribe', '{%user_describe_format}', 2, 'callback', 3),
  21. array('mobile', 'CheckMobile', '{%common_mobile_format_error}', 2, 'callback', 3),
  22. array('email', 'CheckEmail', '{%common_email_format_error}', 2, 'callback', 3),
  23. array('mobile', '', '{%common_mobile_exist_error}', 2, 'unique', 3),
  24. array('email', '', '{%common_email_exist_error}', 2, 'unique', 3),
  25. // 添加
  26. array('pwd', 'CheckLoginPwd', '{%user_login_pwd_format}', 1, 'function', 1),
  27. // 编辑
  28. array('pwd', 'CheckLoginPwd', '{%user_login_pwd_format}', 2, 'function', 2),
  29. );
  30. /**
  31. * [CheckNickName 昵称校验]
  32. * @author Devil
  33. * @blog http://gong.gg/
  34. * @version 0.0.1
  35. * @datetime 2016-12-13T19:29:30+0800
  36. */
  37. public function CheckNickName()
  38. {
  39. $len = Utf8Strlen(I('nickname'));
  40. return ($len <= 16);
  41. }
  42. /**
  43. * [CheckBirthday 生日校验]
  44. * @author Devil
  45. * @blog http://gong.gg/
  46. * @version 0.0.1
  47. * @datetime 2016-12-13T15:12:32+0800
  48. */
  49. public function CheckBirthday()
  50. {
  51. return (preg_match('/'.L('common_regex_birthday').'/', I('birthday')) == 1) ? true : false;
  52. }
  53. /**
  54. * [CheckSignature 个人签名校验]
  55. * @author Devil
  56. * @blog http://gong.gg/
  57. * @version 0.0.1
  58. * @datetime 2016-12-13T19:29:30+0800
  59. */
  60. public function CheckSignature()
  61. {
  62. $len = Utf8Strlen(I('signature'));
  63. return ($len <= 168);
  64. }
  65. /**
  66. * [CheckDescribe 个人描述校验]
  67. * @author Devil
  68. * @blog http://gong.gg/
  69. * @version 0.0.1
  70. * @datetime 2016-12-13T19:29:30+0800
  71. */
  72. public function CheckDescribe()
  73. {
  74. $len = Utf8Strlen(I('describe'));
  75. return ($len <= 255);
  76. }
  77. /**
  78. * [CheckMobile 手机号码校验]
  79. * @author Devil
  80. * @blog http://gong.gg/
  81. * @version 0.0.1
  82. * @datetime 2016-12-13T15:12:32+0800
  83. */
  84. public function CheckMobile()
  85. {
  86. return (preg_match('/'.L('common_regex_mobile').'/', I('mobile')) == 1) ? true : false;
  87. }
  88. /**
  89. * [CheckEmail 电子邮箱校验]
  90. * @author Devil
  91. * @blog http://gong.gg/
  92. * @version 0.0.1
  93. * @datetime 2016-12-13T15:12:32+0800
  94. */
  95. public function CheckEmail()
  96. {
  97. return (preg_match('/'.L('common_regex_email').'/', I('email')) == 1) ? true : false;
  98. }
  99. }
  100. ?>