diff --git a/app/adminapi/validate/custom/CustomValidate.php b/app/adminapi/validate/custom/CustomValidate.php index 198399228..0def72a9c 100644 --- a/app/adminapi/validate/custom/CustomValidate.php +++ b/app/adminapi/validate/custom/CustomValidate.php @@ -14,7 +14,7 @@ namespace app\adminapi\validate\custom; - +use app\common\model\custom\Custom; use app\common\validate\BaseValidate; @@ -32,6 +32,7 @@ class CustomValidate extends BaseValidate */ protected $rule = [ 'id' => 'require', + 'name' => 'require|checkName', ]; @@ -41,6 +42,7 @@ class CustomValidate extends BaseValidate */ protected $field = [ 'id' => 'id', + 'name' => '客户名称' ]; @@ -64,7 +66,7 @@ class CustomValidate extends BaseValidate */ public function sceneEdit() { - return $this->only(['id']); + return $this->only(['id', 'name']); } @@ -91,4 +93,17 @@ class CustomValidate extends BaseValidate return $this->only(['id']); } + public function checkName($value, $rule, $data) + { + if (!empty($data['id'])) { + $custom = Custom::where('name', $value)->where('id', '<>', $data['id'])->findOrEmpty(); + } else { + $custom = Custom::where('name', $value)->findOrEmpty(); + } + if (!$custom->isEmpty()) { + return '客户已存在!'; + } + return true; + } + } \ No newline at end of file