0
0

AttendanceMachine.php 709 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class AttendanceMachine extends Validate{
  6. protected $rule = [
  7. 'sn|设备编号' => 'require|max:30|checkUnique',
  8. // 'org_id|所属项目' => 'require|gt:0',
  9. ];
  10. protected function checkUnique($value,$rule,$data=[])
  11. {
  12. $info = Db::name('attendance_machine')
  13. ->where('sn',$value)
  14. ->where('del',0)
  15. ->find();
  16. if($data['id'] <= 0 && $info){
  17. return '设备编号已被使用';
  18. }
  19. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  20. return '设备编号已被使用';
  21. }
  22. return true;
  23. }
  24. }