AttendanceGroup.php 926 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class AttendanceGroup extends Validate{
  6. protected $rule = [
  7. 'name|名称' => 'require|checkUnique',
  8. // 'class_ids|班次' => 'require',
  9. 'type|类型' => 'require|in:1,2',
  10. ];
  11. protected $message = [
  12. // 'class_ids.require' => '未选择班次',
  13. 'type.in' => '未选择类型',
  14. ];
  15. protected $scene = [
  16. ];
  17. protected function checkUnique($value,$rule,$data=[])
  18. {
  19. $info = Db::name('attendance_group')
  20. ->where('name',$value)
  21. ->where('org_id',$data['org_id'])
  22. ->where('del',0)
  23. ->find();
  24. if($data['id'] <= 0 && $info){
  25. return '名称已被使用';
  26. }
  27. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  28. return '名称已被使用';
  29. }
  30. return true;
  31. }
  32. }