validate()) { throw new Exception($this->getErrorMsg()); } if (!$this->id) { $BaseConfig = new BaseConfig(); } else { $BaseConfig = BaseConfig::find()->where([ 'id' => $this->id, ])->one(); if (!$BaseConfig) { throw new Exception('协议不存在'); } } $BaseConfig->end = $this->end ?? $BaseConfig->end; $BaseConfig->desc = $this->desc ?? $BaseConfig->desc; $BaseConfig->type = $this->type ?? $BaseConfig->type; $BaseConfig->content = $this->content ?? $BaseConfig->content; $BaseConfig->change_at = time(); $BaseConfig->saveOrFail(); return ['success']; } public function del() { $BaseConfig = BaseConfig::find()->where([ 'id' => $this->id ])->one(); if (!$BaseConfig) { throw new Exception('协议不存在'); } $BaseConfig->status = 1; if (!$BaseConfig->saveOrFail()) { throw new Exception('删除失败'); } return ['已删除']; } }