'require', 'key' => 'require|checkKey', 'type' => 'require|in:'.MapKeyEnum::TYPE_TENCENT, ]; protected $message = [ 'id.require' => '参数错误', 'key.require' => '请输入key', 'type.require' => '请选择类型', 'type.in' => '类型值错误', ]; public function sceneAdd() { return $this->only(['key','type']); } public function sceneDetail() { return $this->only(['id']); } public function sceneEdit() { return $this->only(['id','key','type']); } public function sceneDel() { return $this->only(['id']); } /** * @notes 校验key * @param $value * @param $rule * @param $data * @return string|true * @author ljj * @date 2024/11/5 下午2:04 */ public function checkKey($value,$rule,$data) { $where[] = ['key','=',$value]; if (isset($data['id'])) { $where[] = ['id','<>',$data['id']]; } $result = MapKey::where($where)->findOrEmpty(); if (!$result->isEmpty()) { return 'key已存在,请重新输入'; } return true; } }