修改询单验证器&状态范围
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'])) {
|
if (empty($data['email']) && empty($data['tel']) && empty($data['whatsapp'])) {
|
||||||
$exists = InquiryLog::where('contacts', trim($data['contacts']))
|
$query = InquiryLog::where('contacts', trim($value))
|
||||||
->where('country', $data['country'])
|
->where('country', $data['country']);
|
||||||
->exists();
|
|
||||||
return !$exists;
|
if (!empty($data['id'])) {
|
||||||
|
$query->where('id', '<>', $data['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return !$query->exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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;
|
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;
|
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联系方式唯一性
|
* 验证WhatsApp联系方式唯一性
|
||||||
*/
|
*/
|
||||||
protected function checkWhatsappContactUnique($value)
|
protected function checkWhatsappContactUnique($value, $rule, $data, $field, $title)
|
||||||
{
|
{
|
||||||
if (empty($value)) return true;
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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'];
|
$config['where']['status'] = $p['status'];
|
||||||
}
|
}
|
||||||
// 关键字
|
// 关键字
|
||||||
|
|||||||
Reference in New Issue
Block a user