<?php
namespace app\common\validate;

use think\Db;
use think\Validate;

class DinnerUser extends Validate{

    protected $rule = [
        'name|姓名'  =>  'require|checkUnique',
    ];

    protected $message = [

    ];

    protected $scene = [

    ];

    protected function checkUnique($value,$rule,$data=[])
    {
        $info = Db::name('dinner_user')->where('name',$value)->where('org_id',$data['org_id'])->find();
        if($data['id'] <= 0 && $info){
            return '姓名已被使用';
        }
        if($info && $data['id'] > 0 && $info['id'] != $data['id']){
            return '姓名已被使用';
        }
        return true;
    }

}