234 lines
10 KiB
PHP
234 lines
10 KiB
PHP
<?php
|
|
|
|
namespace admin\controllers\base;
|
|
|
|
use admin\components\BaseAdminController;
|
|
use admin\controllers\AuthController;
|
|
use common\enums\UserRoleEnum;
|
|
use common\helpers\FuncHelper;
|
|
use common\models\Prescription;
|
|
use common\models\ProductOrder;
|
|
use common\services\ExportService;
|
|
use yii\db\Exception;
|
|
use yii\helpers\Json;
|
|
use yii\web\Response;
|
|
|
|
/**
|
|
* @doc-module 处方
|
|
*/
|
|
class PrescriptionController extends BaseAdminController
|
|
{
|
|
/**
|
|
* @doc-name 处方列表
|
|
* @doc-param string prescription_no 处方编号 / optional
|
|
* @doc-param string name 患者 / optional
|
|
* @doc-param string doctor 开方医生 / optional
|
|
* @doc-param string clinical_diagnose 临床诊断 / optional
|
|
* @doc-param int status 处方状态0待审核1已通过2未通过3待使用4已使用5未使用6已失效7已初审 / optional
|
|
* @doc-return mixed @List{id,prescription_no-string-处方编号,name-string-患者,sex-int-性别,clinical_diagnose-string-临床诊断,doctor-string-开方医生,doctor_sign-string-医生签名,pharmacist-string-审核药师,pharmacist_view_time-string-审核时间,patient_mobile-string-患者电话,created_at-int-开方时间,status-int-处方状态0待审核1已通过2未通过3待使用4已使用5未使用6已失效7已初审,is_get-int-是否取药0否1是,prescription_type-int-1中药处方2西药处方3颗粒药处方,category-int-类别1自费2医保,is_pay-int-是否支付0否1是,pay_time-string-支付时间,pay_type-int-支付类型1微信2支付宝3银行卡4其他,type-int-类型1普通方2常用方,@OrderInfo{platform_id-int-平台id,platform_store_id-int-平台门店id,platform_order_id-int-平台订单ID,drugstore_id-string-仓库id,order_no-string-产品顶单号,p_id-int-处方id,order_type-int-订单类型1处方订单2商城订单3商城处方订单,type-int-支付类型1微信2支付宝3银行卡4其他,address-string-地址,is_pay-int-是否支付0否1是,total_pay_price-float-支付金额,free_ship-int-是否包邮0否1是,trans_expenses-float-运费(默认包邮),pay_method-int-支付方式1线上2线下,status-int-产品订单状态0未支付1待发货2待收货3已完成}} 处方列表
|
|
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
|
|
*/
|
|
public function actionList()
|
|
{
|
|
$get = \Yii::$app->request->get();
|
|
$admin=\Yii::$app->user->identity;
|
|
$start_time=strtotime($get['start_time'].' '.'00:00:00');
|
|
$end_time=strtotime($get['end_time'].' '.'23:59:59');
|
|
|
|
if ($admin->role==UserRoleEnum::STORE_ADMIN){//门店
|
|
$query = Prescription::find()->where([
|
|
'store_id' => $admin->store_id,
|
|
'is_deleted' => 0,
|
|
])->orderBy(['id'=>SORT_DESC]);
|
|
}else{
|
|
$query = Prescription::find()->where([
|
|
'is_deleted' => 0
|
|
])->orderBy(['id'=>SORT_DESC]);
|
|
}
|
|
|
|
$name = $get['name'];
|
|
$doctor = $get['doctor'];
|
|
|
|
if (!empty($get['prescription_no'])) {//处方编号
|
|
$query->andWhere(['prescription_no' => $get['prescription_no']]);
|
|
}
|
|
if (!empty($name)) {//患者
|
|
$query->joinWith(['userPatient' => function ($u) use ($name) {
|
|
$u->where([
|
|
'like', 'name', $name
|
|
]);
|
|
}]);
|
|
}
|
|
if (!empty($doctor)) {//开方医生
|
|
$query->joinWith(['doctorInfo' => function ($d) use ($doctor) {
|
|
$d->where([
|
|
'like', 'name', $doctor
|
|
]);
|
|
}]);
|
|
}
|
|
if (!empty($get['clinical_diagnose'])) {//临床诊断
|
|
$query->andWhere(['like', 'yii_prescription.clinical_diagnose', $get['clinical_diagnose']]);
|
|
}
|
|
if (!empty($get['status'])) {//处方状态
|
|
$query->andWhere(['yii_prescription.status' => $get['status']]);
|
|
}
|
|
if (!empty($get['is_dispense'])) {//是否配药
|
|
$query->andWhere(['yii_prescription.is_dispense' => $get['is_dispense']]);
|
|
}
|
|
if (!empty($get['start_time']) && !empty($get['end_time'])){
|
|
if ($start_time==$end_time){//筛选某一天
|
|
$time=FuncHelper::getDayBE($get['start_time']);
|
|
|
|
$end_time=$time[1];
|
|
}
|
|
$query->andWhere(['between','yii_prescription.created_at',$start_time,$end_time]);
|
|
}
|
|
|
|
$this->field = [
|
|
Prescription::class => [
|
|
'id', 'prescription_no','online_prescription_no','valid_hours','is_online',
|
|
'content' => function ($p) {
|
|
$repice = Json::decode($p->content, true)['repice'];
|
|
|
|
return $repice;
|
|
},
|
|
'name' => 'userPatient.name',
|
|
'sex' => 'userPatient.sex',
|
|
'patient_age' => 'userPatient.age',
|
|
'dept' => 'doctorInfo.depart.name',
|
|
'patient_mobile' => 'userPatient.mobile',
|
|
'clinical_diagnose', 'doctor_order', 'prescription_type', 'category', 'doctor_sign',
|
|
'doctor' => 'doctorInfo.name',
|
|
'status', 'pharmacist' => 'pharmacistInfo.name', 'pharmacist_view_time'=>function($m){
|
|
return date('Y-m-d H:i:s',$m->pharmacist_view_time);
|
|
},
|
|
'is_pay', 'pay_type', 'pay_time', 'type','register_id','total_pay_price','cancel_status','cancel_time','cancel_remark','refund_status','refund_time','auto_expire_time',
|
|
'is_get' => function ($model) {
|
|
return ProductOrder::find()->select('is_pay')->where([
|
|
'p_id' => $model->id
|
|
])->column();
|
|
},
|
|
'order_info' => function ($q) {
|
|
return ProductOrder::find()->where([
|
|
'p_id' => $q->id
|
|
])->one();
|
|
}, 'created_at' => function ($m) {
|
|
return date('Y-m-d H:i:s', $m->created_at);
|
|
},
|
|
]
|
|
];
|
|
return $this->create($query, $get);
|
|
}
|
|
|
|
|
|
/**
|
|
* @doc-name 打印pdf
|
|
*/
|
|
public function actionPdf()
|
|
{
|
|
|
|
$prescription = \Yii::$app->request->post('prescription');
|
|
$mpdf = new \Mpdf\Mpdf([
|
|
'mode' => 'UTF-8', 'format' => 'A4', 'default_font_size' => 15, 'default_font' => '', 'margin_left' => 20, 'margin_right' => 20]);
|
|
$mpdf->autoScriptToLang = true;//支持中文设置
|
|
$mpdf->autoLangToFont = true;//支持中文设置
|
|
$mpdf->WriteHTML($prescription);
|
|
$path = 'FILE_UPLOAD' . date('YmdHis') . '_' . mt_rand(1, 5) . '.pdf';
|
|
$mpdf->Output();//直接在页面显示pdf页面内容
|
|
//$mpdf->Output($path,'f');//保存pdf文件到指定目录
|
|
}
|
|
|
|
/**
|
|
* @doc-name 处方详情
|
|
* @doc-param int id 处方id
|
|
*/
|
|
public function actionPrescriptionDetail()
|
|
{
|
|
$get = \Yii::$app->request->get();
|
|
$this->requestValidate($get,[
|
|
['id','required']
|
|
]);
|
|
$Prescription= Prescription::find()->alias('p')->where([
|
|
'p.id'=>$get['id'],
|
|
'p.is_deleted' => 0
|
|
])->with(['register','store'])->joinWith(['userPatient'])->asArray()->one();
|
|
if (!$Prescription) throw new Exception('处方不存在');
|
|
|
|
if ( $Prescription['prescription_type']== 1 || $Prescription['prescription_type'] == 3) {//中药 配方颗粒
|
|
|
|
$content=$Prescription['content'];
|
|
$recipe = json_decode($content, true)['repice'];
|
|
|
|
$data['content']= json_decode($recipe[0]['content']);
|
|
$data['deployment']=$recipe[0]['deployment'];
|
|
$data['dosage']=$recipe[0]['dosage'];
|
|
$data['consumption']=$recipe[0]['consumption'];
|
|
$data['directions']=$recipe[0]['directions'];
|
|
$data['usage']=$recipe[0]['usage'];
|
|
$data['fufa_id']=$recipe[0]['fufa_id'];
|
|
$data['volume']=$recipe[0]['volume'];
|
|
$data['is_deepfry']=$recipe[0]['is_deepfry'];
|
|
$data['cm_id']=$recipe[0]['cm_id'];
|
|
$data['total_price']=$recipe[0]['total_price'];
|
|
$data['remark']=$recipe[0]['remark'];
|
|
|
|
} else {//西药
|
|
$repice = json_decode($Prescription['content'], true)['repice'];
|
|
|
|
$data = [];
|
|
foreach ($repice as $v) {
|
|
$item = [
|
|
'id' => $v['id'],
|
|
'content' => json_decode($v['content']),
|
|
'drug_name' => json_decode($v['content'])->drug_name,
|
|
'source' => json_decode($v['content'])->source,
|
|
'function' => json_decode($v['content'])->function,
|
|
'usage' => json_decode($v['content'])->usage,
|
|
'specification' => json_decode($v['content'])->specification,
|
|
'instruction' => json_decode($v['content'])->instruction,
|
|
'image' => json_decode($v['content'])->image,
|
|
'number' => $v['number'],
|
|
'available_days' => $v['available_days'],
|
|
'total_price' => $v['total_price'],
|
|
'created_at' => $v['created_at'],
|
|
'type_id' => json_decode($v['content'])->type_id,
|
|
'time_id' => json_decode($v['content'])->time_id,
|
|
'frequency_id' => json_decode($v['content'])->frequency_id,
|
|
'unit_id' => json_decode($v['content'])->unit_id,
|
|
'usetime' => $v['usetime']['name'],
|
|
'frequency' => $v['frequency']['name'],
|
|
'grain_number' => $v['grain_number'],
|
|
'westUnit' => $v['westUnit']['name'],
|
|
'types' => $v['usetype']['name'], //药的使用方式
|
|
];
|
|
|
|
$data[] = $item;
|
|
}
|
|
}
|
|
|
|
$ProductOrder=ProductOrder::find()->where([
|
|
'p_id'=>$get['id']
|
|
])->one();
|
|
return [
|
|
'content'=>$data,
|
|
'prescription'=>$Prescription,
|
|
'ProductOrder'=>$ProductOrder
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @doc-name 导出处方
|
|
*/
|
|
public function actionExportPrescription()
|
|
{
|
|
// \Yii::$app->response->format = Response::FORMAT_RAW;
|
|
$params=\Yii::$app->request->get();
|
|
$parameter['header']=['订单号','医生','患者','订单状态','价格','是否取药','时间'];
|
|
$parameter['data']=Prescription::inventory($params,\Yii::$app->user->identity->store_id);
|
|
// $Name='处方记录';
|
|
// $class=new Prescription();
|
|
|
|
ExportService::ExportByCors($parameter);
|
|
|
|
}
|
|
} |