'integer|gt:0', 'name' => 'require|length:1,50|chsAlpha', 'phone' => 'require|mobile|checkPhoneUnique', 'province_adcode' => 'require|max:50', 'city_adcode' => 'require|max:50', 'district_adcode' => 'require|max:50', 'address' => 'require|max:255', 'id_card_front' => 'require|max:255', 'id_card_back' => 'require|max:255', ]; /** * 提示消息 */ protected $message = [ // 基础信息 // 'id.require' => '申请ID不能为空', 'id.integer' => '申请ID必须是整数', 'id.gt' => '申请ID必须大于0', 'name.require' => '姓名不能为空', 'name.length' => '姓名长度必须在1-50个字符之间', 'name.chsAlpha' => '姓名只能包含中文、字母', 'phone.require' => '联系电话不能为空', 'phone.mobile' => '联系电话格式不正确', 'phone.checkPhoneUnique' => '该手机号已被申请', 'province_adcode.require' => '省级编码不能为空', 'province_adcode.max' => '省级编码长度不能超过50个字符', 'city_adcode.require' => '市级编码不能为空', 'city_adcode.max' => '市级编码长度不能超过50个字符', 'district_adcode.require' => '区县编码不能为空', 'district_adcode.max' => '区县编码长度不能超过50个字符', 'address.require' => '详细地址不能为空', 'address.max' => '详细地址长度不能超过255个字符', 'id_card_front.require' => '身份证正面照片不能为空', 'id_card_front.max' => '身份证正面照片路径长度不能超过255个字符', 'id_card_back.require' => '身份证反面照片不能为空', 'id_card_back.max' => '身份证反面照片路径长度不能超过255个字符', ]; /** * 验证场景 */ protected $scene = [ // 创建申请 'create' => ['name', 'phone', 'province_adcode', 'city_adcode', 'district_adcode','address', 'id_card_front', 'id_card_back'], // 查看详情 'detail' => ['id'], // 修改申请 'update' => ['id', 'name', 'phone', 'province_adcode', 'city_adcode', 'district_adcode','address', 'id_card_front', 'id_card_back'], ]; /** * 自定义验证方法 - 验证手机号是否已申请 */ protected function checkPhoneUnique($value, $rule, $data = []) { $model = new \app\common\model\inspection\InspectionApplication(); $where = ['phone' => $value]; // 如果是修改,排除当前记录 if (isset($data['id']) && $data['id'] > 0) { $where['id'] = ['neq', $data['id']]; } $exists = $model->where($where)->find(); if ($exists) { return '该手机号已提交过申请'; } return true; } }