Car.php 712 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class Car extends Validate{
  6. protected $rule = [
  7. 'title|名称' => 'require',
  8. 'sn|车牌号' => 'require|checkUnique',
  9. ];
  10. protected $message = [
  11. ];
  12. protected $scene = [
  13. ];
  14. protected function checkUnique($value,$rule,$data=[])
  15. {
  16. $info = Db::name('car')->where('sn',$value)->where('del',0)->where('org_id',$data['org_id'])->find();
  17. if($data['id'] <= 0 && $info){
  18. return '车牌号已被使用';
  19. }
  20. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  21. return '车牌号已被使用';
  22. }
  23. return true;
  24. }
  25. }