|
@@ -341,7 +341,76 @@ class Application extends Base
|
|
|
// $aid = $r['id'];
|
|
|
// }
|
|
|
if(isset($param['apply']) && !empty($param['apply'])){
|
|
|
- DB::table('remote_application')->where('exam_id',$param['id'])->update(['report_status'=>4]);
|
|
|
+ $institution_id = $doctor['institution_id'];
|
|
|
+ $lower_hospital = DB::table('institution')->where('id', $institution_id)->field('is_pay')->find();
|
|
|
+ $is_pay = $lower_hospital['is_pay'];
|
|
|
+ $application = DB::table('remote_application')->where('exam_id', $param['id'])->field('id, remote_institution_id, remote_doctor_id, local_institution_id, req_doctor_id')->find();
|
|
|
+ if(empty($application)) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2011','msg'=> '申请单创建失败']);
|
|
|
+ }
|
|
|
+ $remote_institution_id = $application['remote_institution_id'];
|
|
|
+ $remote_doctor_id = $application['remote_doctor_id'];
|
|
|
+ $local_institution_id = $application['local_institution_id'];
|
|
|
+ $req_doctor_id = $application['req_doctor_id'];
|
|
|
+ if(empty($remote_institution_id)) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2012','msg'=> '远程机构id为空']);
|
|
|
+ }
|
|
|
+ if(empty($remote_doctor_id)) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2013','msg'=> '远程医生id为空']);
|
|
|
+ }
|
|
|
+ if(empty($local_institution_id)) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2014','msg'=> '本地机构id为空']);
|
|
|
+ }
|
|
|
+ if(empty($req_doctor_id)) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2015','msg'=> '本地医生id为空']);
|
|
|
+ }
|
|
|
+ if($is_pay === 1) {
|
|
|
+ $cost = DB::table('remote_cost')
|
|
|
+ ->where('hospital_id', $local_institution_id)
|
|
|
+ ->where('super_hospital_id', $remote_institution_id)
|
|
|
+ ->where('super_doctor_id', $remote_doctor_id)
|
|
|
+ ->where('exam_class', $exam_info['exam_class'])
|
|
|
+ ->field('money')
|
|
|
+ ->find();
|
|
|
+ if(!$cost) {
|
|
|
+ return json_encode(['status'=>'ok','code'=>'2016','msg'=> '远程医生获取失败']);
|
|
|
+ }
|
|
|
+ if($cost['money'] !== 0) {
|
|
|
+ $contact = DB::table('remote_contact')
|
|
|
+ ->where('hospital_id', $local_institution_id)
|
|
|
+ ->where('super_hospital_id', $remote_institution_id)
|
|
|
+ ->field('pay_type')
|
|
|
+ ->find();
|
|
|
+ if(!$contact) {
|
|
|
+ return json_encode(['status'=>'ok','code'=>'2017','msg'=> '远程机构获取失败']);
|
|
|
+ }
|
|
|
+ if($contact['pay_type'] === 0) { //医院挂账
|
|
|
+ // $hospital_id, $super_hospital_id, $doctor_id, $super_doctor_id, $exam_class, $application_id, $order_money
|
|
|
+ $res = $this->createHospitalOrder($local_institution_id, $remote_institution_id, $req_doctor_id, $remote_doctor_id, $exam_info['exam_class'], $application['id'], $cost['money']);
|
|
|
+ if($res !== true) {
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($contact['pay_type'] === 1) { // 患者支付
|
|
|
+ return $this->createPatientsOrder($local_institution_id, $remote_institution_id, $req_doctor_id, $remote_doctor_id, $exam_info['exam_class'], $application['id'], $cost['money']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ DB::table('remote_order')->insert([
|
|
|
+ 'id' => UUIDs::uuid16(),
|
|
|
+ 'hospital_id' => $local_institution_id,
|
|
|
+ 'super_hospital_id' => $remote_institution_id,
|
|
|
+ 'exam_class' => $exam_info['exam_class'],
|
|
|
+ 'doctor_id' => $req_doctor_id,
|
|
|
+ 'application_id' => $application['id'],
|
|
|
+ 'super_doctor_id' => $remote_doctor_id,
|
|
|
+ 'order_money' => 0,
|
|
|
+ 'pay_type' => self::PAY_TYPE['HOSPITAL'],
|
|
|
+ 'pay_way' => self::PAY_WAY['HOSPITAL'],
|
|
|
+ 'timestamp' => time()
|
|
|
+ ]);
|
|
|
+ DB::table('remote_application')->where('exam_id',$param['id'])->update(['report_status'=>4]);
|
|
|
+ }
|
|
|
// 添加messages信息
|
|
|
$t = '收到一条远程诊断申请';
|
|
|
$ins = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
|
|
@@ -357,10 +426,11 @@ class Application extends Base
|
|
|
if($dinfo['institution_id'] == '22100003' || $dinfo['send_sms'] == 1){ //魏庙
|
|
|
$repsone = send_message::sendSms2Apply($d_phone,$d_time,$d_name);
|
|
|
}
|
|
|
- $tel = '18910184804';
|
|
|
- $type = '发起申请';
|
|
|
- $content = $aid;
|
|
|
-// $response = send_message::sendSms2Self($tel,$type,$content);
|
|
|
+ // $tel = '18910184804';
|
|
|
+ // $type = '发起申请';
|
|
|
+ // $content = $aid;
|
|
|
+ // $response = send_message::sendSms2Self($tel,$type,$content);
|
|
|
+
|
|
|
}
|
|
|
return json_encode(['status'=>'ok','code'=>'0000','sessionid'=>$sessionid,'aid'=>$aid]);
|
|
|
}catch(\Exception $e){
|
|
@@ -368,6 +438,113 @@ class Application extends Base
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private function createHospitalOrder($hospital_id, $super_hospital_id, $doctor_id, $super_doctor_id, $exam_class, $application_id, $order_money) {
|
|
|
+ DB::startTrans();
|
|
|
+ $pay_type = self::PAY_TYPE['HOSPITAL'];
|
|
|
+ $pay_way = self::PAY_TYPE['HOSPITAL'];
|
|
|
+ $water_type = self::WATER_TYPE['REDUCE'];
|
|
|
+ $water_why = self::WATER_WHY['REMOTEPAY'];
|
|
|
+ try{
|
|
|
+ $hospital = DB::table('institution')
|
|
|
+ ->where('id', $hospital_id)
|
|
|
+ ->field('min_money, current_money')
|
|
|
+ ->find();
|
|
|
+ if(!$hospital) {
|
|
|
+ DB::rollback();
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2017','查找本地医院失败']);
|
|
|
+ }
|
|
|
+ $min_money = $hospital['min_money'];
|
|
|
+ $current_money = $hospital['current_money'];
|
|
|
+ if($current_money - $order_money < $min_money) {
|
|
|
+ DB::rollback();
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2017','余额不足请联系医院管理员充值']);
|
|
|
+ }
|
|
|
+ DB::table('institution')->where('id',$hospital_id)->update(['current_money'=> $current_money - $order_money]);
|
|
|
+ DB::table('remote_application')->where('id',$application_id)->update(['report_status'=>4]);
|
|
|
+ $order_id = UUIDs::uuid16();
|
|
|
+ DB::table('remote_order')->insert([
|
|
|
+ 'id' => $order_id,
|
|
|
+ 'hospital_id' => $hospital_id,
|
|
|
+ 'super_hospital_id' => $super_hospital_id,
|
|
|
+ 'exam_class' => $exam_class,
|
|
|
+ 'doctor_id' => $doctor_id,
|
|
|
+ 'application_id' => $application_id,
|
|
|
+ 'super_doctor_id' => $super_doctor_id,
|
|
|
+ 'order_money' => $order_money,
|
|
|
+ 'pay_type' => $pay_type,
|
|
|
+ 'pay_way' => $pay_way,
|
|
|
+ 'timestamp' => time(),
|
|
|
+ ]);
|
|
|
+ DB::table('remote_water')->insert([
|
|
|
+ 'id' => UUIDs::uuid16(),
|
|
|
+ 'hospital_id' => $hospital_id,
|
|
|
+ 'order_id' => $order_id,
|
|
|
+ 'money' => $order_money,
|
|
|
+ 'type' => $water_type,
|
|
|
+ 'why' => $water_why,
|
|
|
+ 'timestamp' => time(),
|
|
|
+ ]);
|
|
|
+ // 提交事务
|
|
|
+ DB::commit();
|
|
|
+ return true;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ DB::rollback();
|
|
|
+ }
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2018','远程诊断发起失败']);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function createPatientsOrder($hospital_id, $super_hospital_id, $doctor_id, $super_doctor_id, $exam_class, $application_id, $order_money) {
|
|
|
+ $pay_type = self::PAY_TYPE['PATIENT'];
|
|
|
+ $pay_way = self::PAY_TYPE['WECHAT'];
|
|
|
+ try{
|
|
|
+ $order_id = UUIDs::uuid16();
|
|
|
+ DB::table('remote_order')->insert([
|
|
|
+ 'id' => $order_id,
|
|
|
+ 'hospital_id' => $hospital_id,
|
|
|
+ 'super_hospital_id' => $super_hospital_id,
|
|
|
+ 'exam_class' => $exam_class,
|
|
|
+ 'doctor_id' => $doctor_id,
|
|
|
+ 'application_id' => $application_id,
|
|
|
+ 'super_doctor_id' => $super_doctor_id,
|
|
|
+ 'order_money' => $order_money,
|
|
|
+ 'pay_type' => $pay_type,
|
|
|
+ 'pay_way' => $pay_way,
|
|
|
+ 'timestamp' => time(),
|
|
|
+ ]);
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','oid'=>$order_id,'aid'=>$application_id]);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2019','远程诊断发起失败']);
|
|
|
+ }
|
|
|
+
|
|
|
+ private const WATER_TYPE = [
|
|
|
+ 'ADD' => 1,
|
|
|
+ 'REDUCE' => 2
|
|
|
+ ];
|
|
|
+
|
|
|
+ /**流水原因 远程诊断医院扣款 远程诊断医院收入 远程诊断退款 远程诊断退款收入 */
|
|
|
+ private const WATER_WHY = [
|
|
|
+ 'REMOTEPAY' => 21,
|
|
|
+ 'REMOTEINCOME' => 11,
|
|
|
+ 'REMOTEREFUND' => 22,
|
|
|
+ 'REFUNDINCOME' => 12
|
|
|
+ ];
|
|
|
+ // why 患者支付/远程诊断收入/远程诊断付款/远程诊断退款/提现
|
|
|
+ /**支付方式 微信 支付宝 银联 医院扣款*/
|
|
|
+ private const PAY_WAY = [
|
|
|
+ "HOSPITAL" => 1,
|
|
|
+ "WECHAT" => 11,
|
|
|
+ "ALIPAY" => 12,
|
|
|
+ "BANK" => 13
|
|
|
+ ];
|
|
|
+
|
|
|
+ /**支付类型 医院 微信 */
|
|
|
+ private const PAY_TYPE = [
|
|
|
+ "HOSPITAL" => 0,
|
|
|
+ "PATIENT" => 1
|
|
|
+ ];
|
|
|
|
|
|
/**
|
|
|
* 上传附件
|