123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class BudgetItems extends Validate{
- protected $rule = [
- 'title|名称' => 'require|checkUnique',
- // 'budget_id' => 'require|gt:0',
- 'company_id' => 'require|gt:0',
- ];
- protected $message = [
- // 'budget_id.require' => '参数错误',
- // 'budget_id.gt' => '参数错误',
- 'company_id.require' => '参数错误',
- 'company_id.gt' => '参数错误',
- ];
- protected $scene = [
- ];
- protected function checkUnique($value,$rule,$data=[])
- {
- $info = Db::name('budget_items')
- ->where('title',$data['title'])
- // ->where('budget_id',$data['budget_id'])
- ->where('company_id',$data['company_id'])
- ->find();
- if($data['id'] <= 0 && $info){
- return '名称已被占用';
- }
- if($info && $data['id'] > 0 && $info['id'] != $data['id']){
- return '名称已被占用';
- }
- return true;
- }
- }
|