You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

265 lines
11 KiB

<?php
namespace app\admin\controller;
use app\admin\model\Drugs;
use app\admin\model\User;
use app\admin\model\User_Role;
use app\lib\enum\ExceptionType;
use app\lib\exception\JsonException;
use app\lib\exception\Success;
use app\lib\validate\IdMustBePositiveInt;
use app\viewModel\PatientMedicalView;
use think\Request;
class Payment extends BaseController
{
public function index(){
$map = [];
//有搜索时
if (Request::instance()->isPost()) {
$code = Request::instance()->param('code');
// p($union);die();
if (!empty($code)) {
$patient = \app\admin\model\PatientInfo::where(['code'=>$code])->column('id');
$patientName = \app\admin\model\PatientInfo::where(['code'=>$code])->column('name');
// $test = \app\admin\model\PatientInfo::where(['code'=>$code])->select();
// p($test[0]['code']);die();
//???
$patient['id'] = ['in',$patient];
// p($patient);die();
$medicals = \app\admin\model\PatientMedical::viewQuery(PatientMedicalView::CLASS, "patientDrugsList")
->where(['patient_id' => $patient['id']])
->paginate(10, false, [
"query" => [
'code' => $code,
]
]);
$medicalsCheck = \app\admin\model\PatientMedical::where(['patient_id' => $patient['id']])->select();
// p($medicals[0]['id']);die();
if($medicalsCheck[0]) $check = 1;
else $check = 2;
$totalPrice = 0;
$totalStatus = 0;
$totalType = 0;
foreach($medicals as $key=>$medical){
$totalPrice = $medical['price'] + $totalPrice;
$totalStatus = $medical['status'] + $totalStatus;
$totalType = $medical['type'] + $totalType;
if($medical['status']==0) $medical['status'] = "未缴费";
else $medical['status']="已缴费";
if($medical['type']==0) $medical['type'] = "未取药";
else $medical['type']="已取药";
// p($medical['status']);
}
// p($totalStatus);die();
if($totalStatus == count($medicals)){
$totalStatus = "已缴费";
}
elseif($totalStatus == 0){
$totalStatus = "未缴费";
}
else{
$totalStatus = "有未缴费的药品";
}
if($totalType == count($medicals)){
$totalType = "已取药";
}
elseif($totalType == 0){
$totalType = "未取药";
}
else{
$totalType = "有未取的药品";
}
$total = $medicals->total();
$page = $medicals->render();
$this->assign('page', $page);
$this->assign('total', $total);
$this->assign('code', $code);
$this->assign('medicals', $medicals);
$this->assign('totalPrice', $totalPrice);
$this->assign('totalStatus', $totalStatus);
$this->assign('totalType', $totalType);
$this->assign('check', $check);
$this->assign('patientName', $patientName[0]);
// $this->assign('id', $patient[0]);
}
}
//无搜索时
$patientInfo = \app\admin\model\PatientInfo::viewQuery(PatientMedicalView::CLASS, "patientDate")
->where(1)
->paginate(10, false);
$total = $patientInfo->total();
$page = $patientInfo->render();
$this->assign('page', $page);
$this->assign('total', $total);
$this->assign('patientInfo', $patientInfo);
return $this->fetch();
}
public function check(){
$code = Request::instance()->param('code');
$patient = \app\admin\model\PatientInfo::where(['code'=>$code])->column('id');
$patientName = \app\admin\model\PatientInfo::where(['code'=>$code])->column('name');
// $test = \app\admin\model\PatientInfo::where(['code'=>$code])->select();
// p($test[0]['code']);die();
//???
$patient['id'] = ['in',$patient];
// p($patient);die();
$medicals = \app\admin\model\PatientMedical::viewQuery(PatientMedicalView::CLASS, "patientDrugsList")
->where(['patient_id' => $patient['id']])
->paginate(10, false, [
"query" => [
'code' => $code,
]
]);
$medicalsCheck = \app\admin\model\PatientMedical::where(['patient_id' => $patient['id']])->select();
// p($medicals[0]['id']);die();
if($medicalsCheck[0]) $check = 1;
else $check = 2;
$totalPrice = 0;
$totalStatus = 0;
$totalType = 0;
foreach($medicals as $key=>$medical){
$totalPrice = $medical['price'] + $totalPrice;
$totalStatus = $medical['status'] + $totalStatus;
$totalType = $medical['type'] + $totalType;
if($medical['status']==0) $medical['status'] = "未缴费";
else $medical['status']="已缴费";
if($medical['type']==0) $medical['type'] = "未取药";
else $medical['type']="已取药";
// p($medical['status']);
}
// p($totalStatus);die();
if($totalStatus == count($medicals)){
$totalStatus = "已缴费";
}
elseif($totalStatus == 0){
$totalStatus = "未缴费";
}
else{
$totalStatus = "有未缴费的药品";
}
if($totalType == count($medicals)){
$totalType = "已取药";
}
elseif($totalType == 0){
$totalType = "未取药";
}
else{
$totalType = "有未取的药品";
}
$total = $medicals->total();
$page = $medicals->render();
$this->assign('page', $page);
$this->assign('total', $total);
$this->assign('code', $code);
$this->assign('medicals', $medicals);
$this->assign('totalPrice', $totalPrice);
$this->assign('totalStatus', $totalStatus);
$this->assign('totalType', $totalType);
$this->assign('check', $check);
$this->assign('patientName', $patientName[0]);
return $this->fetch();
}
//单个缴费 id:患者药单的id
public function costAlong($id){
$patientMedical = \app\admin\model\PatientMedical::where(['id'=>$id])->find();
// p($patientMedical);die();
if ($patientMedical['status'] == 1){
throw new JsonException('1','费用已缴');
}
else{
$data = [
'status' => 1,
];
$patientMedical->save($data);
throw new Success('缴费成功!');
}
}
//单个领取 id:患者药单id
public function getMedical($id){
$patientMedical = \app\admin\model\PatientMedical::where(['id'=>$id])->find();
$drugs = Drugs::where(['id'=>$patientMedical['drugs_id']])->find();
if ($patientMedical['type'] == 1){
throw new JsonException('1','药品已领取');
}
else{
$use = [
'use_amount' => $drugs['use_amount'] + $patientMedical['quantity'],
'quantity' => $drugs['quantity'] - $patientMedical['quantity'],
];
$data = [
'type' => 1,
];
$drugs->save($use);
$patientMedical->save($data);
throw new Success('领取成功!');
}
}
//总缴费 union:流水号
public function total(){
//参数传过来的时候有问题??以下均不可以
// public function total($code){
//$code = $_POST['code']
$code = Request::instance()->param('code');
// p($code);die();
// 1590834044M1
$patient = \app\admin\model\PatientInfo::where(['code'=>$code])->find();
$patientMedicals =\app\admin\model\PatientMedical::where(['patient_id'=>$patient['id']])->select();
// p($patient);die();
$check = 0;
foreach($patientMedicals as $medical){
if($medical['status']==0){
$data = ['status' => 1];
$medical->save($data);
}
$check++;
}
if($check == count($patientMedicals)){
throw new Success('缴费成功!');
}
else throw new JsonException('1','缴费失败!');
}
// //总领取 code:流水号
public function getTotal(){
$code = Request::instance()->param('code');
$patient = \app\admin\model\PatientInfo::where(['code'=>$code])->find();
$patientMedicals =\app\admin\model\PatientMedical::where(['patient_id'=>$patient['id']])->select();
// p($patientMedicals);die();
$check1 = 0;
$check2 = 0;
foreach($patientMedicals as $patientMedical){
$drugs = Drugs::where(['id'=>$patientMedical['drugs_id']])->find();
if($drugs){
if($patientMedical['type']==0){
$data = [
'type' => 1,
];
$medical = [
'use_amount' => $drugs['use_amount'] + $patientMedical['quantity'],
'quantity' => $drugs['quantity'] - $patientMedical['quantity'],
];
$patientMedical->save($data);
$drugs->save($medical);
$check2++;
// p($medical);
}
else $check1++;
}
}
// die();
$check = $check1 +$check2;
if($check == count($patientMedicals)){
throw new Success('领取成功!');
}
else throw new JsonException('1','领取失败!');
}
}