diff --git a/app/common/validate/InquiryLogValidate.php b/app/common/validate/InquiryLogValidate.php index aac6495..2a869bb 100644 --- a/app/common/validate/InquiryLogValidate.php +++ b/app/common/validate/InquiryLogValidate.php @@ -80,17 +80,29 @@ class InquiryLogValidate extends Validate ] ]; + /** * 验证联系方式唯一性 */ - protected function checkContactUnique($value, $rule, $data) + protected function checkContactUnique($value, $rule, $data, $field, $title) { - // 至少需要提供一种联系方式 + // 如果是更新操作且联系人未修改,跳过检查 + if ($this->currentScene == 'update') { + $original = InquiryLog::find($data['id']); + if ($original && $original->contacts == $value && $original->country == ($data['country'] ?? 0)) { + return true; + } + } + if (empty($data['email']) && empty($data['tel']) && empty($data['whatsapp'])) { - $exists = InquiryLog::where('contacts', trim($data['contacts'])) - ->where('country', $data['country']) - ->exists(); - return !$exists; + $query = InquiryLog::where('contacts', trim($value)) + ->where('country', $data['country']); + + if (!empty($data['id'])) { + $query->where('id', '<>', $data['id']); + } + + return !$query->exists(); } return true; @@ -99,27 +111,66 @@ class InquiryLogValidate extends Validate /** * 验证邮箱联系方式唯一性 */ - protected function checkEmailContactUnique($value) + protected function checkEmailContactUnique($value, $rule, $data, $field, $title) { if (empty($value)) return true; - return !InquiryLog::where('email', trim($value))->exists(); + + // 如果是更新操作且邮箱未修改,跳过检查 + if ($this->currentScene == 'update' && !empty($data['id'])) { + $original = InquiryLog::find($data['id']); + if ($original && $original->email == $value) { + return true; + } + } + + $query = InquiryLog::where('email', trim($value)); + if (!empty($data['id'])) { + $query->where('id', '<>', $data['id']); + } + return !$query->exists(); } /** * 验证电话联系方式唯一性 */ - protected function checkTelContactUnique($value) + protected function checkTelContactUnique($value, $rule, $data, $field, $title) { if (empty($value)) return true; - return !InquiryLog::where('tel', trim($value))->exists(); + + // 如果是更新操作且电话未修改,跳过检查 + if ($this->currentScene == 'update' && !empty($data['id'])) { + $original = InquiryLog::find($data['id']); + if ($original && $original->tel == $value) { + return true; + } + } + + $query = InquiryLog::where('tel', trim($value)); + if (!empty($data['id'])) { + $query->where('id', '<>', $data['id']); + } + return !$query->exists(); } /** * 验证WhatsApp联系方式唯一性 */ - protected function checkWhatsappContactUnique($value) + protected function checkWhatsappContactUnique($value, $rule, $data, $field, $title) { if (empty($value)) return true; - return !InquiryLog::where('whatsapp', trim($value))->exists(); + + // 如果是更新操作且WhatsApp未修改,跳过检查 + if ($this->currentScene == 'update' && !empty($data['id'])) { + $original = InquiryLog::find($data['id']); + if ($original && $original->whatsapp == $value) { + return true; + } + } + + $query = InquiryLog::where('whatsapp', trim($value)); + if (!empty($data['id'])) { + $query->where('id', '<>', $data['id']); + } + return !$query->exists(); } } \ No newline at end of file diff --git a/app/inquiry/service/InquiryLogService.php b/app/inquiry/service/InquiryLogService.php index d8be346..759c8c4 100644 --- a/app/inquiry/service/InquiryLogService.php +++ b/app/inquiry/service/InquiryLogService.php @@ -85,7 +85,7 @@ class InquiryLogService ]; } // 状态 - if (isset($p['status']) && $p['status']) { + if (isset($p['status']) && in_array($p['status'], [0,1,2])) { $config['where']['status'] = $p['status']; } // 关键字