'require', 'project_id' => 'require|checkProject', 'customer_demand_id' => 'require|checkCustomerDemand', 'estimate_source' => 'require|checkEstimateSource', 'contact_id' => 'require|checkContact', 'quotation_date' => 'require|dateFormat:Y-m-d', 'invoice_type' => 'checkInvoiceType', 'technician' => 'checkTechnician', 'estimate_amount' => 'float|egt:0', 'annex' => 'checkAnnex', ]; protected $message = [ 'id.require' => '缺少必要参数', 'project_id.require' => '请选择项目', 'customer_demand_id.require' => '请选择客户需求', 'contact_id.require' => '请选择联系人', 'estimate_source.require' => '请选择概算来源', 'quotation_date.require' => '请选择报价日期', 'quotation_date.dateFormat' => '报价日期格式错误', 'estimate_amount.float' => '概算金额值必须是数字', 'estimate_amount.egt' => '概算金额值必须大于等于0', ]; /** * @notes 添加场景 * @return ProjectEstimateValidate * @author likeadmin * @date 2023/11/24 21:42 */ public function sceneAdd() { return $this->remove('id', true); } /** * @notes 编辑场景 * @return ProjectEstimateValidate * @author likeadmin * @date 2023/11/24 21:42 */ public function sceneEdit() { } /** * @notes 删除场景 * @return ProjectEstimateValidate * @author likeadmin * @date 2023/11/24 21:42 */ public function sceneDelete() { return $this->only(['id'])->remove('id', 'checkData'); } /** * @notes 详情场景 * @return ProjectEstimateValidate * @author likeadmin * @date 2023/11/24 21:42 */ public function sceneDetail() { return $this->only(['id']); } public function checkProject($value): bool|string { $project = Project::where('id', $value)->findOrEmpty(); if ($project->isEmpty()) { return '项目不存在'; } return true; } public function checkCustomerDemand($value, $rule, $data): bool|string { $customDemand = CustomerDemand::where('id', $value)->findOrEmpty(); if ($customDemand->isEmpty()) { return '客户需求不存在'; } if ($customDemand['project_id'] != $data['project_id']) { return '客户需求与项目信息不一致'; } return true; } public function checkEstimateSource($value): bool|string { $dictDate = DictData::where('type_value', 'estimate_source')->column('value'); if (!in_array($value, $dictDate)) { return '概算来源数据值错误'; } return true; } public function checkContact($value, $rule, $data): bool|string { $customContract = CustomContacts::where('id', $value)->findOrEmpty(); if ($customContract->isEmpty()) { return '联系人不存在'; } $project = Project::field('custom_id')->where('id', $data['project_id'])->findOrEmpty(); if ($customContract['custom_id'] != $project['custom_id']) { return '联系人不是当前客户的联系人'; } return true; } function checkInvoiceType($value): bool|string { $dictDate = DictData::where('type_value', 'invoice_type')->column('value'); if (!in_array($value, $dictDate)) { return '发票类型数据值错误'; } return true; } public function checkTechnician($value): bool|string { $admin = Admin::where('id', $value)->findOrEmpty(); if ($admin->isEmpty()) { return '技术人员不存在'; } return true; } }