'require', 'first_level' => 'require|checkFirstLevel', 'second_level' => 'checkSecondLevel', 'three_level' => 'checkThreeLevel', 'code' => 'require', 'name' => 'require', 'specs' => 'require', 'unit' => 'require', 'inventory' => 'integer|egt:0', 'sales_price' => 'float|egt:0', 'cost_price' => 'float|egt:0', 'annex' => 'checkAnnex' ]; protected $message = [ 'id.require' => '缺少必要参数', 'first_level.require' => '请选择材料大类', 'code.require' => '请填写材料编码', 'name.require' => '请填写材料名称', 'specs.require' => '请填写规格型号', 'unit.require' => '请填写单位', 'inventory.integer' => '安全库存量值必须是整数', 'inventory.egt' => '安全库存量值必须大于等于0', 'sales_price.float' => '销售指导价值必须是数字', 'sales_price.egt' => '销售指导价值必须大于等于0', 'cost_price.float' => '预算成本价值必须是数字', 'cost_price.egt' => '预算成本价值必须大于等于0', ]; /** * @notes 添加场景 * @return MaterialValidate * @author likeadmin * @date 2024/01/04 10:59 */ public function sceneAdd() { return $this->remove('id',true); } /** * @notes 编辑场景 * @return MaterialValidate * @author likeadmin * @date 2024/01/04 10:59 */ public function sceneEdit() {} /** * @notes 删除场景 * @return MaterialValidate * @author likeadmin * @date 2024/01/04 10:59 */ public function sceneDelete() { return $this->only(['id']); } /** * @notes 详情场景 * @return MaterialValidate * @author likeadmin * @date 2024/01/04 10:59 */ public function sceneDetail() { return $this->only(['id']); } public function checkFirstLevel($value): bool|string { $classify = MaterialClassify::where('id',$value)->where('pid',0)->findOrEmpty(); if($classify->isEmpty()){ return '材料大类不存在'; } return true; } public function checkSecondLevel($value,$rule,$data): bool|string { $classify = MaterialClassify::where('id',$value)->where('pid',$data['first_level'])->findOrEmpty(); if($classify->isEmpty()){ return '材料中类不存在'; } return true; } public function checkThreeLevel($value,$rule,$data): bool|string { $classify = MaterialClassify::where('id',$value)->where('pid',$data['second_level'])->findOrEmpty(); if($classify->isEmpty()){ return '材料小类不存在'; } return true; } public function checkAnnex($value): bool|string { if(!empty($value) && $value != ''){ if(!is_array($value)){ return '附件格式错误'; } } return true; } }