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); } }