12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class StampDuty extends Validate{
- protected $rule = [
- 'title|名称' => 'require|length:1,100|checkUnique',
- 'type|类型' => 'require|in:0,1,2',
- ];
- protected $message = [
- 'title.length' => '名称必须100字以内',
- 'type.require' => '未选择类型',
- 'type.in' => '类型错误'
- ];
- protected $scene = [
- ];
- // 自定义验证规则
- protected function checkUnique($value,$rule,$data=[])
- {
- $info = Db::name('stamp_duty')->where('title',$value)->where('org_id',$data['org_id'])->where('del',0)->find();
- if($data['id'] <= 0 && $info){
- return '名称已被使用';
- }
- if($info && $data['id'] > 0 && $info['id'] != $data['id']){
- return '名称已被使用';
- }
- return true;
- }
- }
|