Security.php 769 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class Security extends Validate{
  6. protected $rule = [
  7. 'title|名称' => 'require|length:1,40',
  8. 'sn|设备编号' => 'require|checkUnique',
  9. // 'img' => 'require',
  10. ];
  11. protected $message = [
  12. // 'img.require' => '请上传图片',
  13. ];
  14. public function checkUnique($value, $rule, $data=[]){
  15. if(isset($data['id']) && $data['id'] > 0){
  16. $ret = Db::name('security')->where('sn',$data['sn'])->where('id','<>',$data['id'])->where('del',0)->find();
  17. }else{
  18. $ret = Db::name('security')->where('sn',$data['sn'])->where('del',0)->find();
  19. }
  20. return $ret?'设备编号已被使用':true;
  21. }
  22. }