0
0

TemperatureDevice.php 923 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class TemperatureDevice extends Validate{
  6. protected $rule = [
  7. 'snaddr|设备码' => 'require|checkUnique',
  8. 'dev_name|设备名称' => 'require|length:1,30',
  9. ];
  10. protected function checkUnique($value, $rule, $data=[]){
  11. if(isset($data['id']) && $data['id'] > 0){
  12. $ret = Db::name('temperature_device')
  13. ->where('snaddr',$data['snaddr'])
  14. ->where('org_id',$data['org_id'])
  15. ->where('del',0)
  16. ->where('id','<>',$data['id'])
  17. ->find();
  18. }else{
  19. $ret = Db::name('temperature_device')
  20. ->where('snaddr',$data['snaddr'])
  21. ->where('org_id',$data['org_id'])
  22. ->where('del',0)
  23. ->find();
  24. }
  25. return $ret?'设备码已存在':true;
  26. }
  27. }