AssetWay.php 665 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class AssetWay extends Validate{
  6. protected $rule = [
  7. 'title|名称' => 'require|checkUnique',
  8. ];
  9. protected $message = [
  10. ];
  11. protected $scene = [
  12. ];
  13. protected function checkUnique($value,$rule,$data=[])
  14. {
  15. $info = Db::name('asset_way')->where('title',$value)->where('org_id',$data['org_id'])->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. }