初始化仓库
This commit is contained in:
265
service/modules/v1/controllers/StoreAcceptController.php
Normal file
265
service/modules/v1/controllers/StoreAcceptController.php
Normal file
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
|
||||
namespace service\modules\v1\controllers;
|
||||
|
||||
use common\core\BaseAppController;
|
||||
use common\enums\RegisterEnum;
|
||||
use common\forms\RegisterRefundForm;
|
||||
use common\jobs\RegisterAcceptJob;
|
||||
use common\jobs\templateMessage\RegisterAccept;
|
||||
use common\models\DoctorPatient;
|
||||
use common\models\Prescription;
|
||||
use common\models\Register;
|
||||
use common\models\RegisterRefund;
|
||||
use common\models\SystemNotice;
|
||||
use common\models\UserPatient;
|
||||
use yii\db\Exception;
|
||||
|
||||
/**
|
||||
* @doc-module 到店接诊
|
||||
*/
|
||||
class StoreAcceptController extends BaseAppController
|
||||
{
|
||||
/**
|
||||
* @doc-name 患者信息(线下患者挂号信息)
|
||||
* @doc-param int register_id 挂号id
|
||||
* @doc-param int patient_id 患者id
|
||||
* @doc-return mixed @Register{*} 挂号信息
|
||||
* @doc-return mixed @UserPatient{*} 患者信息
|
||||
* @doc-return mixed @UserPatientHealthInquiry{*} 健康信息
|
||||
* @doc-return mixed @Store{name-string-门店} 门店信息
|
||||
* @doc-return mixed @Doctor{name-string-医生} 医生信息
|
||||
* @doc-return mixed @Depart{name-string-科室} 科室信息
|
||||
*/
|
||||
public function actionPatientDetail()
|
||||
{
|
||||
$post=\Yii::$app->request->post();
|
||||
$this->requestValidate($post,[
|
||||
[['patient_id','register_id'],'required']
|
||||
]);
|
||||
$register=Register::find()->where([
|
||||
'id'=>$post['register_id'],
|
||||
'service_user_id'=>\Yii::$app->user->id,
|
||||
'user_patient_id'=>$post['patient_id'],
|
||||
'is_pay'=>1,
|
||||
'is_cancel'=>0,
|
||||
'is_delete'=>0
|
||||
])->with(['patient','healthInquery'])
|
||||
->with(['depart'=>function($d){
|
||||
$d->select('name');
|
||||
}])
|
||||
->with(['doctor'=>function($d){
|
||||
$d->select('name');
|
||||
}])
|
||||
->with(['store'=>function($s){
|
||||
$s->select('name');
|
||||
}])
|
||||
->asArray()->one();
|
||||
if (!$register) throw new Exception('挂号不存在');
|
||||
$prescription = Prescription::find()->select('id,prescription_no')->where(['register_id' => $register['id']])->all();
|
||||
$register['prescription'] = $prescription;
|
||||
return $register;
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name 患者详情
|
||||
* @doc-param int patient_id 患者id
|
||||
* @doc-return mixed @Info{@UserPatient{*,@UserPatientCase{*},@UserPatientHealthInquiry{*}}} 基本信息
|
||||
* @doc-return mixed @Register{*,@UserPatientCase{*}} 挂号列表
|
||||
* @doc-return mixed @Prescription{*} 处方列表
|
||||
*/
|
||||
public function actionPatientInfo()
|
||||
{
|
||||
$post=\Yii::$app->request->post();
|
||||
$this->requestValidate($post,[
|
||||
['patient_id','required']
|
||||
]);
|
||||
$info=UserPatient::find()->where([
|
||||
'id'=>$post['patient_id'],
|
||||
'is_delete'=>0
|
||||
])->with(['case','health'])->asArray()->one();
|
||||
|
||||
if (!$info){
|
||||
throw new Exception('患者不存在');
|
||||
}
|
||||
$register=Register::find()->where([
|
||||
'service_user_id'=>\Yii::$app->user->id,
|
||||
'user_patient_id'=>$post['patient_id'],
|
||||
'is_delete'=>0,
|
||||
'is_pay'=>1,
|
||||
'is_cancel'=>0
|
||||
])->andWhere([
|
||||
'like','order_no',$post['order_no']??'',
|
||||
])->with(['case'])->asArray()->all();
|
||||
Prescription::find()->where([
|
||||
'su_id'=>\Yii::$app->user->id,
|
||||
'up_id'=>$post['patient_id'],
|
||||
'is_pay'=>1,
|
||||
'cancel_status'=>0
|
||||
])->andWhere([
|
||||
'like','prescription_no',$post['prescription_no']??'',
|
||||
])->all();
|
||||
|
||||
return [
|
||||
'info'=>$info,
|
||||
// 'Register'=>$register,
|
||||
// 'Prescription'=>$Prescription,
|
||||
];
|
||||
|
||||
}
|
||||
/**
|
||||
* @doc-name 接诊/拒诊
|
||||
* @doc-param int register_id 挂号id
|
||||
* @doc-param int status 1接诊2拒绝
|
||||
* @doc-param json refuse_reason 拒诊原因["咨询不对症","患者病情复杂"] / optional
|
||||
*/
|
||||
public function actionAcceptOrRefuse()
|
||||
{
|
||||
$post=\Yii::$app->request->post();
|
||||
$this->requestValidate($post,[
|
||||
[['register_id','status'],'required']
|
||||
]);
|
||||
|
||||
$register=Register::find()->where([
|
||||
'id'=>$post['register_id'],
|
||||
'service_user_id'=>\Yii::$app->user->id,
|
||||
'is_pay'=>1,
|
||||
'is_cancel'=>0,
|
||||
'is_delete'=>0,
|
||||
])->andWhere(['status'=>[RegisterEnum::WAIT]])->one();
|
||||
|
||||
if (!$register) throw new Exception('挂号不存在');
|
||||
|
||||
$UserPatient = UserPatient::find()->where([
|
||||
'user_id' => $register->user_id,
|
||||
'id' =>$register->user_patient_id
|
||||
])->one();
|
||||
if (!$UserPatient) throw new Exception('就诊人不存在');
|
||||
|
||||
if ($post['status']==1){
|
||||
|
||||
$transaction=\Yii::$app->db->beginTransaction();
|
||||
try {
|
||||
//医生患者表(接诊后添加,已存在不新增)
|
||||
$isDoctorPatient = DoctorPatient::find()->where([
|
||||
'user_id' => $register->user_id,
|
||||
'su_id' => \Yii::$app->user->id,
|
||||
'up_id' => $register->user_patient_id
|
||||
])->one();
|
||||
|
||||
if(!$isDoctorPatient){
|
||||
$DoctorPatient=new DoctorPatient();
|
||||
$DoctorPatient->user_id=$register->user_id;
|
||||
$DoctorPatient->su_id=\Yii::$app->user->id;
|
||||
$DoctorPatient->up_id=$register->user_patient_id;
|
||||
$DoctorPatient->avatar=$UserPatient->avatar;
|
||||
$DoctorPatient->name=$UserPatient->name;
|
||||
$DoctorPatient->id_card=$UserPatient->id_card;
|
||||
$DoctorPatient->sex=$UserPatient->sex;
|
||||
$DoctorPatient->mobile=$UserPatient->mobile;
|
||||
$DoctorPatient->saveOrFail();
|
||||
}
|
||||
//接诊
|
||||
$register->status=RegisterEnum::ACCEPTING;
|
||||
$register->created_at=strtotime( $register->created_at);
|
||||
$register->updated_at=time();
|
||||
$register->saveOrFail();
|
||||
|
||||
$transaction->commit();
|
||||
|
||||
//挂号接诊订阅消息通知
|
||||
\Yii::$app->queue->push(new RegisterAccept([
|
||||
'orderId' => $register->id,
|
||||
]));
|
||||
|
||||
//挂号已接诊分账结算
|
||||
\Yii::$app->queue->push(new RegisterAcceptJob([
|
||||
'orderId' => $register->id,
|
||||
]));
|
||||
|
||||
return ['已接诊'];
|
||||
}catch (Exception $e){
|
||||
$transaction->rollBack();
|
||||
throw new $e;
|
||||
}
|
||||
}else{
|
||||
if(!$post['refuse_reason']) throw new Exception('拒诊原因不能为空');
|
||||
$t=\Yii::$app->db->beginTransaction();
|
||||
try {
|
||||
$register->status=RegisterEnum::REFUSE;
|
||||
$register->refuse_reason=$post['refuse_reason'];
|
||||
$register->created_at=strtotime( $register->created_at);
|
||||
$register->updated_at=time();
|
||||
$register->saveOrFail();
|
||||
|
||||
//发送拒诊通知
|
||||
$systemNotice = new SystemNotice();
|
||||
$systemNotice->content = '由于'.$post['refuse_reason'].',医生已拒绝接诊!';
|
||||
$systemNotice->base_type = 3;//处方通知
|
||||
$systemNotice->scene_type = 1;
|
||||
$systemNotice->user_id = $register->user_id;
|
||||
$systemNotice->notice_at = date('Y-m-d H:i:s',time());
|
||||
$systemNotice->saveOrFail();
|
||||
|
||||
//退款
|
||||
$form=new RegisterRefundForm();
|
||||
$form->refund($post['register_id']);
|
||||
|
||||
$t->commit();
|
||||
return ['已拒诊'];
|
||||
}catch (\Exception $e){
|
||||
$t->rollBack();
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name 问诊结束
|
||||
* @doc-param int register_id 挂号id
|
||||
*/
|
||||
public function actionRegisterOver()
|
||||
{
|
||||
$post=\Yii::$app->request->post();
|
||||
$this->requestValidate($post,[
|
||||
[['register_id'],'required']
|
||||
]);
|
||||
|
||||
$register = Register::find()->select('status')->where([
|
||||
'id' => $post['register_id'],
|
||||
'service_user_id' => \Yii::$app->user->id,
|
||||
'is_pay' => 1,
|
||||
'is_cancel' => 0,
|
||||
'is_delete' => 0,
|
||||
])->andWhere(['status'=>[RegisterEnum::ACCEPTING]])->one();
|
||||
|
||||
if (!$register) throw new Exception('挂号不存在');
|
||||
Register::updateAll(['status' => RegisterEnum::OVER],['id' => $post['register_id']]);
|
||||
|
||||
//发送问诊结束通知
|
||||
$systemNotice = new SystemNotice();
|
||||
$systemNotice->content = '问诊已结束,祝您早日康复!';
|
||||
$systemNotice->base_type = 3;//问诊结束通知
|
||||
$systemNotice->scene_type = 1;
|
||||
$systemNotice->user_id = $register->user_id;
|
||||
$systemNotice->notice_at = date('Y-m-d H:i:s',time());
|
||||
$systemNotice->saveOrFail();
|
||||
|
||||
return ['已结束'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @doc-name 拒诊原因列表
|
||||
*/
|
||||
public function actionRefuseList()
|
||||
{
|
||||
$data=[
|
||||
['key'=>0,'value'=>'咨询不对症'],
|
||||
['key'=>1,'value'=>'患者缺少诊疗资料'],
|
||||
['key'=>2,'value'=>'患者病情复杂'],
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user