1234567891011121314151617181920212223242526272829303132 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class Security extends Validate{
- protected $rule = [
- 'title|名称' => 'require|length:1,40',
- 'sn|设备编号' => 'require|checkUnique',
- // 'img' => 'require',
- ];
- protected $message = [
- // 'img.require' => '请上传图片',
- ];
- public function checkUnique($value, $rule, $data=[]){
- if(isset($data['id']) && $data['id'] > 0){
- $ret = Db::name('security')->where('sn',$data['sn'])->where('id','<>',$data['id'])->where('del',0)->find();
- }else{
- $ret = Db::name('security')->where('sn',$data['sn'])->where('del',0)->find();
- }
- return $ret?'设备编号已被使用':true;
- }
- }
|