DinnerUser.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class DinnerUser extends Validate{
  6. protected $rule = [
  7. 'phone|手机号' => 'require|checkUnique',
  8. 'name|姓名' => 'require',
  9. 'password|密码' => 'require|length:6,16',
  10. 'company_id|单位' => 'require|gt:0',
  11. 'oldPass|旧密码' => 'require',
  12. 'pass|新密码' => 'require|length:6,16',
  13. ];
  14. protected $message = [
  15. ];
  16. protected $scene = [
  17. 'add' => ['phone','name','password','company_id'],
  18. 'edit' => ['phone','name','password|密码'=>'length:6,16','company_id'],
  19. 'modifyPass' => ['oldPass','pass']
  20. ];
  21. protected function checkUnique($value,$rule,$data=[])
  22. {
  23. $info = Db::name('dinner_user')
  24. ->where('phone',$data['phone'])
  25. ->where('del',0)
  26. ->find();
  27. if($data['id'] <= 0 && $info){
  28. return '手机号已被使用';
  29. }
  30. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  31. return '手机号已被使用';
  32. }
  33. return true;
  34. }
  35. }