'require', 'supplier_id' => 'require|checkSupplier', 'name' => 'require', 'sex' => 'in:0,1', 'birthday' => 'dateFormat:Y-m-d', 'contacts_type' => 'checkContactsType', 'contacts_cate' => 'checkContactsCate', 'id_type' => 'checkIdType', 'annex' => 'checkAnnex' ]; protected $message = [ 'id.require' => '缺少必要参数', 'supplier_id.require' => '请选择供应商', 'name.require' => '请填写姓名', 'sex.in' => '性别值无效', 'birthday.dateFormat' => '出生日期数据格式错误', ]; /** * @notes 添加场景 * @return SupplierContactsValidate * @author likeadmin * @date 2023/12/26 13:47 */ public function sceneAdd() { return $this->remove('id',true); } /** * @notes 编辑场景 * @return SupplierContactsValidate * @author likeadmin * @date 2023/12/26 13:47 */ public function sceneEdit() {} /** * @notes 删除场景 * @return SupplierContactsValidate * @author likeadmin * @date 2023/12/26 13:47 */ public function sceneDelete() { return $this->only(['id']); } /** * @notes 详情场景 * @return SupplierContactsValidate * @author likeadmin * @date 2023/12/26 13:47 */ public function sceneDetail() { return $this->only(['id']); } public function checkSupplier($value): bool|string { $supplier = Supplier::where('id',$value)->findOrEmpty(); if($supplier->isEmpty()){ return '供应商信息不存在'; } return true; } public function checkContactsType($value): bool|string { $dict = DictData::where('type_value','contacts_type')->column('value'); if(!in_array($value,$dict)){ return '联系人分类无效'; } return true; } public function checkContactsCate($value): bool|string { $dict = DictData::where('type_value','contacts_cate')->column('value'); if(!in_array($value,$dict)){ return '联系人类型无效'; } return true; } public function checkIdType($value): bool|string { $dict = DictData::where('type_value','id_type')->column('value'); if(!in_array($value,$dict)){ return '证件类型无效'; } return true; } public function checkAnnex($value): bool|string { if(!empty($value) && $value != ''){ if(!is_array($value)){ return '附件格式错误'; } } return true; } }