ソースを参照

xiugai messages

lgy 6 年 前
コミット
55aa1f9d09

+ 15 - 10
application/common/library/Message.php

@@ -2,6 +2,7 @@
 
 namespace app\common\library;
 
+use think\Cache;
 use think\Db;
 use app\common\library\UUIDs;
 
@@ -22,7 +23,8 @@ class Message {
             $where['application_id'] = $aid;
             $where['status'] = '0'; //未删除
             $where['is_read'] = '0'; //未读
-            DB::table('messages')->where($where)->update(['is_read'=>1,'htime'=>date('Y-m-d H:i:s',time())]);
+            DB::table('messages')->where($where)->update(['is_read'=>1,'htime'=>date('Y-m-d H:i:s',time()),'count'=>0]);
+            Cache::rm('messages_'.$doctor);
         }catch(\Exception $e){
             return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
         }
@@ -57,6 +59,7 @@ class Message {
 
     //  新增消息
     public static function insert($title,$content,$did,$type,$url,$count =1,$aid = ''){
+        Cache::rm('messages_'.$did);
         try{
             $info['id'] = UUIDs::uuid16();
             $info['title'] = $title;
@@ -76,31 +79,33 @@ class Message {
     }
 
     // 获取跳转url
-    public static function url($sessionid,$id,$is_remote,$exam_class,$report_id=''){
-        $url = 'remotereport/edit/6?sessionid='.$sessionid.'&id='.$id.'&is_remote='.$is_remote.'&exam_class='.$exam_class.'&report_id='.$report_id;
+    public static function url($sessionid,$id,$is_remote,$exam_class,$report_id='',$rid=''){
+        $url = '/remotereport/edit/6?id='.$id.'&is_remote='.$is_remote.'&exam_class='.$exam_class.'&report_id='.$report_id.'&rid='.$rid;
         return $url;
     }
 
     // 消息未读条数自增
     public static function bbs_message($aid,$doctor,$content,$did,$is_remote,$sessionid){
+        Cache::rm('messages_'.$did);
         try{
 // 对话类查询
-            $message = DB::table('messages')->where('application_id',$aid)->where('doctor_id',$doctor)->where('type',7)->where('is_read',0)->find();
+            $message = DB::table('messages')->where('application_id',$aid)->where('doctor_id',$did)->where('type',7)->where('is_read',0)->find();
             if($message['status'] == '0'){
                 // 未删除  有未读
-                Db::table('messages')->where('application_id',$aid)->where('doctor_id',$doctor)->where('type',7)->where('is_read',0)->setInc('count');
+                Db::table('messages')->where('application_id',$aid)->where('doctor_id',$did)->where('type',7)->where('is_read',0)->setInc('count');
+                Db::table('messages')->where('application_id',$aid)->where('doctor_id',$did)->where('type',7)->where('is_read',0)->update(['content'=>$content]);
             }elseif($message['status'] == '1'){
                 // 有未读但已删除
-                Db::table('messages')->where('application_id',$aid)->where('doctor_id',$doctor)->where('type',7)->where('is_read',0)->update(['status'=>0,'count'=>1]);
-            }else{
+                Db::table('messages')->where('application_id',$aid)->where('doctor_id',$did)->where('type',7)->where('is_read',0)->update(['status'=>0,'count'=>1,'content'=>$content]);
+            }elseif(empty($message)){
                 //没有未读消息
-                $read = DB::table('messages')->where('application_id',$aid)->where('doctor_id',$doctor)->where('type',7)->where('is_read',1)->find();
+                $read = DB::table('messages')->where('application_id',$aid)->where('doctor_id',$did)->where('type',7)->where('is_read',1)->find();
                 if($read['status'] == '0'){
                     // 未删除  有已读  变更为未读1条
-                    Db::table('messages')->where('application_id',$aid)->where('doctor_id',$doctor)->where('type',7)->where('is_read',1)->update(['is_read'=>0,'count'=>1]);
+                    Db::table('messages')->where('application_id',$aid)->where('doctor_id',$did)->where('type',7)->where('is_read',1)->update(['is_read'=>0,'count'=>1,'content'=>$content]);
                 }elseif($read['status'] == '1'){
                     // 有已读并且已删除  变更为未读未删除1条
-                    Db::table('messages')->where('application_id',$aid)->where('doctor_id',$doctor)->where('type',7)->where('is_read',1)->update(['status'=>0,'count'=>1,'is_read'=>0]);
+                    Db::table('messages')->where('application_id',$aid)->where('doctor_id',$did)->where('type',7)->where('is_read',1)->update(['status'=>0,'count'=>1,'is_read'=>0,'content'=>$content]);
                 }else{
                     //没有改消息  新增消息
                     $title = '您收到一条远程诊断咨询消息';

+ 2 - 1
application/common/versionsql/Version6

@@ -2,4 +2,5 @@ ALTER  TABLE  `messages`  ADD  url  varchar(250);
 ALTER  TABLE  `messages`  ADD  type  varchar(50);
 ALTER  TABLE  `messages`  ADD  htime  datetime;
 ALTER  TABLE  `messages`  ADD  ctime  datetime;
-ALTER  TABLE  `messages`  ADD  count  int(10);
+ALTER  TABLE  `messages`  ADD  count  int(10);
+ALTER  TABLE  `doctors`  ADD  message_push  varchar(10) default 0;

+ 8 - 12
application/inter/controller/Application.php

@@ -134,7 +134,9 @@ class Application extends Base
                 }
                 $info['application'] = $application;
             }
-            return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid,'is_remote'=>$is_remote,'rid'=>$rid]);
+            $count = DB::table('messages')->where('application_id',$aid)->where('doctor_id',$doctor['id'])->where('status',0)->where('type',7)->where('is_read',0)->field('count')->find();
+            $info['unread_message_num'] = $count['count'];
+            return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid,'is_remote'=>$is_remote,'rid'=>$aid]);
         }catch(\Exception $e){
             return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
         }
@@ -297,10 +299,9 @@ class Application extends Base
                 $ins = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
                 $c = $ins['name'].$doctor['realname'].'医师向您发起一条远程诊断申请';
                 $d = $application_info['remote_doctor_id'];
-                $type = '发起申请';
-                $url = Message::url($sessionid,$param['id'],1,$exam_info['exam_class'],$r_id);
+                $type = '1';
+                $url = Message::url($sessionid,$param['id'],1,$exam_info['exam_class'],$r_id,$aid);
                 Message::insert($t,$c,$d,$type,$url,1,$aid);
-                Cache::rm('messages_'.$doctor['id']);
                 //保存  申请
                 $dinfo = DB::table('doctors')->where('id',$application_info['remote_doctor_id'])->find();
                 $d_phone = $dinfo['phone'];
@@ -434,9 +435,8 @@ class Application extends Base
         $d = $application['req_doctor_id'];
         $type = '2';
         $exam_class = DB::table('exams')->where('id',$re['exam_id'])->field('exam_class')->find();
-        $url = Message::url($sessionid,$re['exam_id'],0,$exam_class['exam_class'],$report['id']);
+        $url = Message::url($sessionid,$re['exam_id'],0,$exam_class['exam_class'],$report['id'],$id);
         Message::insert($t,$c,$d,$type,$url,1,$id);
-        Cache::rm('messages_'.$doctor['id']);
         // 驳回发短信
         $d_phone = $dinfo['phone'];
         if($dinfo['institution_id'] == '22100002' || $dinfo['send_sms'] == 1){ //魏庙下级
@@ -498,9 +498,8 @@ class Application extends Base
         $type = '4';
         $exam_class = DB::table('exams')->where('id',$re['exam_id'])->field('exam_class')->find();
         $report = DB::table('report')->where('remote_application_id',$id)->field('id')->find();
-        $url = Message::url($sessionid,$re['exam_id'],0,$exam_class['exam_class'],$report['id']);
+        $url = Message::url($sessionid,$re['exam_id'],0,$exam_class['exam_class'],$report['id'],$id);
         Message::insert($t,$c,$d,$type,$url,1,$id);
-        Cache::rm('messages_'.$doctor['id']);
         return json_encode(['status'=>'ok','code'=>'0000','sessionid'=>$sessionid]);
     }
 
@@ -552,7 +551,6 @@ class Application extends Base
             $info['reply'] = $rinfo['remote_doctor_id']; //申请的目标远程医生
             $remote = 1;
         }
-//        $info['reply'] = $param['reply']; // 回复人
         $info['remote_application_id'] = $param['appid']; //申请单id
         $info['content'] = $param['content'];
         $info['attachment'] = $param['attachment'];
@@ -560,7 +558,6 @@ class Application extends Base
         DB::table('bbs')->insert($info);
         // 添加message消息
         Message::bbs_message($param['appid'],$doctor['id'],$param['content'],$info['reply'],$remote,$sessionid);
-        Cache::rm('messages_'.$doctor['id']);
         return json_encode(['status'=>'ok','code'=>'0000','sessionid'=>$sessionid]);
     }
     public  function  getbbs(){
@@ -672,9 +669,8 @@ class Application extends Base
         $type = '3';
         $exam_class = DB::table('exams')->where('id',$id)->field('exam_class')->find();
         $report = DB::table('report')->where('remote_application_id',$status['id'])->field('id')->find();
-        $url = Message::url($sessionid,$id,1,$exam_class['exam_class'],$report['id']);
+        $url = Message::url($sessionid,$id,1,$exam_class['exam_class'],$report['id'],$status['id']);
         Message::insert($t,$c,$d,$type,$url,1,$status['id']);
-        Cache::rm('messages_'.$doctor['id']);
         return json_encode(['status'=>'ok','code'=>'0000','msg'=>'撤回成功']);
     }
 }

+ 2 - 0
application/inter/controller/Doctors.php

@@ -162,6 +162,7 @@ class Doctors extends Base
      * @ApiParams         (name="param[email]",              type="string",      sample="",          description="邮箱<必填>")
      * @ApiParams         (name="param[phone]",            type="string",      sample="",          description="手机号<必填>")
      * @ApiParams         (name="param[doctor_title]",            type="string",      sample="",          description="职称<必填>")
+     * @ApiParams         (name="param[message_push]",           type="string",      sample="",          description="是否消息推送<必填>")
      * @ApiParams         (name="param[attachment]",           type="string",      sample="",          description="附件<必填>")
      * @ApiReturnParams   (name="status",                     type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
      * @ApiReturnParams   (name="code",                       type="integer",     required=true,      sample="0", description="返回状态码")
@@ -188,6 +189,7 @@ class Doctors extends Base
             $data['email'] = $info['email'];
             $data['phone'] = $info['phone'];
             $data['doctor_title'] = $info['doctor_title'];
+            $data['message_push'] = $info['message_push'];
             $data['attachment'] = $info['attachment'];
             DB::table('doctors')->where('id',$doctor['id'])->update($data);
             return  json_encode(['status'=>'ok','code'=>'0000','info'=>'修改成功']);

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

@@ -74,7 +74,7 @@ class Login extends Controller
                 return json_encode(['status'=>'fail','code'=>'1101','msg'=>'密码不能为空']);
             }
             //医生信息
-            $info = DB::table('doctors')->where('username',$param['userName'])->field('id,exam_class,attachment,username,password,login_time,login_failure,realname,email,phone,doctor_title,institution_id,department_id,doctor_role,is_report')->find();
+            $info = DB::table('doctors')->where('username',$param['userName'])->field('message_push,id,exam_class,attachment,username,password,login_time,login_failure,realname,email,phone,doctor_title,institution_id,department_id,doctor_role,is_report')->find();
             log::record($info);
             if(!$info){
                 return json_encode(['status'=>'fail','code'=>'1004','msg'=>'用户名'.$param['userName'].'或密码错误']);

+ 12 - 1
application/inter/controller/Messages.php

@@ -128,7 +128,7 @@ class Messages extends Base
             if(Cache::get('messages_'.$doctor['id'])){
                 $num = Cache::get('messages_'.$doctor['id']);
             }else{
-                $num = DB::table('messages')->where('doctor_id',$doctor['id'])->where('status',0)->where('is_read',0)->count();
+                $num = DB::table('messages')->where('doctor_id',$doctor['id'])->where('status',0)->where('is_read',0)->sum('count');
                 Cache::set('messages_'.$doctor['id'],$num);
             }
             return json_encode(['status'=>'ok','code'=>'0000','sessionid'=>$sessionid,'num'=>$num]);
@@ -205,6 +205,9 @@ class Messages extends Base
      *")
      **/
     public function changeRead(){
+        $sessionid = $_REQUEST['sessionid'];
+        $doctor = Cache::get($sessionid);
+        Cache::rm('messages_'.$doctor['id']);
         $id = $_REQUEST['id'];
         DB::table('messages')->where('id',$id)->update(['is_read'=>1]);
         return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已读']);
@@ -235,6 +238,9 @@ class Messages extends Base
      *")
      **/
     public  function unread(){
+        $sessionid = $_REQUEST['sessionid'];
+        $doctor = Cache::get($sessionid);
+        Cache::rm('messages_'.$doctor['id']);
         $id = $_REQUEST['id'];
         DB::table('messages')->where('id',$id)->update(['is_read'=>0]);
         return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已设置为未读']);
@@ -266,6 +272,7 @@ class Messages extends Base
     public function readAll(){
         $sessionid = $_REQUEST['sessionid'];
         $doctor = Cache::get($sessionid);
+        Cache::rm('messages_'.$doctor['id']);
         DB::table('messages')->where('doctor_id',$doctor['id'])->where('status',0)->where('is_read', '0')->update(['is_read'=>1]);
         return json_encode(['status'=>'ok','code'=>'0000','msg'=>'修改成功']);
     }
@@ -295,6 +302,9 @@ class Messages extends Base
      *")
      **/
     public  function delete(){
+        $sessionid = $_REQUEST['sessionid'];
+        $doctor = Cache::get($sessionid);
+        Cache::rm('messages_'.$doctor['id']);
         $id = $_REQUEST['id'];
         DB::table('messages')->where('id',$id)->update(['status'=>1]);
         return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已删除']);
@@ -326,6 +336,7 @@ class Messages extends Base
     public function deleteAll(){
         $sessionid = $_REQUEST['sessionid'];
         $doctor = Cache::get($sessionid);
+        Cache::rm('messages_'.$doctor['id']);
         DB::table('messages')->where('doctor_id',$doctor['id'])->where('status',0)->update(['status'=>1]);
         return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已全部删除']);
     }

+ 3 - 5
application/inter/controller/Writereport.php

@@ -497,7 +497,6 @@ class Writereport extends Base
                 $type = '6';
                 $url = '';
                 Message::insert($t,$c,$d,$type,$url,1,$report_info['remote_application_id']);
-                Cache::rm('messages_'.$doctor['id']);
             }
             DB::table('exams')->where('id',$id)->update(['film_type'=>$_REQUEST['param']['film_type']]);
             DB::table('report')->where('id',$report_id)->update($rinfo);
@@ -627,9 +626,8 @@ class Writereport extends Base
                 $d = $status['req_doctor_id'];
                 $type = '5';
                 $exam_class = DB::table('exams')->where('id',$id)->field('exam_class')->find();
-                $url = Message::url($sessionid,$id,0,$exam_class['exam_class'],$report_id);
+                $url = Message::url($sessionid,$id,0,$exam_class['exam_class'],$report_id,$report['remote_application_id']);
                 Message::insert($t,$c,$d,$type,$url,1,$report['remote_application_id']);
-                Cache::rm('messages_'.$doctor['id']);
             }
             $url = 'wechat.pacsonline.cn/wxzskk/uwx/requestWxQrcode?reportId='.$report_id;
             $info = $this->curl_get($url);
@@ -1156,13 +1154,13 @@ class Writereport extends Base
                 $info[] = $arr;
             }elseif($remote_info['report_status'] == 4){
                 //申请中
-                return json_encode(['status'=>'fail','code'=>'0125','msg'=>'申请单正在申请中,无医生接收远程报告']);
+                return json_encode(['status'=>'fail','code'=>'0125','msg'=>'申请单正在申请中,无医生接收远程报告']);
             }elseif($remote_info['report_status'] == 5){
                 // 驳回
                 return json_encode(['status'=>'fail','code'=>'0125','msg'=>'申请单已被驳回,没有医生完成远程报告']);
             }elseif($remote_info['report_status'] == 12){
                 // 撤回
-                return json_encode(['status'=>'fail','code'=>'0125','msg'=>'申请单正在申请中,无医生完成远程报告']);
+                return json_encode(['status'=>'fail','code'=>'0125','msg'=>'申请单正在申请中,无医生完成远程报告']);
             }elseif($remote_info['report_status'] == ''){
                 // 撤回
                 return json_encode(['status'=>'fail','code'=>'0126','msg'=>'没有申请单']);