Browse Source

修改代码

fuyu 5 năm trước cách đây
mục cha
commit
5568257966

+ 6 - 1
application/inter/controller/Application.php

@@ -11,6 +11,8 @@ use app\common\library\Verify;
 use think\File;
 use app\common\library\send_message;
 use app\common\library\Message;
+use app\inter\service\WechatService;
+
 class Application extends Base
 {
     /**
@@ -273,7 +275,7 @@ class Application extends Base
     }
      *")
      **/
-    public function apply(){
+    public function apply(WechatService $wechatService){
         try{
             log::record($_REQUEST);
             $sessionid = $_REQUEST['sessionid'];
@@ -437,6 +439,7 @@ class Application extends Base
                             }
                         }
                         if($contact['pay_type'] === 1) { // 患者支付
+                           $wechatService->pushWechatOrder($param['id']);
                            return $this->createPatientsOrder($local_institution_id, $remote_institution_id, $req_doctor_id, $remote_doctor_id, $exam_info['exam_class'], $application['id'], $cost['money']);
                         }
                     }
@@ -457,6 +460,8 @@ class Application extends Base
                     DB::table('remote_application')->where('exam_id',$param['id'])->update(['report_status'=>4]);
                 }
                 // 添加messages信息
+
+                $wechatService->pushWechatOrder($param['id']);
                 $t = '收到一条远程诊断申请';
                 $ins = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
                 $c = $ins['name'].$doctor['realname'].'医师向您发起一条远程诊断申请';

+ 80 - 0
application/inter/service/WechatService.php

@@ -0,0 +1,80 @@
+<?php
+namespace app\inter\service;
+
+use think\Db;
+
+class WechatService {
+  public function pushWechatOrder($exam_id) {
+    $openids = $this->getPushOpenId($exam_id);
+    if(!$openids) {
+      log::record('---------没有找到对应openid--------');
+      return false;
+    }
+
+    foreach($openids as $v) {
+      $url   = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid=";
+      $full_url = $url . $v['openid'];
+      // 请求
+      $res = $this->curl_request($full_url, 'GET');
+    }
+    // http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid=
+  }
+
+  public function pushWechatCancel() {
+
+  }
+
+  public function pushWechatComplete() {
+
+  }
+
+  private function getPushOpenId($exam_id) {
+    $exams = DB::table("exams")
+    ->alias('e')
+    ->join('studies s', 'e.study_id = s.id')
+    ->join('patient_infos pi', 'e.patient_id = pi.id')
+    ->field('e.patient_id, s.accession_num, s.studyid, p.temp_patient_id, p.card_num, p.phone')
+    ->where('e.id', $exam_id)
+    ->find();
+
+    if(!$exams) {
+      return false;
+    }
+    $options = [];
+    $accession_num = $exams['accession_num'];
+    $studyid = $exams['studyid'];
+    $patient_id = $exams['patient_id'];
+    $temp_patient_id = $exams['temp_patient_id'];
+    $card_num = $exams['card_num'];
+    $phone = $exams['phone'];
+
+    $sql1 = "select user_id as uid from user_bind where patient_id = ?";
+    $options[] = $patient_id;
+
+    $sql2 = "select uid from wechat_bind where ";
+    $sql2 .= "(patientCode = ?";
+    $options[] = $temp_patient_id;
+    if(!empty($accession_num)) {
+      $sql2 .= " or patientCode = ?";
+      $options[] = $accession_num;
+    }
+    if(!empty($studyid)) {
+      $sql2 .= " or patientCode = ?";
+      $options[] = $studyid;
+    }
+    $sql2 .=")";
+    if($card_num) {
+      $sql2 .= " or idcard = ?";
+      $options[] = $card_num;
+    }
+    if($card_num) {
+      $sql2 .= " or phone = ?";
+      $options[] = $phone;
+    }
+
+    $sql = $sql1." union ".sql2;
+    log::record('---------微信推送sql--------');
+    log::record($sql);
+    return Db::query($sql, $options);
+  }
+}