Przeglądaj źródła

xg 患者发送短信

刘桂岩 5 lat temu
rodzic
commit
63a55490ec

+ 11 - 0
application/common/library/send_message.php

@@ -33,6 +33,17 @@ class send_message extends AliyunSms{
         DB::table('send_message')->insert(['phone'=>$phone,'type'=>'报告完成','doctor'=>$doctor]);
         return self::sendSms($phone,"中世康恺","SMS_153330824",array("doctor" => $doctor));
     }
+
+
+    /*
+    * 给患者发送短信
+    * 通知: 类型:${code} 内容:${rid}
+    * @param {string} code 发送的验证码
+    * @param {string} rid 数据库中这一条信息的id  share表
+    */
+    public static function sendSms2Patient($phone,$code = '', $rid = '') {
+        return self::sendSms($phone,"中世康恺","SMS_181546061",array("code" => $code, "rid" => $rid));
+    }
     /*
     * 发送[内部通知]短信
     * 通知: 类型:${type} 内容:${content}

+ 11 - 0
application/inter/controller/Base.php

@@ -39,6 +39,17 @@ class Base extends Controller
         }
     }
 
+    function getRandomString($len, $chars=null)
+    {
+        if (is_null($chars)){
+            $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
+        }
+        mt_srand(10000000*(double)microtime());
+        for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++){
+            $str .= $chars[mt_rand(0, $lc)];
+        }
+        return $str;
+    }
 
     public function _construct()
     {

+ 1 - 1
application/inter/controller/Inspectregister.php

@@ -403,7 +403,7 @@ class Inspectregister extends Base
             //检查信息和申请信息
             $exam_info['institution_id']     = $doctor['institution_id'];
             $exam_info['register_datetime']  = date('Y-m-d : H:i:s');
-            $exam_info['phone']              = $doctor['phone'];
+            $exam_info['phone']              = isset($param['phone']) ? $param['phone'] : '';;
             $exam_info['patient_num']        = isset($param['pnum']) ? $param['pnum'] : '';
             // $exam_info['hopitalized_no']     = isset($param['hopitalized_no']) ? $param['hopitalized_no'] : '';
             // $exam_info['bed_no']             = isset($param['bed_no']) ? $param['bed_no'] : '';

+ 39 - 0
application/inter/controller/Writereport.php

@@ -517,6 +517,13 @@ class Writereport extends Base
             if($report_info['type'] == 1){
                 //本地报告确认
                 DB::table('exams')->where('id',$id)->update(['exam_status'=>'9']);
+                $sms = DB::table('institution')->where('id',$doctor['institution_id'])->value('patient_sms');
+                if($sms == 1){
+                    $examData = DB::table('exams')->where('id',$id)->field('phone,study_id')->find();
+                    $phone = $examData['phone'];
+                    $study_id = $examData['study_id'];
+                    $this->sendSms($phone,$report_id,$id,$study_id);
+                }
             }else{
                 Message::read($doctor['id'],$report_info['remote_application_id'],4);
                 //远程
@@ -555,6 +562,38 @@ class Writereport extends Base
 
     }
 
+
+    public function sendSms($phone,$reportId,$examId,$studyId)
+    {
+        $code = $this->getRandomString(4);
+        $id = UUIDs::uuid16();
+        if(empty($phone)){
+            $send_message = 0;
+        }else{
+            //发送短信
+            $send = send_message::sendSms2Patient($phone,$code,$id);
+            $data = json_decode(json_encode($send),true);
+            if($data['Code'] == 'OK'){
+                $send_message = 1;
+            }else{
+                $send_message = 0;
+            }
+        }
+        $share = [
+            'id'=>$id,
+            'report_id'=>$reportId,
+            'exam_id'=>$examId,
+            'code'=>$code,
+            'send_time'=>time(),
+            'expires_time'=>time()+86400*7,
+            'send_message'=>$send_message,
+            'url'=>'',
+            'phone'=>$phone,
+            'study_id'=> $studyId
+        ];
+        DB::table('share')->insert($share);
+    }
+
     private function confirmReport($application_id, $wechatService) {
         Db::startTrans();
         try{