473 lines
16 KiB
PHP
473 lines
16 KiB
PHP
<?php
|
|
|
|
namespace member\modules\v1\controllers;
|
|
|
|
use common\core\BaseAppController;
|
|
use common\enums\OrderAcceptEnum;
|
|
use common\models\oldDb\Address;
|
|
use common\models\oldDb\ChineseRepice;
|
|
use common\models\oldDb\DoctorPatient;
|
|
use common\models\oldDb\DoctorService;
|
|
use common\models\oldDb\FollowDoctor;
|
|
use common\models\oldDb\GranularRepice;
|
|
use common\models\oldDb\ImMessage;
|
|
use common\models\oldDb\ImMessageSessionOrder;
|
|
use common\models\oldDb\Order;
|
|
use common\models\oldDb\Prescription;
|
|
use common\models\oldDb\UserInquiry;
|
|
use common\models\oldDb\UserPatient;
|
|
use common\models\oldDb\WestRepice;
|
|
use common\services\PrescriptionService;
|
|
use member\models\forms\AddressForm;
|
|
use member\models\forms\FollowForm;
|
|
use yii\db\Exception;
|
|
use yii\helpers\ArrayHelper;
|
|
use yii\helpers\Json;
|
|
|
|
/**
|
|
* @doc-module 我的
|
|
*/
|
|
class MyController extends BaseAppController
|
|
{
|
|
/**
|
|
* @doc-name 处方记录
|
|
* @doc-param int up_id 就诊人id
|
|
* @doc-return mixed @List{id-int-处方id,prescription_no-int-处方编号,up_id-int-就诊人id,created_at-int-开具时间,clinical_diagnose-string-临床诊断,,status-int-状态0待审核1已通过2未通过3待使用4已使用5未使用6已失效7已初审,doctor_name-string-医生,patient_name-string-患者,drug_name-string-药品} 处方记录
|
|
*/
|
|
public function actionPrescriptionList()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
$this->requestValidate($post, [
|
|
['store_id', 'required']
|
|
]);
|
|
$query = Prescription::find()
|
|
->where([
|
|
'user_id' => \Yii::$app->user->identity->id,
|
|
'store_id' => $post['store_id']
|
|
])->orderBy('created_at DESC');
|
|
|
|
if($post['up_id'] > 0){
|
|
$UserPatient = UserPatient::find()
|
|
->where([
|
|
'user_id' => \Yii::$app->user->identity->id,
|
|
'id' => $post['up_id']
|
|
])
|
|
->one();
|
|
|
|
if (!$UserPatient) {
|
|
throw new Exception('就诊人不存在');
|
|
}
|
|
|
|
$query->andWhere([
|
|
'up_id' => $post['up_id']
|
|
]);
|
|
}
|
|
|
|
$this->field = [
|
|
Prescription::class => [
|
|
'id', 'prescription_no','prescription_type', 'is_online', 'up_id', 'clinical_diagnose', 'status',
|
|
'created_at' => function ($model) {
|
|
return date('Y-m-d H:i:s', $model->created_at);
|
|
},
|
|
'doctor_name' => 'serviceUser.docInfo.name',
|
|
'patient_name' => 'userPatient.name',
|
|
'drug_name' => function ($model) {
|
|
$drug = [];
|
|
if($model->prescription_type == 1){
|
|
$chineseRepice = ChineseRepice::find()
|
|
->where([
|
|
'in', 'id', explode(',', $model->cr_ids)
|
|
])->all();
|
|
if($chineseRepice){
|
|
foreach($chineseRepice as $value){
|
|
$content = Json::decode($value['content']);
|
|
foreach($content as $v){
|
|
$drug[] = $v['name'];
|
|
}
|
|
|
|
}
|
|
}
|
|
}elseif ($model->prescription_type ==2) {
|
|
$westRepice = WestRepice::find()
|
|
->where([
|
|
'in', 'id', explode(',', $model->wr_ids)
|
|
])->all();
|
|
if($westRepice){
|
|
foreach($westRepice as $v){
|
|
$content = Json::decode($v['content']);
|
|
$drug[] = $content['drug_name'];
|
|
}
|
|
}
|
|
}else{
|
|
$granulareRepice = GranularRepice::find()
|
|
->where([
|
|
'in', 'id', explode(',', $model->gr_ids)
|
|
])->all();
|
|
if($granulareRepice){
|
|
foreach($granulareRepice as $value){
|
|
$content = Json::decode($value['content']);
|
|
foreach($content as $v){
|
|
$drug[] = $v['name'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $drug;
|
|
}
|
|
]
|
|
];
|
|
return $this->create($query, $post);
|
|
}
|
|
|
|
/**
|
|
* @doc-name 处方详情
|
|
* @doc-param string prescription_no 处方编号
|
|
* @doc-return mixed @List{id-int-处方id,prescription_no-int-处方编号,type-int-类型1普通方2常用方,created_at-int-开具时间,clinical_diagnose-string-临床诊断,category-int-类别1自费2医保,status-int-状态0待审核1已通过2未通过3待使用4已使用5未使用6已失效7已初审,doctor_order-string-医嘱,patient_name-string-患者,sex-int-0默认1男2女,age-int-年龄,depart-string-科室,mobile-string-手机号,doctor_name-string-医生,first_view-string-初审药师,again_view-string-复审药师,patient_name-string-患者,@Rp{@Chinese{content-string-药品有关信息,dosage-int-剂数,useNum-string-用量,usage-int-用法,fufa-string-服法,is_deepfry-int-是否浓煎0否1是,total_price-float-价格},@West{content-string-药品有关信息,number-int-数量,available_days-int-可用天数,total_price-float-价格}}} 处方记录
|
|
*/
|
|
public function actionPrescriptionDetail()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
$this->requestValidate($post, [
|
|
['prescription_no', 'required']
|
|
]);
|
|
return (new PrescriptionService())->detail($post['prescription_no']);
|
|
}
|
|
|
|
/**
|
|
* @doc-name 关注医生列表
|
|
* @doc-return mixed @Service{register_price-float-挂号价格,register_status-int-挂号状态0关闭1开启} 医生开通服务信息
|
|
* @doc-return mixed @Hospital{name-string-名称} 医院信息
|
|
* @doc-return mixed @Yard{name-string-名称} 院区信息
|
|
* @doc-return mixed @Depart{name-string-名称} 科室信息
|
|
* @doc-return string accept_percent 接诊率
|
|
* @doc-return string good_comment_percent 好评率
|
|
* @doc-return int inquiry_num 问诊量
|
|
* @doc-return string avg_reply 平均回复时间
|
|
*/
|
|
public function actionFollowList()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
|
|
$query = FollowDoctor::find()->where([
|
|
'user_id' => \Yii::$app->user->identity->id,
|
|
]);
|
|
|
|
$depart_arr = json_decode(ArrayHelper::getValue($post, 'depart_id', "[]"), true);
|
|
$type_arr = json_decode(ArrayHelper::getValue($post, 'type', "[]"), true);
|
|
$title_arr = json_decode(ArrayHelper::getValue($post, 'title_id', "[]"), true);
|
|
|
|
$query->joinWith(['docInfo' => function ($q) use ($depart_arr, $title_arr) {
|
|
$q->alias('i');
|
|
if (!empty($depart_arr)) {
|
|
$q->andWhere([
|
|
'i.depart_id' => $depart_arr
|
|
]);
|
|
};
|
|
if (!empty($title_arr)) {
|
|
$q->andWhere([
|
|
'i.title_id' => $title_arr
|
|
]);
|
|
}
|
|
}]);
|
|
|
|
if (!empty($type_arr)) {
|
|
$query->joinWith(['docService' => function ($q) use ($type_arr) {
|
|
$q->alias('s');
|
|
}]);
|
|
}
|
|
$query->joinWith(['docIdentity' => function ($q) {
|
|
$q->alias('it');
|
|
}]);
|
|
|
|
$this->field = [
|
|
FollowDoctor::class => [
|
|
'id', 'su_id',
|
|
'avator' => 'docIdentity.work_avator',
|
|
'name' => 'docInfo.name',
|
|
'depart' => 'docInfo.depart.name',
|
|
'hospital' => 'docInfo.hospital.name',
|
|
'yard' => 'docInfo.yard.name',
|
|
'title' => 'docInfo.title.name',
|
|
'good_at' => 'docInfo.good_at',
|
|
'accept_percent' => function ($model) {
|
|
$accept_num = Order::find()->where([
|
|
'su_id' => $model->id,
|
|
'is_pay' => 1,
|
|
'accept_status' => [OrderAcceptEnum::ACCEPTING, OrderAcceptEnum::OVER],
|
|
])->count();
|
|
$all_num = Order::find()->where([
|
|
'su_id' => $model->id,
|
|
'is_pay' => 1,
|
|
'accept_status' => [OrderAcceptEnum::TIMEOUT_ACCEPT, OrderAcceptEnum::REFUSED, OrderAcceptEnum::ACCEPTING, OrderAcceptEnum::OVER],
|
|
])->count();
|
|
return $all_num == 0 ? '100%' : round(($accept_num / $all_num) * 100, 2) . '%';
|
|
},
|
|
'good_comment_percent' => function ($model) {
|
|
return '100%';
|
|
},
|
|
'inquiry_num' => function ($model) {
|
|
$all_num = Order::find()->where([
|
|
'su_id' => $model->id,
|
|
'is_pay' => 1,
|
|
])->count();
|
|
return $all_num;
|
|
},
|
|
'avg_reply' => function ($model) {
|
|
return '1小时内';
|
|
},
|
|
'service' => 'docService'
|
|
],
|
|
DoctorService::class => [
|
|
'register_status', 'register_price'
|
|
]
|
|
];
|
|
return $this->create($query, $post);
|
|
}
|
|
|
|
/**
|
|
* @doc-name 关注医生
|
|
* @doc-param int su_id 医生id
|
|
* @doc-return int status 状态0未关注1已关注
|
|
*/
|
|
public function actionAddFollow()
|
|
{
|
|
|
|
$form = new FollowForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
|
|
$form->save();
|
|
return [
|
|
'status' => 1
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @doc-name 取消关注
|
|
* @doc-param int su_id 医生id
|
|
*/
|
|
public function actionCancelFollow()
|
|
{
|
|
$form = new FollowForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
|
|
$form->cancel();
|
|
}
|
|
|
|
/**
|
|
* @doc-name 就诊记录
|
|
* @doc-param int up_id 就诊人id
|
|
* @doc-return array desc 主诉
|
|
* @doc-return array created_at 时间
|
|
* @doc-return mixed @Diagnosis{content-string-内容} 诊断
|
|
*/
|
|
public function actionInquiryRecord()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
$up_id = \Yii::$app->request->post('up_id');
|
|
if (!$up_id) throw new Exception('就诊人up_id不能为空');
|
|
|
|
//患者
|
|
$doctorPatient = DoctorPatient::find()->where([
|
|
'user_id' => \Yii::$app->user->identity->id,
|
|
'up_id' => $post['up_id']
|
|
])->all();
|
|
|
|
$UserInquiry = UserInquiry::find()->select('id,patient_data')->where([
|
|
'user_id' => \Yii::$app->user->identity->id,
|
|
])->all();
|
|
if (!$UserInquiry) throw new Exception('暂时还没有就诊记录');
|
|
|
|
foreach ($UserInquiry as $value) {
|
|
$val[] = Json::decode($value['patient_data']);
|
|
}
|
|
|
|
$i = 0;
|
|
foreach ($val as $v) {
|
|
if ($v['id'] == $post['up_id']) {
|
|
$data[] = UserInquiry::find()->select('id,user_id,su_id,desc,created_at')->where([
|
|
'id' => $UserInquiry[$i]['id'],
|
|
'user_id' => \Yii::$app->user->identity->getId(),
|
|
])->one();
|
|
$i++;
|
|
}
|
|
}
|
|
|
|
foreach ($data as $vv) {
|
|
$id[] = Order::find()->select('id')->where([
|
|
'user_id' => \Yii::$app->user->identity->getId(),
|
|
'su_id' => $vv['su_id'],
|
|
'ui_id' => $vv['id'],
|
|
])->one();
|
|
}
|
|
|
|
foreach ($id as $kk) {
|
|
$ImMessageSessionOrder[] = ImMessageSessionOrder::find()->select('ims_id')->where([
|
|
'order_id' => $kk['id']
|
|
])->one();
|
|
}
|
|
|
|
foreach ($ImMessageSessionOrder as $k) {
|
|
$diagnosis[] = ImMessage::find()->select('content')->where([
|
|
'ims_id' => $k['ims_id'],
|
|
'type' => 1
|
|
])->orderBy('id desc')->one();
|
|
}
|
|
|
|
return [$data,$diagnosis];
|
|
}
|
|
|
|
/**
|
|
* @doc-name 就诊人就诊记录
|
|
* @doc-param int up_id 就诊人id
|
|
* @doc-return mixed @List{up_id-int-患者id,su_id-int-医生id,desc-string-主诉,created_at-int-时间,diagnosis-string-诊断} 诊断
|
|
* @doc-return mixed @Pagination{totalPage-int-总数据,totalPage-int-总页数,pageSize-int-每页数据} 分页信息
|
|
*/
|
|
public function actionRecord()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
$this->requestValidate($post,[
|
|
['up_id','required']
|
|
]);
|
|
|
|
$query = UserInquiry::find()->where([
|
|
'user_id' => \Yii::$app->user->identity->getId(),
|
|
'up_id' => $post['up_id']
|
|
]);
|
|
|
|
$this->field=[
|
|
UserInquiry::class=>[
|
|
'id','up_id','user_id','su_id','desc','created_at',
|
|
'diagnosis'=>function($m){
|
|
$order=Order::find()->select('id')->where([
|
|
'ui_id'=>$m->id
|
|
])->column();
|
|
$ims_id= ImMessageSessionOrder::find()->select('ims_id')->where([
|
|
'order_id' => $order
|
|
])->column();
|
|
|
|
$diagnosis = ImMessage::find()->select('content')->where([
|
|
'ims_id' => $ims_id,
|
|
'type' => 1
|
|
])->orderBy('id desc')->one();
|
|
return $diagnosis??'暂未给出诊断';
|
|
}
|
|
]
|
|
];
|
|
return $this->create($query,$post);
|
|
|
|
}
|
|
/**
|
|
* @doc-name 收货地址列表
|
|
* @doc-return mixed @Address{*} 就诊信息
|
|
*/
|
|
public function actionAddressList()
|
|
{
|
|
$list = Address::find()->where([
|
|
'user_id' => \Yii::$app->user->identity->getId(),
|
|
'is_delete' => 0
|
|
])->all();
|
|
if (!$list) throw new Exception('暂无收货地址');
|
|
|
|
$is_default = Address::find()->select('is_default')->where([
|
|
'user_id' => \Yii::$app->user->identity->getId(),
|
|
'is_delete' => 0
|
|
])->column();
|
|
|
|
if (!in_array(1,$is_default)){
|
|
$id = Address::find()->select('id')->where([
|
|
'user_id' => \Yii::$app->user->identity->getId(),
|
|
'is_delete' => 0
|
|
])->orderBy('id asc')->one();
|
|
|
|
Address::updateAll(['is_default'=>1],[
|
|
'user_id' => \Yii::$app->user->identity->getId(),
|
|
'is_delete' => 0,
|
|
'id'=>$id
|
|
]);
|
|
}
|
|
|
|
return $list;
|
|
}
|
|
|
|
/**
|
|
* @doc-name 新增收货地址
|
|
* @doc-param string name 姓名
|
|
* @doc-param string mobile 姓名
|
|
* @doc-param string region 地区
|
|
* @doc-param string detail_address 详细地址
|
|
*/
|
|
public function actionSaveAddress()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
|
|
$addressForm = new AddressForm();
|
|
$addressForm->attributes = $post;
|
|
|
|
$addressForm->save();
|
|
}
|
|
|
|
/**
|
|
* @doc-name 修改收货地址
|
|
* @doc-param int id 地址id
|
|
* @doc-param string name 姓名
|
|
* @doc-param string mobile 姓名
|
|
* @doc-param string region 地区
|
|
* @doc-param string detail_address 详细地址
|
|
*/
|
|
public function actionEditAddress()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
|
|
$this->requestValidate($post, [
|
|
['id', 'required']
|
|
]);
|
|
$addressForm = new AddressForm();
|
|
$addressForm->attributes = $post;
|
|
|
|
$addressForm->edit($post);
|
|
}
|
|
|
|
/**
|
|
* @doc-name 修改默认地址
|
|
* @doc-param int id 地址id
|
|
*/
|
|
public function actionUpdateDefault()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
|
|
$this->requestValidate($post, [
|
|
['id', 'required']
|
|
]);
|
|
$addressForm = new AddressForm();
|
|
$addressForm->attributes = $post;
|
|
|
|
$addressForm->UpdateDefault($post);
|
|
}
|
|
|
|
/**
|
|
* @doc-name 删除收货地址
|
|
* @doc-param int id 地址id
|
|
*/
|
|
public function actionDelAddress()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
|
|
$this->requestValidate($post, [
|
|
['id', 'required']
|
|
]);
|
|
$addressForm = new AddressForm();
|
|
$addressForm->attributes = $post;
|
|
|
|
$addressForm->del($post);
|
|
return ['删除成功'];
|
|
}
|
|
|
|
/**
|
|
* 挂号记录
|
|
*/
|
|
public function actionRegister()
|
|
{
|
|
|
|
}
|
|
}
|