'require', 'org_id' => 'require|checkOrg', 'dept_id' => 'require|checkDept', 'name' => 'require|unique:'.Custom::class, 'custom_type' => 'require|checkType', 'phone' => 'require', 'credit_rating' => 'require|checkRat', 'master_name' => 'require', 'master_phone' => 'mobile', 'master_email' => 'email', 'other_contacts' => 'checkContacts' ]; protected $message = [ 'id.require' => '缺少必要参数', 'org_id.require' => '请选择组织', 'dept_id.require' => '请选择部门', 'name.require' => '请填写客户名称', 'name.unique' => '客户名称已存在', 'custom_type.require' => '请选择客户属性', 'phone.require' => '请填写客户电话', 'credit_rating.require' => '请选择信用度', 'master_name.require' => '请填写主要负责人姓名', 'master_phone.mobile' => '主要负责人手机号格式错误', 'master_email.email' => '主要负责人邮箱格式错误', ]; /** * @notes 添加场景 * @return CustomValidate * @author likeadmin * @date 2023/11/11 22:10 */ public function sceneAdd() { return $this->remove('id', true); } /** * @notes 编辑场景 * @return CustomValidate * @author likeadmin * @date 2023/11/11 22:10 */ public function sceneEdit() { return $this->remove('other_contacts',true); } /** * @notes 删除场景 * @return CustomValidate * @author likeadmin * @date 2023/11/11 22:10 */ public function sceneDelete() { return $this->only(['id']); } /** * @notes 详情场景 * @return CustomValidate * @author likeadmin * @date 2023/11/11 22:10 */ public function sceneDetail() { return $this->only(['id']); } public function checkOrg($value): bool|string { $org = Orgs::where('id',$value)->findOrEmpty(); if($org->isEmpty()){ return '组织不存在'; } return true; } public function checkDept($value,$rule,$data): bool|string { $dept = Dept::where('id',$value)->findOrEmpty(); if($dept->isEmpty()){ return '部门不存在'; } if($dept['org_id'] != $data['org_id']){ return '部门无效'; } return true; } public function checkType($value): bool|string { $dictData = DictData::where('type_value','custom_type')->column('value'); if(!in_array($value,$dictData)){ return '客户属性无效'; } return true; } public function checkRat($value): bool|string { $dictData = DictData::where('type_value','credit_rating')->column('value'); if(!in_array($value,$dictData)){ return '信用度无效'; } return true; } public function checkContacts($value): bool|string { if(empty($value) || !is_array($value)){ return '其他联系人数据格式错误'; } foreach($value as $v){ if(empty($v['name'])){ return '请填写联系人姓名'; } if(isset($v['annex']) && $v['annex'] != ''){ if(!is_array($v['annex'])){ return '联系人附件格式错误'; } } } return true; } }