'服务包', 'drug_number'=>'服务包编号', 'unit_id'=>'单位', 'pinyin_simple'=>'拼音首拼', 'status'=>'状态 1草稿 2下架 3上架', ]; } public function save() { if (!$this->validate()){ throw new Exception($this->getErrorMsg()); } $t = \Yii::$app->db->beginTransaction(); try { $drug=new Drug(); $drug->attributes=$this->attributes; $drug->specification = $this->specification; $drug->usage = $this->usage; $drug->type = '5'; $drug->created_at=time(); $drug->saveOrFail(); $t->commit(); return ['新增成功']; }catch (\Exception $e){ $t->rollBack(); throw new Exception($e->getMessage()); } } public function update() { $drug=Drug::find()->where([ 'id'=>$this->id, 'type'=>3, ])->one(); if (!$drug) throw new Exception('该服务包不存在'); $drug->pinyin_simple=$this->pinyin_simple??$drug->pinyin_simple; $drug->status=$this->status??$drug->status; $drug->drug_name=$this->drug_name??$drug->drug_name; $drug->drug_number=$this->drug_number??$drug->drug_number; $drug->drug_alias=$this->drug_alias??$drug->drug_alias; $drug->unit_id=$this->unit_id??$drug->unit_id; $drug->place=$this->place??$drug->place; $drug->source=$this->source??$drug->source; $drug->instruction=$this->instruction??$drug->instruction; $drug->saveOrFail(); return ['编辑成功']; } public function info() { $drug= Drug::find()->where([ 'id'=>$this->id, 'type'=>3, ])->one(); if (!$drug) throw new Exception('该服务包不存在'); return $drug; } }