DeviceLog.php 745 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class DeviceLog extends Validate{
  6. protected $rule = [
  7. 'sn|编号' => 'require|checkUnique',
  8. 'type|类型' => 'require',
  9. ];
  10. protected $message = [
  11. ];
  12. protected $scene = [
  13. ];
  14. protected function checkUnique($value,$rule,$data=[])
  15. {
  16. $info = Db::name('device_log')
  17. ->where('sn',$value)
  18. ->where('del',0)
  19. ->where('type',$data['type'])->find();
  20. if($data['id'] <= 0 && $info){
  21. return '编号已存在';
  22. }
  23. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  24. return '编号已存在';
  25. }
  26. return true;
  27. }
  28. }