select('id,content')->where(['su_id' => \Yii::$app->user->identity->id])->all(); return $diagnoseCommon; } /** * 添加常用医嘱 */ public function actionAdd(){ $post = \Yii::$app->request->post(); $this->requestValidate($post,[ [['content'],'required'] ]); $diagnoseCommon = DiagnoseCommon::find()->where(['content' => $post['content'],'su_id' => \Yii::$app->user->identity->id])->one(); if($diagnoseCommon){ throw new Exception('已存在相同内容的医嘱'); } $common = new DiagnoseCommon(); $common->su_id = \Yii::$app->user->identity->id; $common->content = $post['content']; $common->saveOrFail(); return ['success']; } /** * 删除常用医嘱 */ public function actionDelete(){ $post = \Yii::$app->request->post(); $this->requestValidate($post,[ [['id'],'required'] ]); $ids = explode(',', $post['id']); $t = \Yii::$app->db->beginTransaction(); try { foreach($ids as $v){ $diagnoseCommon = DiagnoseCommon::find()->where(['id' => $v,'su_id' => \Yii::$app->user->identity->id])->one(); if(!$diagnoseCommon){ throw new Exception('医嘱不存在'); } $diagnoseCommon->delete(); } $t->commit(); } catch (\Exception $e) { $t->rollBack(); throw new Exception($e->getMessage()); } return ['success']; } }