初始化仓库
This commit is contained in:
75
service/modules/v1/controllers/DiagnoseController.php
Normal file
75
service/modules/v1/controllers/DiagnoseController.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/*
|
||||
* @author: liudiao
|
||||
* @Date: 2023-07-31 13:45:51
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
namespace service\modules\v1\controllers;
|
||||
|
||||
use common\core\BaseServiceController;
|
||||
use common\models\DiagnoseCommon;
|
||||
use yii\base\Exception;
|
||||
|
||||
|
||||
/**
|
||||
* @doc-module 常用医嘱
|
||||
*/
|
||||
class DiagnoseController extends BaseServiceController
|
||||
{
|
||||
/**
|
||||
* 常用医嘱列表
|
||||
*/
|
||||
public function actionCommon()
|
||||
{
|
||||
$diagnoseCommon = DiagnoseCommon::find()->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'];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user