修改询单验证器&状态范围
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user