123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class UserSubsidies extends Validate{
- protected $rule = [
- 'title' => 'require|checkUnique',
- // 'name' => 'require|checkUniqueName',
- 'type' => 'require|in:1,2,3',
- 'cate|分类' => 'require|in:1,2',
- 'pay_type|类型' => 'require|in:1,2,3,4,5',
- ];
- protected $message = [
- 'title.require' => '名称不能为空',
- // 'name.require' => '标识不能为空',
- 'type.require' => '请选择范围',
- 'type.in' => '参数错误',
- 'cate.in' => '参数错误',
- 'pay_type.in' => '参数错误',
- ];
- protected $scene = [
- ];
- protected function checkUnique($value,$rule,$data=[])
- {
- $info = Db::name('user_subsidies')->where('pay_type',$data['pay_type'])->where('title',$value)->where('del',0)->find();
- if($data['id'] <= 0 && $info){
- return '名称已被占用';
- }
- if($info && $data['id'] > 0 && $info['id'] != $data['id']){
- return '名称已被占用';
- }
- return true;
- }
- protected function checkUniqueName($value,$rule,$data=[])
- {
- $info = Db::name('user_subsidies')->where('del',0)->where('name',$value)->find();
- if($data['id'] <= 0 && $info){
- return '标识已被占用';
- }
- if($info && $data['id'] > 0 && $info['id'] != $data['id']){
- return '标识已被占用';
- }
- return true;
- }
- }
|