12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class DinnerUser extends Validate{
- protected $rule = [
- 'phone|手机号' => 'require|checkUnique',
- 'name|姓名' => 'require',
- 'password|密码' => 'require|length:6,16',
- 'company_id|单位' => 'require|gt:0',
- 'oldPass|旧密码' => 'require',
- 'pass|新密码' => 'require|length:6,16',
- ];
- protected $message = [
- ];
- protected $scene = [
- 'add' => ['phone','name','password','company_id'],
- 'edit' => ['phone','name','password|密码'=>'length:6,16','company_id'],
- 'modifyPass' => ['oldPass','pass']
- ];
- protected function checkUnique($value,$rule,$data=[])
- {
- $info = Db::name('dinner_user')
- ->where('phone',$data['phone'])
- ->where('del',0)
- ->find();
- if($data['id'] <= 0 && $info){
- return '手机号已被使用';
- }
- if($info && $data['id'] > 0 && $info['id'] != $data['id']){
- return '手机号已被使用';
- }
- return true;
- }
- }
|